WordPress.org

Ready to get started?Download WordPress

Forums

Only "administrators" and not "editors" can see/use my plugin? (2 posts)

  1. icydash
    Member
    Posted 1 year ago #

    Hi guys.

    So I'm learning to make WordPress plugins and I have run into a small speed bump. My plugin code works perfectly and does exactly what I want. It is as follows:

    <?php
    /*
    Plugin Name: edited
    Plugin URI: edited
    Description: Allows updating of the current volume & issue on the homepage.
    Version: 1.0
    Author: edited
    Author URI: edited
    License: GPL2
    */
    
    // Hook for adding admin menus
    add_action('admin_menu', 'mt_add_pages');
    
    // Action function for above hook
    function mt_add_pages()
    {
        // Add a new top-level menu (ill-advised):
    	// add_menu_page('Current Issue/Volume','Current Issue/Volume', 'manage_options', 'current_volume', 'current_volume_page' );
    	add_menu_page(__('Current Issue/Volume','menu-test'), __('Current Issue/Volume','menu-test'), 'manage_options', 'current_volume_handle', 'current_volume_page' );
    }
    
    // Displays the page content for the current issue/volume page
    function current_volume_page()
    {
    
        //must check that the user has the required capability
        if (!current_user_can('manage_options'))
        {
          wp_die( __('You do not have sufficient permissions to access this page.') );
        }
    
        // variables for the field and option names
        $opt_name = 'mt_issue_num';
    	$opt_name2 = 'mt_volume';
        $hidden_field_name = 'mt_submit_hidden';
        $data_field_name = 'mt_issue_num';
    	$data_field_name2 = 'mt_volume';
    
        // Read in existing option value from database
        $opt_val = get_option( $opt_name );
    	$opt_val2 = get_option( $opt_name2 );
    
        // See if the user has posted us some information
        // If they did, this hidden field will be set to 'Y'
        if( isset($_POST[ $hidden_field_name ]) && $_POST[ $hidden_field_name ] == 'Y' )
    	{
    		// Read their posted value
            $opt_val = $_POST[ $data_field_name ];
            $opt_val2 = $_POST[ $data_field_name2 ];
    
            // Save the posted value in the database
            update_option( $opt_name, $opt_val );
            update_option( $opt_name2, $opt_val2 );
    
            // Put an settings updated message on the screen
    		?>
    		<div class="updated"><p><strong><?php _e('settings saved.', 'menu-test' ); ?></strong></p></div>
    		<?php
        }
    
        // Now display the settings editing screen
    
        echo '<div class="wrap">';
    
        // header
    
        echo "<h2>" . __( 'Current Issue and Volume Settings', 'menu-test' ) . "</h2>";
    
        // settings form
    
        ?>
    
    <form name="form1" method="post" action="">
    <input type="hidden" name="<?php echo $hidden_field_name; ?>" value="Y">
    
    <p><?php _e("Current issue number:", 'menu-test' ); ?>
    <input type="text" name="<?php echo $data_field_name; ?>" value="<?php echo $opt_val; ?>" size="20">
    <p><?php _e("Current volume:", 'menu-test' ); ?>
    <input type="text" name="<?php echo $data_field_name2; ?>" value="<?php echo $opt_val2; ?>" size="20">
    </p><hr />
    
    <p class="submit">
    <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" />
    </p>
    
    </form>
    </div>
    
    <?php
    
    }
    
    ?>

    The problem: only WordPress users with "Administrator" level access can see/use my plugin. However, I would like "Editors" to be able to see/use my plugin, too. So what am I doing wrong?

  2. icydash
    Member
    Posted 1 year ago #

    Never mind. I figured it out. Needed to swap out "manage_options" in all its spots in the code with "moderate_comments".

Topic Closed

This topic has been closed to new replies.

About this Topic