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