Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Permissions | |
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
90 | |
0.00% |
0 / 1 |
| rest_is_authorized_admin | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| is_authorized_admin | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| rest_can_manage_themes | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| custom_post_authorized_admin | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace NewfoldLabs\WP\Module\Onboarding; |
| 3 | |
| 4 | /** |
| 5 | * Permissions and Authorization constants and utilities. |
| 6 | */ |
| 7 | final class Permissions { |
| 8 | /** |
| 9 | * WordPress Admin capability string |
| 10 | */ |
| 11 | const ADMIN = 'manage_options'; |
| 12 | const INSTALL_THEMES = 'install_themes'; |
| 13 | const EDIT_THEMES = 'edit_themes'; |
| 14 | |
| 15 | /** |
| 16 | * Confirm REST API caller has ADMIN user capabilities. |
| 17 | * |
| 18 | * @return boolean |
| 19 | */ |
| 20 | public static function rest_is_authorized_admin() { |
| 21 | return \is_user_logged_in() && \current_user_can( self::ADMIN ); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Confirm logged-in user is in wp-admin and has ADMIN user capabilities. |
| 26 | * |
| 27 | * @return boolean |
| 28 | */ |
| 29 | public static function is_authorized_admin() { |
| 30 | return \is_admin() && self::rest_is_authorized_admin(); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Confirm logged-in user can manage themes. |
| 35 | * |
| 36 | * @return boolean |
| 37 | */ |
| 38 | public static function rest_can_manage_themes() { |
| 39 | return \is_user_logged_in() && |
| 40 | \current_user_can( self::INSTALL_THEMES ) && |
| 41 | \current_user_can( self::EDIT_THEMES ); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Confirm whether user has ADMIN user and edit_post capabilities for creating pages. |
| 46 | * |
| 47 | * @return boolean |
| 48 | */ |
| 49 | public static function custom_post_authorized_admin() { |
| 50 | return \current_user_can( 'edit_posts' ) && \current_user_can( self::ADMIN ); |
| 51 | } |
| 52 | } |