is_admin() returns false in save_post hook with Gutenberg editor

Question

I have a plugin that implements a REST API that needs to be notified when an admin adds one of my supported shortcodes to a page or post. I hook save_post with my function like this.

        add_action( 'save_post', 'detect_shortcodes');

However, when I update from the editor, it does an ajax call that instantiates my plugin. The first thing it does is determine whether to load public or admin hooks like this.

    if(is_admin())
    {
        $this->define_admin_hooks();
    }
    else
    {
        $this->define_public_hooks();
    }

Of course, my detect_shortcodes function is on the admin side. With the TinyMCE editor, this worked correctly, and instantiated my admin hooks. With the Gutenberg editor, is_admin() returns false.

Is there a replacement for is_admin() that will work with Gutenberg ajax calls?

0
, , AldenG 4 years 2020-05-25T16:10:19-05:00 0 Answers 85 views 0

Leave an answer

Browse
Browse