Make WordPress Core

Opened 4 years ago

Last modified 2 years ago

#51082 new defect (bug)

Default value for comment_type changed can lead to comments not shown and malfunctioning plugins

Reported by: ov3rfly's profile Ov3rfly Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.5
Component: Comments Keywords:
Focuses: Cc:

Description

Had a situation where a theme would not show comments any more with WP 5.5, it would show correct number of comments but not the comments content. Using 5.4.2 backup made the comments appear again.

After some research found this remark at wp_insert_comment()

@since 5.5.0 Default value for `$comment_type` argument changed to `comment`.

The theme in question uses a callback function for wp_list_comments() with this code:

switch ( $comment->comment_type ) :
	case '' :
		// print normal comment here...
		break;
	case 'pingback'  :
	case 'trackback' :
		break;
endswitch;

That causes the comments not to be shown because $comment->comment_type is 'comment' with WP 5.5 and not an empty string any more.

Many themes with callbacks including Twenty Twelve, Twenty Eleven compare to 'pingback' and 'trackback' first and then as default case print normal comment, without checking real value of $comment->comment_type.

That's why the new behaviour of WP 5.5 accidentally works with many themes.

For backward compatibility $comment->comment_type should be set to empty string instead 'comment' when using a callback or a deprecated notice or similar should be triggered.

Change History (17)

#1 @Ov3rfly
4 years ago

.. or the default value for $comment_type should be changed back to empty string.

This ticket was mentioned in Slack in #themereview by joyously. View the logs.


4 years ago

#3 @SergeyBiryukov
4 years ago

Related: [47597] / #49236.

Last edited 4 years ago by SergeyBiryukov (previous) (diff)

#4 @jeremyfelt
4 years ago

I think this was an unfortunate but expected side effect of applying an actual default to the comment_type field. The corresponding dev note walks through the related tickets and mentions this specifically in relation to the pattern that Twenty Ten propagated. See also this comment.

#5 @Ov3rfly
4 years ago

Actually Twenty Ten and some other themes out there did it right before.

They check the actual value of comment_type, an empty string is a valid value.

More about this here: https://core.trac.wordpress.org/ticket/49236#comment:36

#6 @TimothyBlynJacobs
4 years ago

#51208 was marked as a duplicate.

#7 @sulfsby
4 years ago

All Artisteer generated themes have the same problem. They have this code:

<?php
function theme_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
switch ($comment->comment_type) :
case '' :
?>

#8 @smerriman
4 years ago

This isn't just affecting themes, but many plugins. For example, the WP Recipe Maker plugin uses the comment_approved_ and comment_unapproved_ actions to sync comment statuses with its ratings.

After WP 5.5, this is now broken, so that when a comment is approved its rating isn't.

I'm about to contact the author to get them to add a workaround, but I'm sure a large number of other plugins do similar - this seems a pretty breaking change. I'm not sure why an empty string couldn't continue to be used for normal comments.

#9 @Ov3rfly
4 years ago

Also affects millions of users of major plugins like WP Super Cache or Duplicate Posts which rely on empty string as valid comment_type for certain functionalities.

#10 in reply to: ↑ description ; follow-up: @SergeyBiryukov
4 years ago

Replying to Ov3rfly:

The theme in question uses a callback function for wp_list_comments() with this code:

switch ( $comment->comment_type ) :
	case '' :
		// print normal comment here...
		break;
	case 'pingback'  :
	case 'trackback' :
		break;
endswitch;

Here's a workaround for any themes using that pattern:

function wp51082_restore_empty_comment_type_on_frontend( $comment ) {
	if ( ! is_admin() && 'comment' === $comment->comment_type ) {
		$comment->comment_type = '';
	}

	return $comment;
}
add_filter( 'get_comment', 'wp51082_restore_empty_comment_type_on_frontend' );

In my testing, this makes comments display again an older version of Twenty Ten, before it was updated in [47597].

I don't have any Artisteer themes to test, but it should probably work for them too.

#11 @Ov3rfly
4 years ago

@SergeyBiryukov An example theme created with Aristeer v4.3.0.60745 has been provided by @sulfsby in #51208.

Aristeer themes will most probably never be updated, most of those users probably don't even know what PHP is.

#12 @knutsp
4 years ago

Could a helper plugin, that reverts this change, be a solution? Then re-do, at least offer it, at uninstall.

#13 @Ov3rfly
4 years ago

  • Summary changed from Default value for comment_type changed can lead to comments not shown to Default value for comment_type changed can lead to comments not shown and malfunctioning plugins

#14 follow-up: @zeno001
4 years ago

  • Summary changed from Default value for comment_type changed can lead to comments not shown and malfunctioning plugins to Default value for comment_type changed can lead to comments not shown

@SergeyBiryukov

I have several Artisteer themes that this affects. Does that code just go into functions.php?

#15 @Ov3rfly
4 years ago

  • Summary changed from Default value for comment_type changed can lead to comments not shown to Default value for comment_type changed can lead to comments not shown and malfunctioning plugins

#16 in reply to: ↑ 14 @zeno001
4 years ago

Replying to zeno001:

@SergeyBiryukov

I have several Artisteer themes that this affects. Does that code just go into functions.php?

I can confirm that has fixed one of my Artisteer sites and comments are now displayed correctly.

Many thanks, @SergeyBiryukov !

#17 in reply to: ↑ 10 @cinemamayhem
2 years ago

Replying to SergeyBiryukov:

Replying to Ov3rfly:

The theme in question uses a callback function for wp_list_comments() with this code:

switch ( $comment->comment_type ) :
	case '' :
		// print normal comment here...
		break;
	case 'pingback'  :
	case 'trackback' :
		break;
endswitch;

Here's a workaround for any themes using that pattern:

function wp51082_restore_empty_comment_type_on_frontend( $comment ) {
	if ( ! is_admin() && 'comment' === $comment->comment_type ) {
		$comment->comment_type = '';
	}

	return $comment;
}
add_filter( 'get_comment', 'wp51082_restore_empty_comment_type_on_frontend' );

In my testing, this makes comments display again an older version of Twenty Ten, before it was updated in [47597].

I don't have any Artisteer themes to test, but it should probably work for them too.

I've tried adding this to my Aristeer theme, but it just stalls out when I try to update the functions.php portion. WP just takes forever and then says it didn't save.

Is there another work around here? Or can someone tell me what I'm doing wrong here (please don't say stop using Artisteer themes, I've used them on my sites for ages) but the fact that comments are now hidden is really troublesome.

Any help would be appreciated.

Note: See TracTickets for help on using tickets.