WordPress.org

Make WordPress Core

Opened 4 months ago

Closed 2 months ago

#47548 closed defect (bug) (reported-upstream)

`transition_post_status` hook is triggered twice when a post is scheduled in the block editor

Reported by: sudar Owned by:
Milestone: Priority: normal
Severity: normal Version: trunk
Component: Posts, Post Types Keywords:
Focuses: administration Cc:
PR Number:

Description

The transition_post_status hook is getting triggered twice for scheduled posts when using block editor with the same $old_status and $new_status parameters.

Here are the steps to replicate this.

<?php
        add_action( 'transition_post_status', 'on_post_status_changed', 10, 3 );

        function on_post_status_changed( $old_status, $new_status, $post ) {
                error_log( "$old_status -> $new_status for " . $post->ID );
        }
  • Add the above code in a new plugin or functions.php file
  • Create a new post in block editor and schedule it
  • The hook will be triggered and you will get entries in the error log
  • Now Make some changes and then click the Schedule button
  • The hook will be triggered twice and you will two entires in the error log. Both the entires will have the old and new status and future.

If we don't use the block editor but only the classic editor, then it will be triggered only once.

Change History (1)

#1 @noisysocks
2 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to reported-upstream
  • Status changed from new to closed

Hi @sudar! This definitely looks like a bug in the block editor, though some more digging is required to figure out what's causing it. There's an existing issue for this bug in the Gutenberg repository, so let's move discussion here:

https://github.com/WordPress/gutenberg/issues/15094

Note: See TracTickets for help on using tickets.