add wp-rocket
This commit is contained in:
79
wp-content/plugins/wp-rocket/inc/Engine/Support/Data.php
Normal file
79
wp-content/plugins/wp-rocket/inc/Engine/Support/Data.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\Engine\Support;
|
||||
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
|
||||
class Data {
|
||||
/**
|
||||
* Options instance
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Array of WP Rocket options to send
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $to_send = [
|
||||
'cache_mobile' => 'Mobile Cache',
|
||||
'do_caching_mobile_files' => 'Specific Cache for Mobile',
|
||||
'cache_logged_user' => 'User Cache',
|
||||
'emoji' => 'Disable Emojis',
|
||||
'embeds' => 'Disable Embeds',
|
||||
'defer_all_js' => 'Defer JS',
|
||||
'defer_all_js_safe' => 'Defer JS Safe',
|
||||
'delay_js' => 'Delay JS',
|
||||
'async_css' => 'Optimize CSS Delivery',
|
||||
'lazyload' => 'Lazyload Images',
|
||||
'lazyload_iframes' => 'Lazyload Iframes',
|
||||
'lazyload_youtube' => 'Lazyload Youtube',
|
||||
'cache_webp' => 'WebP Cache',
|
||||
'minify_css' => 'Minify CSS',
|
||||
'minify_concatenate_css' => 'Combine CSS',
|
||||
'minify_js' => 'Minify JS',
|
||||
'minify_concatenate_js' => 'Combine JS',
|
||||
'minify_google_fonts' => 'Combine Google Fonts',
|
||||
'manual_preload' => 'Preload',
|
||||
'sitemap_preload' => 'Sitemap Preload',
|
||||
'preload_links' => 'Preload Links',
|
||||
'cdn' => 'CDN Enabled',
|
||||
'do_cloudflare' => 'Cloudflare Enabled',
|
||||
'varnish_auto_purge' => 'Varnish Purge Enabled',
|
||||
'google_analytics_cache' => 'Google Tracking Add-on',
|
||||
'facebook_pixel_cache' => 'Facebook Tracking Add-on',
|
||||
'control_heartbeat' => 'Hearbeat Control',
|
||||
'sucury_waf_cache_sync' => 'Sucuri Add-on',
|
||||
];
|
||||
|
||||
/**
|
||||
* Instantiate the class
|
||||
*
|
||||
* @param Options_Data $options Options instance.
|
||||
*/
|
||||
public function __construct( Options_Data $options ) {
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data to populate the support information
|
||||
*
|
||||
* @since 3.7.5
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_support_data() {
|
||||
$active_options = array_intersect_key( $this->to_send, array_filter( $this->options->get_options() ) );
|
||||
|
||||
return [
|
||||
'Website' => home_url(),
|
||||
'WordPress Version' => get_bloginfo( 'version' ),
|
||||
'WP Rocket Version' => rocket_get_constant( 'WP_ROCKET_VERSION' ),
|
||||
'Theme' => wp_get_theme()->get( 'Name' ),
|
||||
'Plugins Enabled' => implode( ' - ', rocket_get_active_plugins() ),
|
||||
'WP Rocket Active Options' => implode( ' - ', $active_options ),
|
||||
];
|
||||
}
|
||||
}
|
121
wp-content/plugins/wp-rocket/inc/Engine/Support/Rest.php
Normal file
121
wp-content/plugins/wp-rocket/inc/Engine/Support/Rest.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\Engine\Support;
|
||||
|
||||
use WP_Rocket\Admin\Options_Data;
|
||||
|
||||
class Rest {
|
||||
const ROUTE_NAMESPACE = 'wp-rocket/v1';
|
||||
|
||||
/**
|
||||
* Data instance
|
||||
*
|
||||
* @var Data
|
||||
*/
|
||||
private $data;
|
||||
|
||||
/**
|
||||
* Options instance
|
||||
*
|
||||
* @var Options_Data
|
||||
*/
|
||||
private $options;
|
||||
|
||||
/**
|
||||
* Instantiate the class
|
||||
*
|
||||
* @param Data $data Data instance.
|
||||
* @param Options_Data $options Options instance.
|
||||
*/
|
||||
public function __construct( Data $data, Options_Data $options ) {
|
||||
$this->data = $data;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the REST route to get the support data
|
||||
*
|
||||
* @since 3.7.5
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_route() {
|
||||
register_rest_route(
|
||||
self::ROUTE_NAMESPACE,
|
||||
'support',
|
||||
[
|
||||
'methods' => 'POST',
|
||||
'callback' => [ $this, 'get_support_data' ],
|
||||
'args' => [
|
||||
'email' => [
|
||||
'required' => true,
|
||||
'validate_callback' => [ $this, 'validate_email' ],
|
||||
],
|
||||
'key' => [
|
||||
'required' => true,
|
||||
'validate_callback' => [ $this, 'validate_key' ],
|
||||
],
|
||||
],
|
||||
'permission_callback' => '__return_true',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the support data if the referer is correct
|
||||
*
|
||||
* @since 3.7.5
|
||||
*
|
||||
* @return WP_REST_Response
|
||||
*/
|
||||
public function get_support_data() {
|
||||
if ( false === strpos( wp_get_raw_referer(), 'wp-rocket.me' ) ) {
|
||||
return rest_ensure_response(
|
||||
[
|
||||
'code' => 'rest_invalid_referer',
|
||||
'message' => 'Invalid referer',
|
||||
'data' => [
|
||||
'status' => 400,
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return rest_ensure_response(
|
||||
[
|
||||
'code' => 'rest_support_data_success',
|
||||
'message' => 'Support data request successful',
|
||||
'data' => [
|
||||
'status' => 200,
|
||||
'content' => $this->data->get_support_data(),
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the email sent along the request corresponds to the one saved in the DB
|
||||
*
|
||||
* @since 3.7.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.7.5
|
||||
*
|
||||
* @param string $param Parameter value to validate.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validate_key( $param ) {
|
||||
return $param === $this->options->get( 'consumer_key', '' );
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\Engine\Support;
|
||||
|
||||
use WP_Rocket\Engine\Container\ServiceProvider\AbstractServiceProvider;
|
||||
use WP_Rocket\Engine\Support\Data;
|
||||
use WP_Rocket\Engine\Support\Rest;
|
||||
use WP_Rocket\Engine\Support\Subscriber;
|
||||
|
||||
class ServiceProvider extends AbstractServiceProvider {
|
||||
/**
|
||||
* The provides array is a way to let the container
|
||||
* know that a service is provided by this service
|
||||
* provider. Every service that is registered via
|
||||
* this service provider must have an alias added
|
||||
* to this array or it will be ignored.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $provides = [
|
||||
'support_data',
|
||||
'rest_support',
|
||||
'support_subscriber',
|
||||
];
|
||||
|
||||
/**
|
||||
* Registers the services in the container
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register() {
|
||||
$options = $this->getContainer()->get( 'options' );
|
||||
|
||||
$this->getContainer()->add( 'support_data', Data::class )
|
||||
->withArgument( $options );
|
||||
$this->getContainer()->add( 'rest_support', Rest::class )
|
||||
->withArgument( $this->getContainer()->get( 'support_data' ) )
|
||||
->withArgument( $options );
|
||||
$this->getContainer()->share( 'support_subscriber', Subscriber::class )
|
||||
->withArgument( $this->getContainer()->get( 'rest_support' ) );
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Rocket\Engine\Support;
|
||||
|
||||
use WP_Rocket\Event_Management\Subscriber_Interface;
|
||||
|
||||
class Subscriber implements Subscriber_Interface {
|
||||
/**
|
||||
* Rest instance
|
||||
*
|
||||
* @var Rest
|
||||
*/
|
||||
private $rest;
|
||||
|
||||
/**
|
||||
* Instantiate the class
|
||||
*
|
||||
* @param Rest $rest Rest instance.
|
||||
*/
|
||||
public function __construct( Rest $rest ) {
|
||||
$this->rest = $rest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Events this subscriber listens to.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_subscribed_events() {
|
||||
return [
|
||||
'rest_api_init' => 'register_support_route',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the rest support route
|
||||
*
|
||||
* @since 3.7.5
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register_support_route() {
|
||||
$this->rest->register_route();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user