Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#57810 new defect (bug)

Should wp_insert_post() function call 'wp_insert_post' action with 'update' equals true after creating post for the first time.

Reported by: zenithcity Owned by:
Priority: normal Milestone: Awaiting Review
Component: Posts, Post Types Version: 6.1.1
Severity: normal Keywords:
Cc: Focuses:

Description

The wp_insert_post() function calls 'wp_insert_post' action hook with 'update' equals true when creating post for the first time.

Post was created using the Gutenberg editor.

/* $update should only be true when updating post */
do_action( 'wp_insert_post', $post_ID, $post, $update );

Attachments (4)

Screenshot_20230226_014746.2.png​ (191.2 KB ) - added by zenithcity 4 years ago.
Screenshot 2023-03-12 033810.png​ (190.3 KB ) - added by zenithcity 4 years ago.
Screenshot 2023-03-12 034657.png​ (289.7 KB ) - added by zenithcity 4 years ago.
Added var_dump to inspect value of $update in do_action( 'wp_insert_post', $post_ID, $post, $update );
Screenshot 2023-03-12 040407.png​ (128.3 KB ) - added by zenithcity 4 years ago.

Download all attachments as: .zip

Change History (9)

#1 follow-up: @zenithcity
4 years ago

Please anyone who can remove an attachment should help me unlink the first added attachment (Screenshot_20230226_014746.png) from this ticket. I can't see the delete attachment button.

This ticket was mentioned in ​Slack in #core-test by ironprogrammer. ​View the logs.


4 years ago

#3 in reply to: ↑ 1 ; follow-up: @ironprogrammer
4 years ago

  • Keywords reporter-feedback added

Thank you for the the report, @zenithcity!

Regarding the question around the $update parameter, the passing of $update in this manner has been around for some time (​additional context), and would likely remain for backward compatibility reasons.

Are you able to provide more detail as to the console error/invalid JSON response? Is the wp_insert_post hook being used by custom code?

Please anyone who can remove an attachment should help me unlink the first added attachment (Screenshot_20230226_014746.png) from this ticket. I can't see the delete attachment button.

The first attachment has been removed as requested.

#4 @zenithcity
4 years ago

  • Keywords reporter-feedback removed

Thank you removing the first attachment as requested, @ironprogrammer

So, all plugins are disabled and using the latest WordPress default theme. I added a var_dump('create: $update) directly to where the do_action is fired and created a new post to test, the result is shown on the screenshot.

@zenithcity
4 years ago

Added var_dump to inspect value of $update in do_action( 'wp_insert_post', $post_ID, $post, $update );

#5 in reply to: ↑ 3 @zenithcity
4 years ago

Replying to ironprogrammer:

Thank you for the the report, @zenithcity!

Regarding the question around the $update parameter, the passing of $update in this manner has been around for some time (​additional context), and would likely remain for backward compatibility reasons.

Are you able to provide more detail as to the console error/invalid JSON response? Is the wp_insert_post hook being used by custom code?

Please anyone who can remove an attachment should help me unlink the first added attachment (Screenshot_20230226_014746.png) from this ticket. I can't see the delete attachment button.

The first attachment has been removed as requested.

There's no error in console and the JSON response of the publish post action is valid.

Note: See TracTickets for help on using tickets.