@@ -153,6 +153,24 @@ public function current_user_can() {
153
153
return current_user_can ( $ this ->get_cap () );
154
154
}
155
155
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
+
156
174
/**
157
175
* Get the required capability to perform a certain action on snippets.
158
176
* Does not check if the user has this capability or not.
@@ -171,11 +189,11 @@ public function get_cap() {
171
189
/* If multisite is enabled and the snippet menu is not activated,
172
190
restrict snippet operations to super admins only */
173
191
if ( empty ( $ menu_perms ['snippets ' ] ) ) {
174
- return apply_filters ( ' code_snippets_network_cap ' , ' manage_network_snippets ' );
192
+ return $ this -> get_network_cap_name ( );
175
193
}
176
194
}
177
195
178
- return apply_filters ( ' code_snippets_cap ' , ' manage_snippets ' );
196
+ return $ this -> get_cap_name ( );
179
197
}
180
198
181
199
/**
@@ -190,7 +208,7 @@ function grant_network_cap( $user_id ) {
190
208
$ user = new WP_User ( $ user_id );
191
209
192
210
/* 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 ( ) );
194
212
}
195
213
196
214
/**
@@ -205,7 +223,7 @@ function remove_network_cap( $user_id ) {
205
223
$ user = new WP_User ( $ user_id );
206
224
207
225
/* 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 ( ) );
209
227
}
210
228
211
229
/**
0 commit comments