-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4c4074
commit 319e8c9
Showing
6 changed files
with
113 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
namespace NewfoldLabs\WP\Module\Performance; | ||
|
||
/** | ||
* Permissions and Authorization constants and utilities. | ||
*/ | ||
final class Permissions { | ||
/** | ||
* WordPress Admin capability string | ||
*/ | ||
const ADMIN = 'manage_options'; | ||
const INSTALL_THEMES = 'install_themes'; | ||
const EDIT_THEMES = 'edit_themes'; | ||
|
||
/** | ||
* Confirm REST API caller has ADMIN user capabilities. | ||
* | ||
* @return boolean | ||
*/ | ||
public static function rest_is_authorized_admin() { | ||
return \is_user_logged_in() && \current_user_can( self::ADMIN ); | ||
} | ||
|
||
/** | ||
* Confirm logged-in user is in wp-admin and has ADMIN user capabilities. | ||
* | ||
* @return boolean | ||
*/ | ||
public static function is_authorized_admin() { | ||
return \is_admin() && self::rest_is_authorized_admin(); | ||
} | ||
|
||
/** | ||
* Confirm logged-in user can manage themes. | ||
* | ||
* @return boolean | ||
*/ | ||
public static function rest_can_manage_themes() { | ||
return \is_user_logged_in() && | ||
\current_user_can( self::INSTALL_THEMES ) && | ||
\current_user_can( self::EDIT_THEMES ); | ||
} | ||
|
||
/** | ||
* Confirm whether user has ADMIN user and edit_post capabilities for creating pages. | ||
* | ||
* @return boolean | ||
*/ | ||
public static function custom_post_authorized_admin() { | ||
return \current_user_can( 'edit_posts' ) && \current_user_can( self::ADMIN ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace NewfoldLabs\WP\Module\Performance\RestApi; | ||
|
||
//use NewfoldLabs\WP\Module\Onboarding\RestApi\RestApiFilter; | ||
|
||
/** | ||
* Instantiate controllers and register routes. | ||
*/ | ||
final class RestApi { | ||
|
||
/** | ||
* List of custom REST API controllers | ||
* | ||
* @var array | ||
*/ | ||
protected $controllers = array( | ||
'NewfoldLabs\\WP\\Module\\Performance\\RestApi\\JetpackController', | ||
); | ||
|
||
/** | ||
* Setup the custom REST API | ||
*/ | ||
public function __construct() { | ||
add_action( 'rest_api_init', array( $this, 'register_routes' ) ); | ||
} | ||
|
||
/** | ||
* Register the custom REST API routes | ||
*/ | ||
public function register_routes() { | ||
foreach ( $this->controllers as $controller ) { | ||
/** | ||
* Get an instance of the WP_REST_Controller. | ||
* | ||
* @var $instance WP_REST_Controller | ||
*/ | ||
$instance = new $controller(); | ||
$instance->register_routes(); | ||
} | ||
} | ||
} |