Skip to content

Commit 2719466

Browse files
committed
Add methods for retrieving capability names
1 parent 6bdfe69 commit 2719466

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

php/class-code-snippets.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,24 @@ public function current_user_can() {
153153
return current_user_can( $this->get_cap() );
154154
}
155155

156+
/**
157+
* Retrieve the name of the capability required to manage sub-site snippets
158+
*
159+
* @return string
160+
*/
161+
public function get_cap_name() {
162+
return apply_filters( 'code_snippets_cap', 'manage_snippets' );
163+
}
164+
165+
/**
166+
* Retrieve the name of the capability required to manage network snippets
167+
*
168+
* @return string
169+
*/
170+
public function get_network_cap_name() {
171+
return apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' );
172+
}
173+
156174
/**
157175
* Get the required capability to perform a certain action on snippets.
158176
* Does not check if the user has this capability or not.
@@ -171,11 +189,11 @@ public function get_cap() {
171189
/* If multisite is enabled and the snippet menu is not activated,
172190
restrict snippet operations to super admins only */
173191
if ( empty( $menu_perms['snippets'] ) ) {
174-
return apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' );
192+
return $this->get_network_cap_name();
175193
}
176194
}
177195

178-
return apply_filters( 'code_snippets_cap', 'manage_snippets' );
196+
return $this->get_cap_name();
179197
}
180198

181199
/**
@@ -190,7 +208,7 @@ function grant_network_cap( $user_id ) {
190208
$user = new WP_User( $user_id );
191209

192210
/* Add the capability */
193-
$user->add_cap( apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' ) );
211+
$user->add_cap( $this->get_network_cap_name() );
194212
}
195213

196214
/**
@@ -205,7 +223,7 @@ function remove_network_cap( $user_id ) {
205223
$user = new WP_User( $user_id );
206224

207225
/* Remove the capability */
208-
$user->remove_cap( apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' ) );
226+
$user->remove_cap( $this->get_network_cap_name() );
209227
}
210228

211229
/**

php/upgrade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function code_snippets_upgrader() {
2323

2424
/* Register capabilities */
2525
$role = get_role( apply_filters( 'code_snippets_role', 'administrator' ) );
26-
$role->add_cap( apply_filters( 'code_snippets_cap', 'manage_snippets' ) );
26+
$role->add_cap( code_snippets()->get_cap_name() );
2727
}
2828

2929
/* Check if we have upgraded from an older version */

0 commit comments

Comments
 (0)