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

WordPress Trac noreply at wordpress.org
Fri Mar 26 19:42:27 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 theMikeD):

 What is the suggested way to write this code that evidently no longer

 if ( is_admin() ) {
         $admin = new Admin();
 } else {
         $front_end = new FrontEnd();

 If I understand what you're saying correctly, when a class is instantiated
 at the beginning of the page load process, this simple check to see if
 you're in the admin area fails for every block editor page. Further,
 because the instantiation happens earlier than `current_screen` the
 improved `is_admin` code I linked to earlier, also fails.

 What is the suggested best practice here to identify if I am in the admin
 or not, in every possible case? Is the only way to know for sure that I am
 in the admin by hooking to `current_screen` and seeing if it works?
 Because while this may work for the admin code, it removes the ability to
 do the else statement code does it not?

 This seems to me to be a pretty big deal. I've added a note to the
 is_admin() page but I'd like to augment that note with the best practice.

 For example, this seems to no longer be true either


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

More information about the wp-trac mailing list