Make WordPress Core

Opened 7 years ago

Closed 3 months ago

#45801 closed defect (bug) (worksforme)

Duplicate post publish action

Reported by: bmettee4's profile bmettee4 Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.0.2
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

I'll try to keep this short. Action "publish_to_publish" is being called twice when updating a published post under some circumstances. Web server registers two calls (one to index.php, one to /wp-admin/post.php). First call appears to update the content and non-meta data. Second call updates data from meta blocks.

Specifics: Any theme or plugin that adds meta data to a post forces a second call to the update process with the meta block data.

Problem: Any plugin that performs actions based on "publish_to_publish" is being called twice. In my specific instance the Better Notifications for WordPress plugin sends notifications mails doubled.

Wordpress version: 5.0.2
Theme: Customify, no plugins
Or
Theme: TwentyNineteen, and Plugin: Profile Builder

Basically anything that adds meta-data to a post object causes a second, duplicate, action.

If meta-data updates should trigger a second action, how can a plugin detect that there has been an additional call?

Change History (2)

#1 @SergeyBiryukov
7 years ago

  • Component changed from Plugins to Posts, Post Types

#2 @SirLouen
3 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Reproduction Report

Description

❌ This can't validates that the issue can be reproduced.

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.29
  • Server: nginx/1.29.1
  • Database: mysqli (Server: 8.4.6 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 139.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Twenty-Five 1.3
  • MU Plugins: None activated
  • Plugins:
    • BBB Testing Dolly
    • Test Reports 1.2.0

Reproduciton instructions

  1. Add the code to a plugin, in the supp artifacts. This code simply add post meta, everytime a post is updated
  2. Create a new post
  3. Update the post
  4. 👌 Only one call is done to publish_to_publish

Actual Results

  1. ❌ Error condition is not occurring.

Additional Notes

  • I'm going to close this for two reasons:
  1. The first reason is that its not reproducible
  2. The second, is that even if there are double calls to hooks, they can be easily controlled either with a transient, temporary meta, or with a static variable if it's a callback, just to name some. There are many ways to handle this.

Supplemental Artifacts

add_action( 'post_updated', 'bb_testing_add_update_meta', 10, 1 );
function bb_testing_add_update_meta( $post_ID ) {
	if ( wp_is_post_autosave( $post_ID ) || wp_is_post_revision( $post_ID ) ) {
		return;
	}
	$timestamp = current_time( 'mysql' );
	add_post_meta( $post_ID, '_bb_testing_last_' . $timestamp, $timestamp );
}
Note: See TracTickets for help on using tickets.