Make WordPress Core

Opened 6 months ago

Last modified 3 weeks ago

#61244 new defect (bug)

The export_wp() function inserts empty <wp:comment> data when get_comment() returns a false or empty value

Reported by: wpexplorer's profile WPExplorer Owned by:
Milestone: 6.8 Priority: normal
Severity: minor Version: 4.4
Component: Export Keywords: has-patch needs-testing
Focuses: administration Cc:

Description

If you wish to exclude comments from the WordPress export you can use the following code:

add_action( 'export_wp', function() {
    add_filter( 'get_comment', '__return_false' );
} );

However, the function will still loop through empty values for the $comments array inserting unnecessary <wp:comment> items.

Attachments (2)

Screen Shot 2024-09-17 at 3.00.51 PM.png (329.5 KB) - added by lbones 2 months ago.
This is the test that was done using the patch [from PR=6574] which was PHP 8.2 and WP 6.6.2
Screen Shot 2024-09-17 at 3.14.49 PM.png (262.2 KB) - added by lbones 2 months ago.
Another view of the issue in the patch [with PR=6574] using PHP 8.2 and WP 6.6.2

Download all attachments as: .zip

Change History (9)

This ticket was mentioned in PR #6574 on WordPress/wordpress-develop by @WPExplorer.


6 months ago
#1

  • Keywords has-patch added

If you wish to exclude comments from the WordPress export you can use the following code:

add_action( 'export_wp', function() {
    add_filter( 'get_comment', '__return_false' );
} );

However, the function will still loop through empty values for the $comments array inserting unnecessary <wp:comment> items.

#2 @freewebmentor
6 months ago

  • Focuses administration added

Hi @wpexplorer! 👋

Thank you for your contribution to WordPress! 💖

#3 @hellofromTonya
2 months ago

  • Keywords needs-testing added
  • Milestone changed from Awaiting Review to 6.7
  • Version changed from 6.6 to 4.4

While scrubbing for 6.6.x minor, dove into which WordPress Version introduced this bug and code. It was in WP 4.4 via [33891].

As it has a clear explanation and patch, moving it into 6.7 cycle for possible resolution.

#4 @lbones
2 months ago

I am working on testing this one! I am planning on recreating the issue in WP 4.4, and then running the patch to verify if the issue has been resolved. I am using the WordPress Playground, but can test through the CLI or whatever you may need.

In the PlayGround, I did notice that the user is not able to enter an empty comment. To recreate, I wrote a comment, and then went into the WordPress editor and removed the text in the comment.

Version 0, edited 2 months ago by lbones (next)

@lbones
2 months ago

This is the test that was done using the patch [from PR=6574] which was PHP 8.2 and WP 6.6.2

@lbones
2 months ago

Another view of the issue in the patch [with PR=6574] using PHP 8.2 and WP 6.6.2

#5 @lbones
2 months ago

Initially, I thought that the issue was that the comments were coming through whether or not they contained content. I realized upon further investigation that the issue, is if the person wants to run

add_action( 'export_wp', function() {
    add_filter( 'get_comment', '__return_false' );
} );

then the patch, which contains an array_filter does work. Recommendation would be to add an export option without comments instead of the current patch.

Reasoning: This very niche solution makes the entire get_comment call in the wp_export function slower. The array_filter in combination with array_map creates two maps (could probably have a map_reduce like function), and with the for loop, we are going through all of the comments thrice.

P.S. I plan on opening a new ticket with the commenting editing issue I found. I believe the checks on modify_item in the comment controller just needs to be a little more robust.

This ticket was mentioned in Slack in #core by stoyangeorgiev. View the logs.


3 weeks ago

#7 @stoyangeorgiev
3 weeks ago

  • Milestone changed from 6.7 to 6.8

This one was discussed at a bug-scrub. By the looks of it this one needs a bit more time, and with RC1 right around the corner, moving this one to 6.8. Cheers!

Note: See TracTickets for help on using tickets.