Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_admin Not working #11138

Closed
ghost opened this issue Oct 26, 2018 · 2 comments
Closed

is_admin Not working #11138

ghost opened this issue Oct 26, 2018 · 2 comments
Labels
[Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@ghost
Copy link

ghost commented Oct 26, 2018

Describe the bug 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;
}

if(wp_doing_ajax()) return 1;

return 0;
}

To Reproduce
Steps to reproduce the behavior:
call is_admin from server while saving a post.

Expected behavior
is_admin should return true on the editor screen

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
4.1.1

@swissspidy
Copy link
Member

Hey there

Since Gutenberg uses the REST API to save posts, you would have to check for that, not is_admin or wp_doing_ajax

@ocean90 ocean90 added the [Type] Help Request Help with setup, implementation, or "How do I?" questions. label Oct 27, 2018
@ocean90
Copy link
Member

ocean90 commented Oct 27, 2018

I'm wondering why you have to do that check?

With the introduction of the REST API posts can also be created outside of wp-admin. And as said before, the new editor is using the REST API for all interactions so you have to adjust your plugin for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

2 participants