Permission Issue (wp-admin redirect) #477

Closed
tareq1988 opened this Issue May 29, 2013 · 10 comments

Projects

None yet

5 participants

@tareq1988

I have a plugin which does admin area blocking based on user roles. The code is as follows (runs on admin_init):

function block_admin_access() {
    global $pagenow;

    $access_level = wpuf_get_option( 'admin_access', 'wpuf_general', 'read' );
    $valid_pages = array('admin-ajax.php', 'async-upload.php', 'media-upload.php');

    if ( !current_user_can( $access_level ) && !in_array( $pagenow, $valid_pages ) ) {
        wp_die( __( 'Access Denied. Your site administrator has blocked your access to the WordPress back-office.', 'wpuf' ) );
    }
}

It was working fine when I was using WordPress 3.5.1. Recently upgraded to 3.6-beta3 and wp-cli gave some error. So I thought to upgrade to the latest dev(github) version. Now when I run wp command, I get Access Denied. Your site administrator has blocked your access to the WordPress back-office. message which is coming from my plugin, which I think it shouldn't. So I can't run any command while the code is active.

@scribu
Member
scribu commented May 29, 2013

That's because WP-CLI started pretending it's in wp-admin. Long story: #385

@scribu
Member
scribu commented May 29, 2013

There are several ways to fix it:

a) check defined('WP_CLI') in your plugin code
b) pass --user=some_admin to WP-CLI

@tareq1988

Okay, thanks.

@tareq1988 tareq1988 closed this May 30, 2013
@scribu scribu added a commit that referenced this issue Aug 14, 2013
@scribu scribu Don't pretend we're in wp-admin, but continue to load all admin APIs.
The WP_CLI context is not like the WP_ADMIN context. It's a different
animal.

See #674 for more details.

Fixes #477, #519, #574, #579, #582, #669
10845a7
@hipnoddic

Just installed WP-CLI and when I try to execute commands I get the redirect error:

Warning: Some code is trying to do a URL redirect. Backtrace:
#0 WP_CLI\Utils\wp_redirect_handler(http://mysite.com/)
#1 call_user_func_array(WP_CLI\Utils\wp_redirect_handler, Array ([0] => http://mysite.com/)) called at [/Applications/MAMP/htdocs/mysite/wp-includes/plugin.php:173]
#2 apply_filters(wp_redirect, http://mysite.com/, 302) called at [/Applications/MAMP/htdocs/mysite/wp-includes/pluggable.php:865]
#3 wp_redirect(http://mysite.com/, 302) called at [/Applications/MAMP/htdocs/mysite/wp-includes/pluggable.php:923]
#4 wp_safe_redirect(http://mysite.com/) called at [/Applications/MAMP/htdocs/mysite/wp-content/plugins/woocommerce/admin/woocommerce-admin-functions.php:258]
#5 woocommerce_prevent_admin_access()
#6 call_user_func_array(woocommerce_prevent_admin_access, Array ([0] => )) called at [/Applications/MAMP/htdocs/mysite/wp-includes/plugin.php:406]
#7 do_action(admin_init) called at [/Users/username/.wp-cli/vendor/wp-cli/wp-cli/php/wp-cli.php:35]
#8 include(/Users/username/.wp-cli/vendor/wp-cli/wp-cli/php/wp-cli.php) called at [/Users/username/.wp-cli/vendor/wp-cli/wp-cli/php/boot-fs.php:17]

I passed the user flag (with an admin user), but I still get the same error:
wp export --dir=/tmp/ --user=myadmin

Any other options?

WP-CLI version: 0.11.1

@scribu
Member
scribu commented Aug 14, 2013

The other option is to upgrade to the dev version:

cd ~/.wp-cli
php composer.phar require wp-cli/wp-cli=dev-master
@hipnoddic

The dev version worked for me - thanks for the quick (and very helpful) response!

WP-CLI version: 0.12-alpha2

@eyedarts
eyedarts commented Sep 2, 2013

I'm using WP-CLI version: 0.12-alpha2 and am still having this problem whether I pass the admin user or not. The conflicting plugin seems to be Simple IP Ban (http://www.sandorkovacs.ro/ip-ban-wordpress-plugin/) because I'm able to use WP-CLI once I deactivate that plugin. Do you have any suggestions for how I might be able to use both WP-CLI and this plugin? Thanks.

@scribu
Member
scribu commented Sep 2, 2013

@eyedarts The link you pasted returns a 404.

@wojsmol
Contributor
wojsmol commented Sep 2, 2013

Hello
@scribu I found this plugin on wordpress.org - http://wordpress.org/plugins/simple-ip-ban/
Regards

@scribu
Member
scribu commented Sep 2, 2013

Ok, I was able to reproduce the problem. Let's discuss in #741

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment