Skip to content

Commit

Permalink
Fixed an error with admin menu capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
sheabunge committed Apr 28, 2013
1 parent 36ec1de commit be1e84e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
30 changes: 23 additions & 7 deletions code-snippets.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,25 +512,41 @@ function setup_ms_roles( $install = true ) {
/**
* Check if the current user can perform some action on snippets or not
*
* If multisite, checks if *Enable Administration Menus: Snippets* is active
* under the *Settings > Network Settings* network admin menu
*
* @uses current_user_can() To check if the current user can perform a task
* @uses current_user_can() To check if the current user can perform a task
* @uses $this->get_cap() To get the required capability
*
* @param string $do_what The task to check against.
* @return bool Whether the current user can perform this task or not
*
* @since 1.7.2 Moved logic to $this->get_cap method
* @since 1.7.1
* @access public
*/
public function user_can( $do_what ) {
return current_user_can( $this->get_cap( $do_what ) );
}

/**
* Get the required capability to perform a certain action on snippets.
* Does not check if the user has this capability or not.
*
* If multisite, checks if *Enable Administration Menus: Snippets* is active
* under the *Settings > Network Settings* network admin menu
*
* @since 1.7.2
* @access public
*/
public function get_cap( $do_what ) {

if ( is_multisite() ) {

if ( in_array( 'snippets', get_site_option( 'menu_items' ) ) )
return current_user_can( "{$do_what}_snippets" );
return "{$do_what}_snippets";
else
return current_user_can( "{$do_what}_network_snippets" );
return "{$do_what}_network_snippets";

} else {
return current_user_can( "{$do_what}_snippets" );
return "{$do_what}_snippets";
}
}

Expand Down
8 changes: 4 additions & 4 deletions includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function add_admin_menus() {
$this->manage_page = add_menu_page(
__('Snippets', 'code-snippets'),
__('Snippets', 'code-snippets'),
is_multisite() ? 'manage_network_snippets' : 'manage_snippets',
$code_snippets->get_cap( 'manage' ),
$this->manage_slug,
array( $this, 'display_manage_menu' ),
$menu_icon,
Expand All @@ -192,7 +192,7 @@ function add_admin_menus() {
$this->manage_slug,
__('Snippets', 'code-snippets'),
__('Manage', 'code-snippets'),
$code_snippets->user_can( 'manage' ),
$code_snippets->get_cap( 'manage' ),
$this->manage_slug,
array( $this, 'display_manage_menu')
);
Expand All @@ -204,7 +204,7 @@ function add_admin_menus() {
$this->manage_slug,
$editing ? __('Edit Snippet', 'code-snippets') : __('Add New Snippet', 'code-snippets'),
$editing ? __('Edit', 'code-snippets') : __('Add New', 'code-snippets'),
$code_snippets->user_can( 'install' ),
$code_snippets->get_cap( 'install' ),
$this->single_slug,
array( $this, 'display_single_menu' )
);
Expand Down Expand Up @@ -236,7 +236,7 @@ function add_import_admin_menu() {
$this->manage_slug,
__('Import Snippets', 'code-snippets'),
__('Import', 'code-snippets'),
$code_snippets->user_can( 'import' ),
$code_snippets->get_cap( 'import' ),
'import-code-snippets',
array( $this, 'display_import_menu' )
);
Expand Down

0 comments on commit be1e84e

Please sign in to comment.