WordPress.org

Support

Support » Plugins and Hacks » [Resolved] The 'sufficient permissions' message out of nothing

[Resolved] The 'sufficient permissions' message out of nothing

  • I’m developing a plugin with some basic settings.
    I have been able to access the settings page until now, but after making some minor changes to the code, I started getting the “You do not have sufficient permissions to access this page.” message.

    Here’s what it does:

    in the constructor:
    add_action( 'admin_init', array( $this, 'mc_register_settings') );

    the register settings function

    add_options_page(
    	PLUGIN_NAME,
    	PLUGIN_NAME,
    	'read', //this was originally 'manage_options'
    	PLUGIN_SLUG,
    	array( $this, 'mc_output_options_page' )
    );
    
    // CREATE 'GENERAL OPTIONS' SECTION
    add_settings_section(
    	'sve_general_options',
    	'General settings',
    	array( $this, 'mc_output_settings_section_general' ),
    	PLUGIN_SLUG
    );
    
    // ADD 'DEFAULT DIRECTORY' SETTING
    add_settings_field(
    	'sve_options_default_directory',
    	'Video directory (default is /wp-content/uploads/video',
    	array($this, 'mc_output_option_default_directory'),
    	PLUGIN_SLUG,
    	'sve_general_options'
    );
    
    ...

    then I add two more fields and register them with register_setting('mc_sve_options', '[optionname]');

    here’s the output options function

    function mc_output_options_page()
    {
    	?>
    	<div class="wrap">
    	<h2><?php echo PLUGIN_NAME; ?> Settings</h2>
    
    	<form method="post" action="options.php">
    
    		<?php settings_fields( 'mc_sve_options' ); ?>
    		<?php do_settings_sections( PLUGIN_SLUG ); ?>
    		<?php submit_button(); ?>
    
    	</form>
    	</div>
    	<?php
    }

    Any ideas ?

Viewing 10 replies - 1 through 10 (of 10 total)
  • What were the ‘minor changes’ that triggered the error?

    Before the error, I was outputting the form manually (into a table) and now, well, you can see the function. I changed it, because this is supposed to be correct way and because it didn’t save the changes I made.

    I tried to comment out all code that is relevant to the output, so there’s only

    add_action( 'admin_init', array( $this, 'mc_register_settings') );

    function mc_register_settings()
    {
    	add_options_page(
    		PLUGIN_NAME,
    		PLUGIN_NAME,
    		'read',
    		PLUGIN_SLUG,
    		array( $this, 'mc_output_options_page' )
    	);
    }
    function mc_output_options_page()
    {
        echo 'whatever';
    }

    I still get the error.

    Have you tried with some other capability, like ‘manage_options’ (which works for me in one of my projects and which is why I mention that on in particular)?

    Yup, ‘manage_options’ was the one I used originally. I tried ‘read’, because that’s the lowest possible. So it must be something else.

    Are you, as implied by the code and by a post you made earlier, in object context– this code is inside a class? Are PLUGIN_NAME and PLUGIN_SLUG properly defined constants, and not class constants? Class constants need to be self::PLUGIN_NAME not just PLUGIN_NAME.

    Yeah, it’s OOP.
    They are defined in the constructor with the define function define(NAME, ‘value’).
    I simply call them without the ‘self::’. I’ll try it the other way when I get to the code, which will be tomorrow and will let you know. Thank you for your time so far.

    Sorry about some of the obvious questions. Sometimes you have to ask anyway…

    I simply call them without the ‘self::’. I’ll try it the other way when I get to the code, which will be tomorrow and will let you know.

    Defined the way you have, it should work, and using self:: would break. To use self:: you have to declare the constants with the const keyword.

    Can you post you whole class to the pastebin?

    Here it is…

    Hook mc_register_settings to admin_menu instead of to admin_init. I don’t know that that is the issue. I am am just matching up pieces of your code to pieces of my working code.

    And it works !!!
    Awesome. Thank you very much.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Resolved] The 'sufficient permissions' message out of nothing’ is closed to new replies.