admin管理员组

文章数量:1124079

I'm using a custom template for my wordpress comments. I can't figure out why plugins like dislike/like comments can't add their code to my comments content. Same for rating, if users choose let's say three stars out of five, his choose is not showed in comment body.

comments.php

    <?php

echo '<p class="ctacomentarii">';
$comment_count = get_comments_number();
if ($comment_count === 0) {
  echo '0 comentarii';
} else if ($comment_count === 1) {
  echo '1 comentariu';
} else {
  echo $comment_count . ' comentarii';
}
echo '</p>';

$labels = array(
    'send' => 'TRIMITE COMENTARIU',
    'reply' => '',
    'reply_to' => 'Răspunde',
    'author' => 'Nume*',
    'email' => 'Adresa de email*',
    'body' => 'Scrie comentariul tău aici.',
    'cookies' => 'Accept politica de confidențialtiate.',
    'cancel' => ' [ANULEAZĂ]',
);

$fields = array(
    'author' => '<div class="comment-form-author"><input id="author" name="author" aria-required="true" placeholder="' . $labels['author'] .'"></input></div>',
    'email' => '<div class="comment-form-email"><input id="email" name="email" placeholder="' . $labels['email'] .'"></input></div>',
    'cookies' => '',
);

$comments_args = array(
    'fields' => $fields,
    'label_submit' => __( $labels['send'] ),
    'title_reply' => __( $labels['reply'] ),
    'title_reply_to' => __( $labels['reply_to'] ),
    'cancel_reply_link' => __( $labels['cancel'] ),
    'comment_field' => '<textarea id="comment" name="comment" aria-required="true" placeholder="' . $labels['body'] .'"></textarea>',
    'comment_notes_before' => '',
    'comment_notes_after' => '',
    'id_submit' => 'comment-submit',
    'class_submit' => 'submit',
    'id_form' => 'commentform',
    'class_form' => 'comment-form',
    'reply_text' => 'Răspunde',
);
comment_form( $comments_args );

echo '<ol class="listacomentarii">';
wp_list_comments( array(
    'style'       => 'ol',
    'short_ping'  => true,
    'avatar_size' => 48,
    'callback' => 'comentarii'
) );
echo '</ol>'; 

wp_enqueue_script( 'comment-reply' );
?>

inc/comentarii.php

<?php

function comentarii( $comment, $args, $depth ) {
    $GLOBALS['comment'] = $comment;
    $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
    ?>

    <<?php echo $tag; ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID(); ?>">
        <div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
            <?php

            switch ( $comment->comment_type ) :
                case 'pingback' :
                case 'trackback' :
                    echo '<div class="pingback-entry"><span class="pingback-heading">' . esc_html__( 'Pingback:', 'pe-zona.ro' ) . '</span> ' . comment_author_link() . '</div>';
                    break;
                default :

                    echo '<div class="imagine-autor-data-comentariu">';


                    if ( $args['avatar_size'] != 0 ) {
                        $avatar_size = ! empty( $args['avatar_size'] ) ? $args['avatar_size'] : 20; // setează dimensiunea implicită a avatarului
                        echo get_avatar( $comment, $avatar_size, '.webp' );
                    }

           
                    echo '<div class="autor-data-container">';
                    echo '<p class="autor-nume">' . get_comment_author_link() . '</p>';
                    echo '<time class="data">' . get_comment_date('d F, Y', $comment->comment_ID) . '</time>';
                    echo '</div>'; 
                    echo '</div>'; 

                    echo '<div class="text-comentariu">';
                    echo '<p>' . get_comment_text() . '</p>';

                    if ($depth == 1) {
                        echo '<div class="buton-raspunde">';
                        comment_reply_link( array_merge( $args, array(
                            'reply_text' => __('<img height="10px" width="10px" src="/wp-content/themes/template1/assets/reply-icon.svg"> Răspunde', 'pe-zona.ro'),
                            'depth' => $depth,
                            'add_below' => 'div-comment',
                            'max_depth' => $args['max_depth']
                        )) );
                        echo '</div>';
                    }

                    echo '</div>'; 

        
                    if ( $comment->comment_approved == '0' ) {
                        echo '<em class="comment-awaiting-moderation">' . _e( '<p style="color: #fff; background-color: #F42E17; font-family:var(--familie-font-titlu);font-weight:800;padding: 5px 0;text-transform:uppercase;text-align:center;";>Comentariul tău urmează să fie moderat.</p>', 'pe-zona.ro' ) . '</em><br/>';
                    }
                    break;
            endswitch; 
            ?>
        </div>
    </<?php echo $tag; ?>>
    <?php
}
?>

I'm using a custom template for my wordpress comments. I can't figure out why plugins like dislike/like comments can't add their code to my comments content. Same for rating, if users choose let's say three stars out of five, his choose is not showed in comment body.

comments.php

    <?php

echo '<p class="ctacomentarii">';
$comment_count = get_comments_number();
if ($comment_count === 0) {
  echo '0 comentarii';
} else if ($comment_count === 1) {
  echo '1 comentariu';
} else {
  echo $comment_count . ' comentarii';
}
echo '</p>';

$labels = array(
    'send' => 'TRIMITE COMENTARIU',
    'reply' => '',
    'reply_to' => 'Răspunde',
    'author' => 'Nume*',
    'email' => 'Adresa de email*',
    'body' => 'Scrie comentariul tău aici.',
    'cookies' => 'Accept politica de confidențialtiate.',
    'cancel' => ' [ANULEAZĂ]',
);

$fields = array(
    'author' => '<div class="comment-form-author"><input id="author" name="author" aria-required="true" placeholder="' . $labels['author'] .'"></input></div>',
    'email' => '<div class="comment-form-email"><input id="email" name="email" placeholder="' . $labels['email'] .'"></input></div>',
    'cookies' => '',
);

$comments_args = array(
    'fields' => $fields,
    'label_submit' => __( $labels['send'] ),
    'title_reply' => __( $labels['reply'] ),
    'title_reply_to' => __( $labels['reply_to'] ),
    'cancel_reply_link' => __( $labels['cancel'] ),
    'comment_field' => '<textarea id="comment" name="comment" aria-required="true" placeholder="' . $labels['body'] .'"></textarea>',
    'comment_notes_before' => '',
    'comment_notes_after' => '',
    'id_submit' => 'comment-submit',
    'class_submit' => 'submit',
    'id_form' => 'commentform',
    'class_form' => 'comment-form',
    'reply_text' => 'Răspunde',
);
comment_form( $comments_args );

echo '<ol class="listacomentarii">';
wp_list_comments( array(
    'style'       => 'ol',
    'short_ping'  => true,
    'avatar_size' => 48,
    'callback' => 'comentarii'
) );
echo '</ol>'; 

wp_enqueue_script( 'comment-reply' );
?>

inc/comentarii.php

<?php

function comentarii( $comment, $args, $depth ) {
    $GLOBALS['comment'] = $comment;
    $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
    ?>

    <<?php echo $tag; ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID(); ?>">
        <div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
            <?php

            switch ( $comment->comment_type ) :
                case 'pingback' :
                case 'trackback' :
                    echo '<div class="pingback-entry"><span class="pingback-heading">' . esc_html__( 'Pingback:', 'pe-zona.ro' ) . '</span> ' . comment_author_link() . '</div>';
                    break;
                default :

                    echo '<div class="imagine-autor-data-comentariu">';


                    if ( $args['avatar_size'] != 0 ) {
                        $avatar_size = ! empty( $args['avatar_size'] ) ? $args['avatar_size'] : 20; // setează dimensiunea implicită a avatarului
                        echo get_avatar( $comment, $avatar_size, 'https://pe-zona.ro/cook.webp' );
                    }

           
                    echo '<div class="autor-data-container">';
                    echo '<p class="autor-nume">' . get_comment_author_link() . '</p>';
                    echo '<time class="data">' . get_comment_date('d F, Y', $comment->comment_ID) . '</time>';
                    echo '</div>'; 
                    echo '</div>'; 

                    echo '<div class="text-comentariu">';
                    echo '<p>' . get_comment_text() . '</p>';

                    if ($depth == 1) {
                        echo '<div class="buton-raspunde">';
                        comment_reply_link( array_merge( $args, array(
                            'reply_text' => __('<img height="10px" width="10px" src="/wp-content/themes/template1/assets/reply-icon.svg"> Răspunde', 'pe-zona.ro'),
                            'depth' => $depth,
                            'add_below' => 'div-comment',
                            'max_depth' => $args['max_depth']
                        )) );
                        echo '</div>';
                    }

                    echo '</div>'; 

        
                    if ( $comment->comment_approved == '0' ) {
                        echo '<em class="comment-awaiting-moderation">' . _e( '<p style="color: #fff; background-color: #F42E17; font-family:var(--familie-font-titlu);font-weight:800;padding: 5px 0;text-transform:uppercase;text-align:center;";>Comentariul tău urmează să fie moderat.</p>', 'pe-zona.ro' ) . '</em><br/>';
                    }
                    break;
            endswitch; 
            ?>
        </div>
    </<?php echo $tag; ?>>
    <?php
}
?>
Share Improve this question asked Mar 12, 2024 at 21:32 Villas VillasVillas Villas 312 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

This was the solution:

echo '<p>' . apply_filters( 'comment_text', get_comment_text(), $comment, $args ) . '</p>';

本文标签: phpWhy plugins can39t add(inject) their code in my comments