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

Permission Issue (wp-admin redirect) #477

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

Comments

5 participants
@tareq1988

tareq1988 commented May 29, 2013

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

This comment has been minimized.

Show comment
Hide comment
@scribu

scribu May 29, 2013

Member

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

Member

scribu commented May 29, 2013

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

@scribu

This comment has been minimized.

Show comment
Hide comment
@scribu

scribu May 29, 2013

Member

There are several ways to fix it:

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

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

This comment has been minimized.

Show comment
Hide comment
@tareq1988

tareq1988 May 30, 2013

Okay, thanks.

tareq1988 commented May 30, 2013

Okay, thanks.

@hipnoddic

This comment has been minimized.

Show comment
Hide comment
@hipnoddic

hipnoddic Aug 14, 2013

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

hipnoddic commented Aug 14, 2013

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

This comment has been minimized.

Show comment
Hide comment
@scribu

scribu Aug 14, 2013

Member

The other option is to upgrade to the dev version:

cd ~/.wp-cli
php composer.phar require wp-cli/wp-cli=dev-master
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

This comment has been minimized.

Show comment
Hide comment
@hipnoddic

hipnoddic Aug 14, 2013

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

WP-CLI version: 0.12-alpha2

hipnoddic commented Aug 14, 2013

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

WP-CLI version: 0.12-alpha2

@eyedarts

This comment has been minimized.

Show comment
Hide comment
@eyedarts

eyedarts 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.

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

This comment has been minimized.

Show comment
Hide comment
@scribu

scribu Sep 2, 2013

Member

@eyedarts The link you pasted returns a 404.

Member

scribu commented Sep 2, 2013

@eyedarts The link you pasted returns a 404.

@wojsmol

This comment has been minimized.

Show comment
Hide comment
@wojsmol

wojsmol Sep 2, 2013

Contributor

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

Contributor

wojsmol commented Sep 2, 2013

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

@scribu

This comment has been minimized.

Show comment
Hide comment
@scribu

scribu Sep 2, 2013

Member

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

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