[wp-trac] [WordPress Trac] #47394: Gutenberg doesn't respond is_admin on firing save_post action

WordPress Trac noreply at wordpress.org
Sat Mar 20 20:34:36 UTC 2021


#47394: Gutenberg doesn't respond is_admin on firing save_post action
--------------------------+----------------------
 Reporter:  SGr33n        |       Owner:  (none)
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  Editor        |     Version:
 Severity:  normal        |  Resolution:  invalid
 Keywords:                |     Focuses:
--------------------------+----------------------

Comment (by SergeyBiryukov):

 Replying to [comment:4 theMikeD]:
 > your suggested fix is not working when editing a post. I get `null` for
 `$current screen`
 >
 > {{{
 > public function better_is_admin() {
 >       if ( is_admin() ) {
 >               error_log( "Admin" );
 >               return true;
 >       }
 >       global $current_screen;
 >       if ( $current_screen instanceof \WP_Screen &&
 $current_screen->is_block_editor() ) {
 >               error_log( "Admin" );
 >               return true;
 >       };
 >       error_log( "Not Admin" );
 >       return false;
 > }
 > }}}

 It's not quite clear when exactly your code runs. Calling it after the
 current screen is set, e.g. on the
 [https://developer.wordpress.org/reference/hooks/current_screen/
 current_screen] action or later, seems to work as expected for me.

 Core itself uses the same method in a few places, e.g. in
 [source:tags/5.7/src/wp-admin/admin-header.php?marks=192#L190 admin
 header], or in [source:tags/5.7/src/wp-admin/includes/class-wp-privacy-
 policy-content.php?marks=334#L330 privacy policy guide].

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47394#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list