Skip to content

Commit be1e84e

Browse files
committed
Fixed an error with admin menu capabilities
1 parent 36ec1de commit be1e84e

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

code-snippets.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,25 +512,41 @@ function setup_ms_roles( $install = true ) {
512512
/**
513513
* Check if the current user can perform some action on snippets or not
514514
*
515-
* If multisite, checks if *Enable Administration Menus: Snippets* is active
516-
* under the *Settings > Network Settings* network admin menu
517-
*
518-
* @uses current_user_can() To check if the current user can perform a task
515+
* @uses current_user_can() To check if the current user can perform a task
516+
* @uses $this->get_cap() To get the required capability
519517
*
520518
* @param string $do_what The task to check against.
521519
* @return bool Whether the current user can perform this task or not
520+
*
521+
* @since 1.7.2 Moved logic to $this->get_cap method
522+
* @since 1.7.1
523+
* @access public
522524
*/
523525
public function user_can( $do_what ) {
526+
return current_user_can( $this->get_cap( $do_what ) );
527+
}
528+
529+
/**
530+
* Get the required capability to perform a certain action on snippets.
531+
* Does not check if the user has this capability or not.
532+
*
533+
* If multisite, checks if *Enable Administration Menus: Snippets* is active
534+
* under the *Settings > Network Settings* network admin menu
535+
*
536+
* @since 1.7.2
537+
* @access public
538+
*/
539+
public function get_cap( $do_what ) {
524540

525541
if ( is_multisite() ) {
526542

527543
if ( in_array( 'snippets', get_site_option( 'menu_items' ) ) )
528-
return current_user_can( "{$do_what}_snippets" );
544+
return "{$do_what}_snippets";
529545
else
530-
return current_user_can( "{$do_what}_network_snippets" );
546+
return "{$do_what}_network_snippets";
531547

532548
} else {
533-
return current_user_can( "{$do_what}_snippets" );
549+
return "{$do_what}_snippets";
534550
}
535551
}
536552

includes/class-admin.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function add_admin_menus() {
181181
$this->manage_page = add_menu_page(
182182
__('Snippets', 'code-snippets'),
183183
__('Snippets', 'code-snippets'),
184-
is_multisite() ? 'manage_network_snippets' : 'manage_snippets',
184+
$code_snippets->get_cap( 'manage' ),
185185
$this->manage_slug,
186186
array( $this, 'display_manage_menu' ),
187187
$menu_icon,
@@ -192,7 +192,7 @@ function add_admin_menus() {
192192
$this->manage_slug,
193193
__('Snippets', 'code-snippets'),
194194
__('Manage', 'code-snippets'),
195-
$code_snippets->user_can( 'manage' ),
195+
$code_snippets->get_cap( 'manage' ),
196196
$this->manage_slug,
197197
array( $this, 'display_manage_menu')
198198
);
@@ -204,7 +204,7 @@ function add_admin_menus() {
204204
$this->manage_slug,
205205
$editing ? __('Edit Snippet', 'code-snippets') : __('Add New Snippet', 'code-snippets'),
206206
$editing ? __('Edit', 'code-snippets') : __('Add New', 'code-snippets'),
207-
$code_snippets->user_can( 'install' ),
207+
$code_snippets->get_cap( 'install' ),
208208
$this->single_slug,
209209
array( $this, 'display_single_menu' )
210210
);
@@ -236,7 +236,7 @@ function add_import_admin_menu() {
236236
$this->manage_slug,
237237
__('Import Snippets', 'code-snippets'),
238238
__('Import', 'code-snippets'),
239-
$code_snippets->user_can( 'import' ),
239+
$code_snippets->get_cap( 'import' ),
240240
'import-code-snippets',
241241
array( $this, 'display_import_menu' )
242242
);

0 commit comments

Comments
 (0)