Support » Plugins » Network activating; if ( !current_user_can( ‘manage_options’ ) ) locks me out…

  • Hi,

    I use this snippet in a plugin;

    if ( !current_user_can( 'manage_options' ) )
      do something

    I also tried;

    if ( ! ( current_user_can( 'manage_options' ) ) )
      do something

    both options work when I activate the plugin, but if I network activate it, I get locked out of the admin area. WP says “You don’t have authority to this page” or something (translating from Swedish).

    And yes, the code it runs works, if I don’t do this checkup.
    See github for an example of how I try to implement it.

    How come? I’ve tried it out many times and tried to tweak the code, but it does not work.
    I also have to include the pluggable.php to get current_user_can to work at all.

    Any better way of checking it user does NOT have authority to manage options (does not have admin capabilities)?
    It’s not necessary to network activate the plugin, but if someone does I don’t want them to be locked out of there site…

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter George Bredberg


    In fact, is_super_admin locks me out to.. How to check user capabilities in a multi-site installation?
    It works, as long as I don’t network activate the script..

    Thread Starter George Bredberg


    Surely someone has to have noticed this before?
    Really tried to google this, but noop..

    Try this in a php file in your plugins folder, and network activate it;

    * Plugin Name: Lock your self out
    * Plugin URI:
    * Description: Show how you get locked out when using current_user_can in a plugin that get's network activated.
    * Version: 0.0.1
    * Author: George Bredberg
    * Author URI:
    * License GPLv3
    * License URI:
    if(!function_exists('wp_get_current_user')) { require_once(ABSPATH . "wp-includes/pluggable.php"); }
    // Down locks me out of admin area...
    if (!(current_user_can('manage_options'))) {
    	echo "<h1><center>Doing something here....</center></h1>";

    Also available as gist on Github

    How can I get passed this problem (I.E. be able to check user abilities and not risk that people get locked out of admin if network activating the plugin.)?

    Regards /George

    Thread Starter George Bredberg


    Seems current_user_can has to be wrapped up in a call that delays it a bit.
    Used wp_loaded to trigger the function and then it works without locking me out when network activating.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Network activating; if ( !current_user_can( ‘manage_options’ ) ) locks me out…’ is closed to new replies.