WPDiscourse\Templates\HTMLTemplates::bad_response_html PHP Method

bad_response_html() public static method

This template is displayed in the comments section when there is no discourse_permalink index in the response returned from Discourse::sync_to_discourse_work Can be customized in the theme using the filter provided.
public static bad_response_html ( ) : mixed | void
return mixed | void
    public static function bad_response_html()
    {
        ob_start();
        ?>
		<div class="respond comment-respond">
			<div class="comment-reply-title discourse-no-connection-notice">
				<p><?php 
        esc_html_e('Comments are not enabled for this post.', 'wp-discourse');
        ?>
</p>
			</div>
		</div>
		<?php 
        $output = ob_get_clean();
        return apply_filters('discourse_no_connection_html', $output);
    }

Usage Example

Ejemplo n.º 1
0
<?php

use WPDiscourse\Templates;
$custom = get_post_custom();
// If, when a new post is published to Discourse, there is not a valid response from
// the forum, the `discourse_permalink` key will not be set. Display the `bad_response_html` template.
if (!array_key_exists('discourse_permalink', $custom)) {
    echo wp_kses_post(Templates\HTMLTemplates::bad_response_html());
} else {
    $options = get_option('discourse');
    $is_enable_sso = isset($options['enable-sso']) && intval($options['enable-sso']) == 1;
    $permalink = (string) $custom['discourse_permalink'][0];
    if ($is_enable_sso) {
        $permalink = esc_url($options['url']) . '/session/sso?return_path=' . $permalink;
    }
    $discourse_url_name = preg_replace("(https?://)", "", esc_url($options['url']));
    if (isset($custom['discourse_comments_raw'])) {
        $discourse_info = json_decode($custom['discourse_comments_raw'][0]);
    } else {
        $discourse_info = array();
    }
    $defaults = array('posts_count' => 0, 'posts' => array(), 'participants' => array());
    // add <time> tag to WP allowed html tags
    global $allowedposttags;
    $allowedposttags['time'] = array('datetime' => array());
    // use custom datetime format string if provided, else global date format
    $datetime_format = $options['custom-datetime-format'] == '' ? get_option('date_format') : $options['custom-datetime-format'];
    // Add some protection in the event our metadata doesn't look how we expect it to
    $discourse_info = (object) wp_parse_args((array) $discourse_info, $defaults);
    $more_replies = $discourse_info->posts_count - count($discourse_info->posts) - 1;
    $more = count($discourse_info->posts) == 0 ? "" : "more ";