WordPress.org

Make WordPress Core

Opened 3 months ago

Closed 3 months ago

#47394 closed defect (bug) (invalid)

Gutenberg doesn't respond is_admin on firing save_post action

Reported by: SGr33n Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Editor Keywords:
Focuses: Cc:

Description

Hi,
I'm the developer of a plugin that use the action save_post inside a is_admin() condition. It's working since the first version but if I activate Gutenberg doesn't work anymore, it begin working if I move the add_action outside the is_admin condition.

Since this is a different behavior than before and I also see that on forums there are people asking why save_post doesn't work on Gutenberg (this is not true), I suppose this could be a bug.

Change History (2)

#1 @SergeyBiryukov
3 months ago

There's a WP_Screen::is_block_editor() method that might be helpful:

global $current_screen;
$is_block_editor = ( $current_screen instanceof WP_Screen ) && $current_screen->is_block_editor();

#2 @ocean90
3 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Version 5.2.1 deleted

The block editor is using the REST API to get and save data, including posts. So you either have to check for a REST request or remove the condition altogether.

Related: https://github.com/WordPress/gutenberg/issues/11138

Note: See TracTickets for help on using tickets.