Make WordPress Core

Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#44914 closed defect (bug) (fixed)

Bulk Edit posts changes Post format back to Standard

Reported by: lanche86's profile lanche86 Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.1 Priority: normal
Severity: normal Version: 4.9
Component: Post Formats Keywords: has-screenshots has-patch has-unit-tests dev-feedback
Focuses: administration Cc:


Hello, all!

Here is the weird bug :) While doing a Bulk edit of posts and even if Post Format is set to "No change" it updates all the posts and it sets them back to Standard format losing all the previous Post Formats.

Steps to reproduce:
1) Select posts you want to edit in bulk, keeping the Post Format to No change -
2) Hit Submit
3) All your post formats of the selected posts are Standard now -

Attachments (3)

44914.patch (537 bytes) - added by mukesh27 6 years ago.
Try this patch.
44914.diff (2.0 KB) - added by birgire 6 years ago.
44914-2.diff (2.0 KB) - added by birgire 5 years ago.

Download all attachments as: .zip

Change History (22)

#1 @anakin4816
6 years ago

True story! Thanks Milan for posting it. :)

#2 @mukesh27
6 years ago

  • Focuses administration added
  • Keywords reporter-feedback added

@lanche86 Have you checked above issue with default WP and twentyseventeen theme? Also disable all other plugin as Bulk edit is not core functionality of WordPress.

#3 @lanche86
6 years ago

  • Keywords reporter-feedback removed

Hey, @mukesh27!

Yes, default WordPress installation with twentyseventeen theme activated and no plugins installed/activated.

I am talking about editing posts in bulk, please see the screenshot - - this is core functionality of WordPress. Let me know if you have any questions

#4 @mukesh27
6 years ago

  • Keywords needs-patch has-screenshots added

@lanche86 got it. it's bug

Last edited 6 years ago by mukesh27 (previous) (diff)

#5 @birgire
6 years ago

It looks like the problem could originate from bulk_edit_posts() (src):

$current_terms = (array) wp_get_object_terms( $post_ID, $tax_name, array( 'fields' => 'names' ) );

where it fetches the post format names, like "Image" or "Video".

Then these names are added into the tax_input for wp_update_post().

But wp_set_post_terms() doesn't knows how to add post formats without the correct slug prefix.

One suggestion could be to consider using:

$current_terms = (array) wp_get_object_terms( $post_ID, $tax_name, array( 'fields' => 'slugs' ) );

for post formats, to fetch slugs with the correct post format prefix, like post-format-image and post-format-video.

Last edited 6 years ago by birgire (previous) (diff)

6 years ago

Try this patch.

#6 @mukesh27
6 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

Hi @lanche86, welcome to WordPress Trac! Thanks for the ticket.

Hi @birgire i have found the issue in bulk_edit_posts function in which $post_data['tax_input']['post_format'] is not unset when post format selection is empty. you can please check my patch and let me know your though

6 years ago

#7 @birgire
6 years ago

  • Keywords has-unit-tests added
  • Version changed from 4.9.8 to 4.9

Related ticket #41396

@mukesh27 that looks good

The patch in 44914.diff adjusts 44914.patch by using a single unset.

It also adds a unit test.

We note that get_post_format() removes the post format prefix 'post-format-' before returning the post format slug.

It's not enough to assert only with get_post_format() if the post format was preserved in bulk post editing,

as the bug here removes the post format prefix from the post format slug.

Example: The 'post-format-image' is changed and saved to 'image'.

So we need to explicitly check the post format slug.

Here we tested 3 posts;

  • the first one with Image post format,
  • the second one with Aside post format,
  • the third one with Standard post format (means it's not set).

#8 follow-up: @mukesh27
6 years ago

@birgire check video it's working for me.

#9 in reply to: ↑ 8 @birgire
6 years ago

  • Keywords needs-testing removed

Replying to mukesh27:

@birgire check video it's working for me.

Thanks for the video, looks good.

#10 @SergeyBiryukov
6 years ago

  • Milestone changed from Awaiting Review to 4.9.9
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#11 @pento
6 years ago

  • Milestone changed from 4.9.9 to 5.0.1

#12 @pento
6 years ago

  • Milestone changed from 5.0.1 to 5.0.2

#13 @pento
6 years ago

  • Milestone changed from 5.0.2 to 5.0.3

#14 @audrasjb
5 years ago

  • Keywords dev-feedback reporter-feedback added


The issue is very relevant and a real reproductible bug, but after some tests, the patch doesn't apply on my side, it doesn't fix the problem, post_format are still removed. @SergeyBiryukov @mukesh27 @birgire @lanche86 Do you think you can test it again and see if the latest patch looks good on your side? Otherwise, we are going to punt it to 5.1. Thanks.

Version 0, edited 5 years ago by audrasjb (next)

5 years ago

#15 @birgire
5 years ago

  • Keywords reporter-feedback removed

@audrasjb thanks for testing

The patch seems to work for me, it just needed a refresh as it didn't apply cleanly after 4 months, creating wp-admin/includes/post.rej instead of updating the wp-admin/includes/post.php file.

The unit test is running as expected and I also tested successfully to bulk edit posts with non-default post formats in wp-admin.

If the refreshed 44914-2.diff is not working, it would be great if you could post the steps in your testing and verify the changes in wp-admin/includes/post.php, thanks.

Last edited 5 years ago by birgire (previous) (diff)

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

5 years ago

#17 @desrosj
5 years ago

  • Milestone changed from 5.0.3 to 5.1

Thanks for the refresh, @birgire! This still needs testing and a final review. Punting to 5.1.

#18 @SergeyBiryukov
5 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 44670:

Post Formats: Prevent Bulk Edit from unintentionally changing post format to Standard even if set to "No change".

Correct the logic in [41187].

Props birgire, mukesh27, lanche86.
Fixes #44914. See #41396.

#19 @SergeyBiryukov
5 years ago

In 44672:

PHPCS: Fix formatting issues introduced in [44670].

See #44914.

Note: See TracTickets for help on using tickets.