• I have a plugin that relies on is_admin returning true when save_post is fired from the editor screen. The new editor does not seem to return true when is_admin is called after clicking the update button. I have tried a number of work arounds such as this function but it to fails to recognize that it is on the editor screen.

    function is_admin_request() {
    $current_url = home_url( add_query_arg( null, null ) );
    $admin_url = strtolower( admin_url() );
    if ( strpos( $current_url, $admin_url ) ) {
    return 1;
    }

    if(wp_doing_ajax()) return 1;

    return 0;
    }

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Marius L. J.

    (@clorith)

    Hiya,

    So the save feature in Gutenberg is done using the REST API, and because of how is_admin() works (it looks if you’re in mysite.com/wp-admin/*) checking it like you are describing, if I understand you correctly, won’t work.

    Could i ask what the use case is here so we can find the best solution, why does it need to only work from the admin post editor?

    Thread Starter seshelby

    (@seshelby)

    It doesn’t have to and I have found a work around but I do believe it was not a good idea for this new editor to fundamentally change how wordpress core works. There are going to be a lot of broken plugins like mine that have to be re-written to support a plugin that is to be frank, not user friendly. I for one will make my plugins work with it but not use it on any of my websites.

    Moderator Marius L. J.

    (@clorith)

    True, there are many moving pieces in WordPress, this is also why we’ve been very open about the development for such a long time.

    I’d still like ot hear the use cases, even though you found a workaround for your case, it may be something we’ve not considered that would benefit others if we know of it ??

    Not to jump and take over this thread, but I too am a plugin developer which is facing this same issue. The following code for tracking page views for me no longer works as intended as every time the post/page is saved using the Gutenberg editor it tracks two additional page views.

    	protected function save_page_view__premium_only( $user_id, $post_id ) {
    
    		global $wpdb;
    
    		if (! is_admin()){
    
    			$results = $wpdb->insert(
    				$wpdb->prefix . 'pageviews',
    				array(
    					'user_id'   => $user_id,
    					'post_id'   => $post_id,
    					'timestamp' => current_time()->toDateTimeString(),
    				),
    				array(
    					'user_id'   => '%d',
    					'post_id'   => '%d',
    					'timestamp' => '%s',
    				)
    			);
    
    			return $results;
    		}
    
    		return false;
    
    	}
    Moderator Marius L. J.

    (@clorith)

    @mattpramschufer That’s exactly what you are doing, please create your own topic, as this thread is more than 5 months old, and not even about the same issue.

    I am closing this thread to avoid further resurrections of an old topic.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘is_admin Not working’ is closed to new replies.