Commit 581c155 1 parent e358637 commit 581c155 Copy full SHA for 581c155
File tree 4 files changed +60
-8
lines changed
4 files changed +60
-8
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * @package MultipleAuthors\
4
+ * @author PublishPress <[email protected] >
5
+ * @copyright Copyright (C) 2018 PublishPress. All rights reserved.
6
+ * @license GPLv2 or later
7
+ * @since 1.0.0
8
+ */
9
+
10
+ namespace MultipleAuthors ;
11
+
12
+ defined ('ABSPATH ' ) or die ('No direct script access allowed. ' );
13
+
14
+
15
+ abstract class Capability
16
+ {
17
+ public static function getManageAuthorsCapability ()
18
+ {
19
+ return apply_filters ('pp_multiple_authors_manage_authors_cap ' , 'ppma_manage_authors ' );
20
+ }
21
+
22
+ public static function getManageOptionsCapability ()
23
+ {
24
+ return apply_filters ('pp_multiple_authors_manage_settings_cap ' , 'manage_options ' );
25
+ }
26
+
27
+ public static function getEditPostAuthorsCapability ()
28
+ {
29
+ return apply_filters ('pp_multiple_authors_edit_post_authors ' , 'ppma_edit_post_authors ' );
30
+ }
31
+
32
+ public static function currentUserCanManageSettings ()
33
+ {
34
+ return current_user_can (self ::getManageOptionsCapability ());
35
+ }
36
+
37
+ public static function currentUserCanManageAuthors ()
38
+ {
39
+ return current_user_can (self ::getManageAuthorsCapability ());
40
+ }
41
+
42
+ public static function currentUserCanEditPostAuthors ()
43
+ {
44
+ return current_user_can (self ::getEditPostAuthorsCapability ());
45
+ }
46
+ }
Original file line number Diff line number Diff line change 23
23
24
24
namespace MultipleAuthors \Classes ;
25
25
26
+ use MultipleAuthors \Capability ;
26
27
use MultipleAuthors \Classes \Objects \Author ;
27
28
use WP_Role ;
28
29
@@ -323,9 +324,9 @@ public static function createAuthorTermsForPostsWithLegacyCoreAuthors($args = nu
323
324
private static function addDefaultCapabilitiesForAdministrators ()
324
325
{
325
326
$ role = get_role ('administrator ' );
326
- $ role ->add_cap (' ppma_manage_authors ' );
327
- $ role ->add_cap (' manage_options ' );
328
- $ role ->add_cap (' ppma_edit_post_authors ' );
327
+ $ role ->add_cap (Capability:: getManageAuthorsCapability () );
328
+ $ role ->add_cap (Capability:: getManageAuthorsCapability () );
329
+ $ role ->add_cap (Capability:: getEditPostAuthorsCapability () );
329
330
}
330
331
331
332
/**
Original file line number Diff line number Diff line change 21
21
* along with PublishPress. If not, see <http://www.gnu.org/licenses/>.
22
22
*/
23
23
24
+ use MultipleAuthors \Capability ;
24
25
use MultipleAuthors \Classes \Admin_Ajax ;
25
26
use MultipleAuthors \Classes \Author_Utils ;
26
27
use MultipleAuthors \Classes \Installer ;
@@ -1695,8 +1696,7 @@ public function handle_maintenance_task()
1695
1696
wp_die (esc_html__ ('Invalid nonce ' , 'publishpress-authors ' ));
1696
1697
}
1697
1698
1698
- $ capability = apply_filters ('pp_multiple_authors_manage_settings_cap ' , 'manage_options ' );
1699
- if (! current_user_can ($ capability )) {
1699
+ if (! Capability::currentUserCanManageSettings ()) {
1700
1700
wp_die (esc_html__ ('Access denied ' , 'publishpress-authors ' ));
1701
1701
}
1702
1702
@@ -2124,6 +2124,10 @@ public function getCoauthorsMigrationData()
2124
2124
wp_send_json_error (null , 403 );
2125
2125
}
2126
2126
2127
+ if (! Capability::currentUserCanManageSettings ()) {
2128
+ wp_send_json_error (null , 403 );
2129
+ }
2130
+
2127
2131
// nonce: migrate_coauthors
2128
2132
wp_send_json (
2129
2133
[
@@ -2470,7 +2474,7 @@ public function coauthorsMigrationNotice()
2470
2474
return ;
2471
2475
}
2472
2476
2473
- if (!current_user_can ( ' manage_options ' )) {
2477
+ if (! Capability:: currentUserCanManageSettings ( )) {
2474
2478
return ;
2475
2479
}
2476
2480
Original file line number Diff line number Diff line change 28
28
* along with PublishPress. If not, see <http://www.gnu.org/licenses/>.
29
29
*/
30
30
31
+ use MultipleAuthors \Capability ;
31
32
use MultipleAuthors \Classes \Legacy \Module ;
32
33
use MultipleAuthors \Classes \Legacy \Util ;
33
34
use MultipleAuthors \Factory ;
@@ -98,7 +99,7 @@ public function action_admin_submenu()
98
99
MA_Multiple_Authors::MENU_SLUG ,
99
100
esc_html__ ('Multiple Authors Settings ' , 'publishpress-authors ' ),
100
101
esc_html__ ('Settings ' , 'publishpress-authors ' ),
101
- apply_filters ( ' pp_multiple_authors_manage_settings_cap ' , ' manage_options ' ),
102
+ Capability:: getManageOptionsCapability ( ),
102
103
self ::MENU_SLUG ,
103
104
[$ this , 'options_page_controller ' ],
104
105
20
@@ -297,7 +298,7 @@ public function helper_settings_validate_and_save()
297
298
return false ;
298
299
}
299
300
300
- if (!current_user_can ( ' manage_options ' ) || !wp_verify_nonce ($ _POST ['_wpnonce ' ], 'edit-publishpress-settings ' )) {
301
+ if (!Capability:: currentUserCanManageSettings ( ) || !wp_verify_nonce ($ _POST ['_wpnonce ' ], 'edit-publishpress-settings ' )) {
301
302
wp_die (__ ('Cheatin’ uh? ' ));
302
303
}
303
304
You can’t perform that action at this time.
0 commit comments