capabilities = $capabilities; } /** * {@inheritDoc} */ public function register_hooks(): void { add_action( 'rest_api_init', array( $this, 'register_routes' ) ); } /** * Registers the controller's routes. * * @return void */ abstract public function register_routes(): void; /** * Permission callback shared by all routes. * * @return true|WP_Error */ public function check_permission() { if ( $this->capabilities->current_user_can_manage() ) { return true; } return new WP_Error( 'rest_forbidden', __( 'Sorry, you are not allowed to sync content.', 'cherrylift' ), array( 'status' => rest_authorization_required_code() ) ); } }