[wp-trac] [WordPress Trac] #41025: get_comment_text and comment_text do not return the same result.
WordPress Trac
noreply at wordpress.org
Tue Jun 13 12:13:05 UTC 2017
#41025: get_comment_text and comment_text do not return the same result.
--------------------------+-----------------------------
Reporter: BackuPs | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 4.8
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Hi
I was working on some changes to the comment code and came across a weird
issue. I looked at the wp core code but could not figure out why.
Suppose a comment is added like this
{{{
Hello World
This is a comment
With a new line of text
}}}
If i call get_comment_text i get a comment that has been stripped from all
empty lines (p-tags) in the comment when the comment was posted not being
a admin or editor.
i get this
{{{
Hello World This is a comment With a new line of text
}}}
However if i call the function comment_text this does not happen.
i get this
{{{
Hello World
This is a comment
With a new line of text
}}}
It tried some modified code in the default wp twenty seventeen theme and i
get similar results.
if you change the comments.php in that theme to this
{{{#!php
<?php
/**
* The template for displaying comments
*
* This is the template that displays the area of the page that contains
both the current comments
* and the comment form.
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage Twenty_Seventeen
* @since 1.0
* @version 1.0
*/
/*
* If the current post is protected by a password and
* the visitor has not yet entered the password we will
* return early without loading the comments.
*/
if ( post_password_required() ) {
return;
}
function theme_comments($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID()
?>">
<div id="comment-<?php comment_ID(); ?>"
class="comment_wrap">
<div class="gravatar"><?php echo
get_avatar($comment,$size='60',$default=''); ?></div>
<div class='comment_content'>
<div class="comment_meta">
<?php printf( '<cite
class="comment_author">%s</cite>', get_comment_author_link()) ?><?php
edit_comment_link(__('(Edit)', 'theme_front' ),' ','') ?>
<time class="comment_time"><?php
echo get_comment_date(); ?></time>
</div>
<div class='comment_text'>
<?php echo
get_comment_text();?>
<?php if ($comment->comment_approved == '0') : ?>
<span class="unapproved"><?php
_e('Your comment is awaiting moderation.','theme_front') ?></span>
<?php endif; ?>
</div>
<div class="reply">
<?php
comment_reply_link(array_merge( $args, array('depth' => $depth,
'max_depth' => $args['max_depth']))) ?>
</div>
</div>
</div>
<?php
}
?>
<div id="comments" class="comments-area">
<?php
// You can start editing here -- including this comment!
if ( have_comments() ) : ?>
<h2 class="comments-title">
<?php
$comments_number = get_comments_number();
if ( '1' === $comments_number ) {
/* translators: %s: post title */
printf( _x( 'One Reply to
“%s”', 'comments title', 'twentyseventeen' ), get_the_title()
);
} else {
printf(
/* translators: 1: number of
comments, 2: post title */
_nx(
'%1$s Reply to
“%2$s”',
'%1$s Replies to
“%2$s”',
$comments_number,
'comments title',
'twentyseventeen'
),
number_format_i18n(
$comments_number ),
get_the_title()
);
}
?>
</h2>
<ol class="comment-list">
<?php
wp_list_comments( array( 'callback' =>
'theme_comments' ) );
?>
</ol>
<?php the_comments_pagination( array(
'prev_text' => twentyseventeen_get_svg( array(
'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __(
'Previous', 'twentyseventeen' ) . '</span>',
'next_text' => '<span class="screen-reader-text">'
. __( 'Next', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg(
array( 'icon' => 'arrow-right' ) ),
) );
endif; // Check for have_comments().
// If comments are closed and there are comments, let's leave a
little note, shall we?
if ( ! comments_open() && get_comments_number() &&
post_type_supports( get_post_type(), 'comments' ) ) : ?>
<p class="no-comments"><?php _e( 'Comments are closed.',
'twentyseventeen' ); ?></p>
<?php
endif;
comment_form();
?>
</div><!-- #comments -->
}}}
all line breaks (p-tags are gone in the returned comments
if however you use this which is only one line of code difference
{{{#!php
<?php
/**
* The template for displaying comments
*
* This is the template that displays the area of the page that contains
both the current comments
* and the comment form.
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package WordPress
* @subpackage Twenty_Seventeen
* @since 1.0
* @version 1.0
*/
/*
* If the current post is protected by a password and
* the visitor has not yet entered the password we will
* return early without loading the comments.
*/
if ( post_password_required() ) {
return;
}
function theme_comments($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID()
?>">
<div id="comment-<?php comment_ID(); ?>"
class="comment_wrap">
<div class="gravatar"><?php echo
get_avatar($comment,$size='60',$default=''); ?></div>
<div class='comment_content'>
<div class="comment_meta">
<?php printf( '<cite
class="comment_author">%s</cite>', get_comment_author_link()) ?><?php
edit_comment_link(__('(Edit)', 'theme_front' ),' ','') ?>
<time class="comment_time"><?php
echo get_comment_date(); ?></time>
</div>
<div class='comment_text'>
<?php comment_text();?>
<?php if ($comment->comment_approved == '0') : ?>
<span class="unapproved"><?php
_e('Your comment is awaiting moderation.','theme_front') ?></span>
<?php endif; ?>
</div>
<div class="reply">
<?php
comment_reply_link(array_merge( $args, array('depth' => $depth,
'max_depth' => $args['max_depth']))) ?>
</div>
</div>
</div>
<?php
}
?>
<div id="comments" class="comments-area">
<?php
// You can start editing here -- including this comment!
if ( have_comments() ) : ?>
<h2 class="comments-title">
<?php
$comments_number = get_comments_number();
if ( '1' === $comments_number ) {
/* translators: %s: post title */
printf( _x( 'One Reply to
“%s”', 'comments title', 'twentyseventeen' ), get_the_title()
);
} else {
printf(
/* translators: 1: number of
comments, 2: post title */
_nx(
'%1$s Reply to
“%2$s”',
'%1$s Replies to
“%2$s”',
$comments_number,
'comments title',
'twentyseventeen'
),
number_format_i18n(
$comments_number ),
get_the_title()
);
}
?>
</h2>
<ol class="comment-list">
<?php
wp_list_comments( array( 'callback' =>
'theme_comments' ) );
?>
</ol>
<?php the_comments_pagination( array(
'prev_text' => twentyseventeen_get_svg( array(
'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __(
'Previous', 'twentyseventeen' ) . '</span>',
'next_text' => '<span class="screen-reader-text">'
. __( 'Next', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg(
array( 'icon' => 'arrow-right' ) ),
) );
endif; // Check for have_comments().
// If comments are closed and there are comments, let's leave a
little note, shall we?
if ( ! comments_open() && get_comments_number() &&
post_type_supports( get_post_type(), 'comments' ) ) : ?>
<p class="no-comments"><?php _e( 'Comments are closed.',
'twentyseventeen' ); ?></p>
<?php
endif;
comment_form();
?>
</div><!-- #comments -->
}}}
This does not happen. But I cannot seem to find the difference in the
class-walker-comment.php causing this.
Can anybody point me into the right direction?
thank you
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41025>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list