/home/vianto5/heredit.mx/wp-content/plugins/wp-rocket/inc/Engine/CDN/RocketCDN
Edit: /home/vianto5/heredit.mx/wp-content/plugins/wp-rocket/inc/Engine/CDN/RocketCDN/RESTSubscriber.php (4225B)
cdn_options = $cdn_options;
$this->options = $options;
}
/**
* {@inheritdoc}
*/
public static function get_subscribed_events() {
return [
'rest_api_init' => [
[ 'register_enable_route' ],
[ 'register_disable_route' ],
],
];
}
/**
* Register Enable route in the WP REST API
*
* @since 3.5
*
* @return void
*/
public function register_enable_route() {
register_rest_route(
self::ROUTE_NAMESPACE,
'rocketcdn/enable',
[
'methods' => 'PUT',
'callback' => [ $this, 'enable' ],
'args' => [
'email' => [
'required' => true,
'validate_callback' => [ $this, 'validate_email' ],
],
'key' => [
'required' => true,
'validate_callback' => [ $this, 'validate_key' ],
],
'url' => [
'required' => true,
'validate_callback' => function ( $param ) {
$url = esc_url_raw( $param );
return ! empty( $url );
},
'sanitize_callback' => function ( $param ) {
return esc_url_raw( $param );
},
],
],
'permission_callback' => '__return_true',
]
);
}
/**
* Register Disable route in the WP REST API
*
* @since 3.5
*
* @return void
*/
public function register_disable_route() {
register_rest_route(
self::ROUTE_NAMESPACE,
'rocketcdn/disable',
[
'methods' => 'PUT',
'callback' => [ $this, 'disable' ],
'args' => [
'email' => [
'required' => true,
'validate_callback' => [ $this, 'validate_email' ],
],
'key' => [
'required' => true,
'validate_callback' => [ $this, 'validate_key' ],
],
],
'permission_callback' => '__return_true',
]
);
}
/**
* Enable CDN and add RocketCDN URL to WP Rocket options
*
* @since 3.5
*
* @param \WP_REST_Request $request the WP REST Request object.
*
* @return \WP_REST_Response|\WP_Error
*/
public function enable( \WP_REST_Request $request ) {
$params = $request->get_body_params();
$this->cdn_options->enable( $params['url'] );
$response = [
'code' => 'success',
'message' => __( 'RocketCDN enabled', 'rocket' ),
'data' => [
'status' => 200,
],
];
return rest_ensure_response( $response );
}
/**
* Disable the CDN and remove the RocketCDN URL from WP Rocket options
*
* @since 3.5
*
* @param \WP_REST_Request $request the WP Rest Request object.
*
* @return \WP_REST_Response|\WP_Error
*/
public function disable( \WP_REST_Request $request ) {
$this->cdn_options->disable();
$response = [
'code' => 'success',
'message' => __( 'RocketCDN disabled', 'rocket' ),
'data' => [
'status' => 200,
],
];
return rest_ensure_response( $response );
}
/**
* Checks that the email sent along the request corresponds to the one saved in the DB
*
* @since 3.5
*
* @param string $param Parameter value to validate.
*
* @return bool
*/
public function validate_email( $param ) {
return $param === $this->options->get( 'consumer_email' );
}
/**
* Checks that the key sent along the request corresponds to the one saved in the DB
*
* @since 3.5
*
* @param string $param Parameter value to validate.
*
* @return bool
*/
public function validate_key( $param ) {
return $param === $this->options->get( 'consumer_key' );
}
}