Skip to main content

Comments broken after Dec. 2020 update

Comments

5 comments

  • Alex

    Hi,

    from what I understand by using that function you create a shortcode. Does that shortcode no longer work in Brizy editor? Does it work in WordPress editor? Does it no longer work after Brizy update or Disquiz update?

    0
  • Rick Houghton

    The WP_discuz comments work in regular WP posts and pages. After your update ALL my comments are broken on my website! It appears that you have made major changes to the code architecture in this update as the 'shortcode' folder has been removed:

    before update: wp-content/plugins/brizy-pro/shortcode/comments.php

    after update : wp-content/plugins/brizy-pro/templates/comments.php (not the same)
    'shortcode' folder gone...

    Old comments.php (with my modified code):

    <?php

    class BrizyPro_Shortcode_Comments extends Brizy_Shortcode_AbstractShortcode {

    private $atts = [];

    public function __construct() {
    parent::__construct();

    add_action( 'template_redirect', [ $this, '_action_template_redirect' ], 9 );
    // add_action( 'option_thread_comments', [ $this, '_action__return_true' ] );
    // add_action( 'option_thread_comments_depth', [ $this, '_action_thread_comments_depth' ] );
    }

    /**
    * Get shortcode name
    *
    * @return string
    */
    public function getName() {
    return 'comments';
    }

    /**
    * @param $atts
    * @param null $content
    *
    * @return mixed|string
    */
    public function render( $atts, $content = null ) {

    $this->atts = $atts;

    add_action( 'wp_list_comments_args', [ $this, '_action_wp_list_comments_args' ] );
    add_action( 'comments_template', [ $this, '_action_comments_template' ] );
    add_action( 'comments_template_query_args', [ $this, '_action_comments_template_query_args' ] );

    ob_start(); ob_clean();

    comments_template();

    $ob_get_clean = ob_get_clean();

    return $ob_get_clean;
    }

    public function _action_wp_list_comments_args( $args ) {
    return array_merge( $args, $this->atts );
    }

    public function _action_comments_template() {
    return implode( DIRECTORY_SEPARATOR, [ BRIZY_PRO_PLUGIN_PATH, 'templates', 'comments.php' ] );
    }

    public function _action_comments_template_query_args( $comment_args ) {

    $comment_args['number'] = $this->atts['limit'];
    $cpage = get_query_var( 'cpage' );
    $get_query_var = ( empty( $cpage ) ? 1 : $cpage ) - 1;
    $comment_args['offset'] = $comment_args['number'] * $get_query_var;

    return $comment_args;
    }

    public function _action__return_true() {
    return true;
    }

    public function _action_comments_per_page() {
    return $this->atts['limit'];
    }

    public function _action_thread_comments_depth() {
    return 5; //$this->atts['thread'];
    }

    public function _action_template_redirect() {

    $pid = Brizy_Editor::get()->currentPostId();

    try {
    $use_editor = Brizy_Editor_Post::get( $pid )->uses_editor();
    } catch ( Exception $e ) {
    $use_editor = false;
    }

    if ( ! Brizy_Admin_Templates::getTemplate() && ! $use_editor ) {
    return;
    }

    add_action( 'option_page_comments', [ $this, '_action__return_true' ] );

    return;
    }
    }
    /**
    * Add support for DISCUZ comments plugin
    */
    function my_wpdiscuz_shortcode() {
    $html = "";
    if (file_exists(ABSPATH . "wp-content/plugins/wpdiscuz/themes/default/comment-form.php")) {
    ob_start();
    include_once ABSPATH . "wp-content/plugins/wpdiscuz/themes/default/comment-form.php";
    $html = ob_get_clean();
    }
    return $html;
    }
    add_shortcode("wpdiscuz_comments", "my_wpdiscuz_shortcode");

    New comments.php (in the templates folder):

    <?php

    if ( post_password_required() ) {
    return;
    }

    $is_woo = false;
    if ( is_singular( [ 'product' ] ) && class_exists( 'WooCommerce' ) ) {
    global $product;
    $is_woo = true;
    }

    if ( ! comments_open() ) {
    return;
    }

    ?>

    <div id="comments" class="brz-comments-area">

    <?php

    if ( have_comments() ) :
    ?>
    <h2 class="brz-comments-title">
    <?php

    if ( $is_woo ) {

    $count = $product->get_review_count();
    if ( $count && wc_review_ratings_enabled() ) {
    /* translators: 1: reviews count 2: product name */
    $reviews_title = sprintf( esc_html( _n( '%1$s review for %2$s', '%1$s reviews for %2$s', $count, 'brizy-pro' ) ), esc_html( $count ), '<span>' . get_the_title() . '</span>' );
    echo apply_filters( 'woocommerce_reviews_title', $reviews_title, $count, $product ); // WPCS: XSS ok.
    } else {
    esc_html_e( 'Reviews', 'woocommerce' );
    }

    } else {

    $comments_number = get_comments_number();
    if ( '1' === $comments_number ) {
    /* translators: %s: post title */
    printf( _x( 'One Reply to &ldquo;%s&rdquo;', 'comments title', 'brizy-pro' ), get_the_title() );
    } else {
    printf(
    /* translators: 1: number of comments, 2: post title */
    _nx(
    '%1$s Reply to &ldquo;%2$s&rdquo;',
    '%1$s Replies to &ldquo;%2$s&rdquo;',
    $comments_number,
    'comments title',
    'brizy-pro'
    ),
    number_format_i18n( $comments_number ),
    get_the_title()
    );
    }
    }
    ?>
    </h2>

    <div class="brz-comments">
    <?php
    wp_list_comments([
    'walker' => new BrizyPro_Templates_CommentsWalker(),
    'short_ping' => true,
    'style' => 'div'
    ]);
    ?>
    </div>

    <?php
    the_comments_pagination(
    array(
    'prev_text' => '<span class="brz-screen-reader-text">' . __( 'Previous', 'brizy-pro' ) . '</span>',
    'next_text' => '<span class="brz-screen-reader-text">' . __( 'Next', 'brizy-pro' ) . '</span>',
    )
    );
    else:
    if ( $is_woo ) {
    echo '<p class="woocommerce-noreviews">' . __( 'There are no reviews yet.', 'brizy-pro' ) . '</p>';
    }
    endif; // Check for have_comments().


    if ( $is_woo && ! ( get_option( 'woocommerce_review_rating_verification_required' ) === 'no' || wc_customer_bought_product( '', get_current_user_id(), $product->get_id() ) ) ) :

    echo '<p class="brz-no-comments">' . __( 'Only logged in customers who have purchased this product may leave a review.', 'brizy-pro' ) . '</p>';

    elseif ( ! comments_open() && get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) :

    echo '<p class="brz-no-comments">' . __( 'Comments are closed.', 'brizy-pro' ) . '</p>';

    else :

    ob_start(); ob_clean();

    comment_form();

    $form = ob_get_clean();

    echo str_replace( 'class="comment-respond"', 'class="brz-comment-respond"', $form );

    endif;
    ?>
    </div>

    So it appears that you have completely removed the shortcode functionality from Brizy no? Where did the shortcode folder go?

    0
  • Alex

    Hi Rick,

    I had a discussion with the devs and indeed some changes have been made. These refer to how shortcodes work in Brizy and the class was moved to plugins/brizy-pro/content/placeholders/comments.php 

    I'm not sure if your code will work even if you add it to the new location. Generally, we do not recommend making such changes because we will make changes through the code with each update. I recommend you to wait for the API to be created and then you will be able to extend the Brizy functionality.

    0
  • Rick Houghton

    Hey Alex:

    Thanks for the info. My comments are working again!  I will look forward to the API but I needed the comments back now (like two days ago) so I have modified the file at the new location. Merry Christmas!

    0
  • Alex

    I'm glad you solved this.

    Merry Christmas!

    0

Please sign in to leave a comment.