add wp-rocket

This commit is contained in:
nguyen dung
2022-02-18 19:09:35 +07:00
parent 39b8cb3612
commit 3110d00ee7
927 changed files with 271703 additions and 2 deletions

View File

@@ -0,0 +1,630 @@
<?php
namespace WP_Rocket\Engine\Admin\Beacon;
use WP_Rocket\Abstract_Render;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Engine\Support\Data;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* Helpscout Beacon integration
*
* @since 3.2
*/
class Beacon extends Abstract_Render implements Subscriber_Interface {
/**
* Options_Data instance
*
* @since 3.2
*
* @var Options_Data $options
*/
private $options;
/**
* Current user locale
*
* @since 3.2
*
* @var string $locale
*/
private $locale;
/**
* Support data instance
*
* @var Data
*/
private $support_data;
/**
* Constructor
*
* @since 3.2
*
* @param Options_Data $options Options instance.
* @param string $template_path Absolute path to the views/settings.
* @param Data $support_data Support data instance.
*/
public function __construct( Options_Data $options, $template_path, Data $support_data ) {
parent::__construct( $template_path );
$this->options = $options;
$this->support_data = $support_data;
}
/**
* Return an array of events that this subscriber wants to listen to.
*
* @since 3.2
*
* @return array
*/
public static function get_subscribed_events() {
return [
'admin_print_footer_scripts-settings_page_wprocket' => 'insert_script',
];
}
/**
* Configures and returns beacon javascript
*
* @since 3.2
*
* @return void
*/
public function insert_script() {
if ( ! current_user_can( 'rocket_manage_options' ) ) {
return;
}
switch ( $this->get_user_locale() ) {
case 'fr':
$form_id = '9db9417a-5e2f-41dd-8857-1421d5112aea';
break;
default:
$form_id = '44cc73fb-7636-4206-b115-c7b33823551b';
break;
}
$data = [
'form_id' => $form_id,
'identify' => wp_json_encode( $this->identify_data() ),
'session' => wp_json_encode( $this->support_data->get_support_data() ),
'prefill' => wp_json_encode( $this->prefill_data() ),
];
echo $this->generate( 'beacon', $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Sets the locale property with the current user locale if not set yet
*
* @since 3.5
*
* @return string
*/
private function get_user_locale() {
if ( ! isset( $this->locale ) ) {
$this->locale = current( array_slice( explode( '_', get_user_locale() ), 0, 1 ) );
}
/**
* Filters the locale ID for Beacon
*
* @since 3.6
*
* @param string $locale The locale ID.
*/
return apply_filters( 'rocket_beacon_locale', $this->locale );
}
/**
* Returns Identify data to pass to Beacon
*
* @since 3.0
*
* @return array
*/
private function identify_data() {
$identify_data = [
'email' => $this->options->get( 'consumer_email' ),
'Website' => home_url(),
];
$customer_data = get_transient( 'wp_rocket_customer_data' );
if ( false !== $customer_data && isset( $customer_data->status ) ) {
$identify_data['status'] = $customer_data->status;
}
return $identify_data;
}
/**
* Returns prefill data to pass to Beacon
*
* @since 3.6
*
* @return array
*/
private function prefill_data() {
$prefill_data = [
'fields' => [
[
'id' => 21728,
'value' => 108003, // default to nulled.
],
],
];
$customer_data = get_transient( 'wp_rocket_customer_data' );
if ( false === $customer_data || ! isset( $customer_data->licence_account ) ) {
return $prefill_data;
}
$licenses = [
'Single' => 108000,
'Plus' => 108001,
'Infinite' => 108002,
'Unavailable' => 108003,
];
if ( isset( $licenses[ $customer_data->licence_account ] ) ) {
$prefill_data['fields'][0]['value'] = $licenses[ $customer_data->licence_account ];
}
return $prefill_data;
}
/**
* Returns the IDs for the HelpScout docs for the corresponding section and language.
*
* @since 3.0
*
* @param string $doc_id Section identifier.
*
* @return string|array
*/
public function get_suggest( $doc_id ) {
$suggest = [
'faq' => [
'en' => [
[
'id' => '5569b671e4b027e1978e3c51',
'url' => 'https://docs.wp-rocket.me/article/99-pages-are-not-cached-or-css-and-js-minification-are-not-working/?utm_source=wp_plugin&utm_medium=wp_rocket',
'title' => 'Pages Are Not Cached or CSS and JS Minification Are Not Working',
],
[
'id' => '556778c8e4b01a224b426fad',
'url' => 'https://docs.wp-rocket.me/article/85-google-page-speed-grade-does-not-improve/?utm_source=wp_plugin&utm_medium=wp_rocket',
'title' => 'Google PageSpeed Grade does not Improve',
],
[
'id' => '556ef48ce4b01a224b428691',
'url' => 'https://docs.wp-rocket.me/article/106-my-site-is-broken/?utm_source=wp_plugin&utm_medium=wp_rocket',
'title' => 'My Site Is Broken',
],
[
'id' => '54205957e4b099def9b55df0',
'url' => 'https://docs.wp-rocket.me/article/19-resolving-issues-with-file-optimization/?utm_source=wp_plugin&utm_medium=wp_rocket',
'title' => 'Resolving Issues with File Optimization',
],
],
'fr' => [
[
'id' => '5697d2dc9033603f7da31041',
'url' => 'https://fr.docs.wp-rocket.me/article/264-les-pages-ne-sont-pas-mises-en-cache-ou-la-minification-css-et-js-ne-fonctionne-pas/?utm_source=wp_plugin&utm_medium=wp_rocket',
'title' => 'Les pages ne sont pas mises en cache, ou la minification CSS et JS ne fonctionne pas',
],
[
'id' => '569564dfc69791436155e0b0',
'url' => 'https://fr.docs.wp-rocket.me/article/218-la-note-google-page-speed-ne-sameliore-pas/?utm_source=wp_plugin&utm_medium=wp_rocket',
'title' => "La note Google Page Speed ne s'améliore pas",
],
[
'id' => '5697d03bc69791436155ed69',
'url' => 'https://fr.docs.wp-rocket.me/article/263-site-casse/?utm_source=wp_plugin&utm_medium=wp_rocket',
'title' => 'Mon site est cassé',
],
[
'id' => '56967d73c69791436155e637',
'url' => 'https://fr.docs.wp-rocket.me/article/241-problemes-minification/?utm_source=wp_plugin&utm_medium=wp_rocket',
'title' => "Résoudre les problèmes avec l'optimisation des fichiers",
],
],
],
'user_cache_section' => [
'en' => '56b55ba49033600da1c0b687,587920b5c697915403a0e1f4,560c66b0c697917e72165a6d',
'fr' => '56cb9ba990336008e9e9e3d9,5879230cc697915403a0e211,569410999033603f7da2fa94',
],
'user_cache' => [
'en' => [
'id' => '56b55ba49033600da1c0b687',
'url' => 'https://docs.wp-rocket.me/article/313-user-cache/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '56cb9ba990336008e9e9e3d9',
'url' => 'https://fr.docs.wp-rocket.me/article/333-cache-utilisateurs-connectes/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'mobile_cache_section' => [
'en' => '577a5f1f903360258a10e52a,5678aa76c697914361558e92,5745b9a6c697917290ddc715',
'fr' => '589b17a02c7d3a784630b249,5a6b32830428632faf6233dc,58a480e5dd8c8e56bfa7b85c',
],
'mobile_cache' => [
'en' => [
'id' => '577a5f1f903360258a10e52a',
'url' => 'https://docs.wp-rocket.me/article/708-mobile-caching/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '589b17a02c7d3a784630b249',
'url' => 'https://fr.docs.wp-rocket.me/article/934-mise-en-cache-pour-mobile/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'cache_ssl' => [
'en' => [
'id' => '56c24fd3903360436857f1ed',
'url' => 'https://docs.wp-rocket.me/article/314-using-ssl-with-wp-rocket/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '56cb9d24c6979102ccfc801c',
'url' => 'https://fr.docs.wp-rocket.me/article/335-utiliser-ssl-wp-rocket/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'cache_lifespan' => [
'en' => [
'id' => '555c7e9ee4b027e1978e17a5',
'url' => 'https://docs.wp-rocket.me/article/78-how-often-is-the-cache-updated/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '568f7df49033603f7da2ec72',
'url' => 'https://fr.docs.wp-rocket.me/article/171-intervalle-cache/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'cache_lifespan_section' => [
'en' => '555c7e9ee4b027e1978e17a5,5922fd0e0428634b4a33552c',
'fr' => '568f7df49033603f7da2ec72,598080e1042863033a1b890e',
],
'nonce' => [
'en' => [
'id' => '5922fd0e0428634b4a33552c',
'url' => 'https://docs.wp-rocket.me/article/975-nonces-and-cache-lifespan/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '598080e1042863033a1b890e',
'url' => 'https://fr.docs.wp-rocket.me/article/1015-nonces-delai-nettoyage-cache/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'basic_section' => [
'en' => '55231415e4b0221aadf25676,588286b32c7d3a4a60b95b6c,58869c492c7d3a7846303a3d',
'fr' => '569568269033603f7da30334,58e3be72dd8c8e5c57311c6e,59b7f049042863033a1cc5d0',
],
'css_section' => [
'en' => '54205957e4b099def9b55df0,5419ec47e4b099def9b5565f,5578cfbbe4b027e1978e6bb1,5569b671e4b027e1978e3c51,5923772c2c7d3a074e8ab8b9',
'fr' => '56967d73c69791436155e637,56967e80c69791436155e646,56957209c69791436155e0f6,5697d2dc9033603f7da31041593fec6d2c7d3a0747cddb93',
],
'js_section' => [
'en' => '54205957e4b099def9b55df0,5419ec47e4b099def9b5565f,5578cfbbe4b027e1978e6bb1,587904cf90336009736c678e,54b9509de4b07997ea3f27c7,59236dfb0428634b4a3358f9',
'fr' => '56967d73c69791436155e637,56967e80c69791436155e646,56957209c69791436155e0f6,58a337c12c7d3a576d352cde,56967eebc69791436155e649,593fe9882c7d3a0747cddb77',
],
'file_optimization' => [
'en' => [
'id' => '54205957e4b099def9b55df0',
'url' => 'https://docs.wp-rocket.me/article/19-resolving-issues-with-file-optimization/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '56967d73c69791436155e637',
'url' => 'https://fr.docs.wp-rocket.me/article/241-problemes-minification/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'combine' => [
'en' => [
'id' => '596eaf7d2c7d3a73488b3661',
'url' => 'https://docs.wp-rocket.me/article/1009-configuration-for-http-2/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '59a418ad042863033a1c572e',
'url' => 'https://fr.docs.wp-rocket.me/article/1018-configuration-http-2/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'exclude_inline_js' => [
'en' => [
'id' => '5b4879100428630abc0c0713',
'url' => 'https://docs.wp-rocket.me/article/1104-excluding-inline-js-from-combine/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'exclude_js' => [
'en' => [
'id' => '54b9509de4b07997ea3f27c7',
'url' => 'https://docs.wp-rocket.me/article/39-excluding-external-js-from-concatenation/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'defer_js' => [
'en' => [
'id' => '5d52138d2c7d3a68825e8faa',
'url' => 'https://docs.wp-rocket.me/article/1265-load-javascript-deferred/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '5d5ac08b2c7d3a7920be3649',
'url' => 'https://fr.docs.wp-rocket.me/article/1270-chargement-differe-des-fichiers-js/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'jquery_migrate' => [
'en' => [
'id' => '5e1d27de2c7d3a7e9ae627e8',
'url' => 'https://docs.wp-rocket.me/article/1304-remove-jquery-migrate/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '5e5e5bfe04286364bc962504',
'url' => 'https://fr.docs.wp-rocket.me/article/1309-supprimer-jquery-migrate/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'delay_js' => [
'en' => [
'id' => '5f359695042863444aa04e26',
'url' => 'https://docs.wp-rocket.me/article/1349-delay-javascript-execution/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'async' => [
'en' => [
'id' => '5d52144c0428631e94f94ae2',
'url' => 'https://docs.wp-rocket.me/article/1266-optimize-css-delivery/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '5d5abada0428634552d85bff',
'url' => 'https://fr.docs.wp-rocket.me/article/1268-optimiser-le-chargement-du-css/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'lazyload' => [
'en' => [
'id' => '5c884cf80428633d2cf38314',
'url' => 'https://docs.wp-rocket.me/article/1141-using-lazyload-in-wp-rocket/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '5c98ff532c7d3a1544614cf4',
'url' => 'https://fr.docs.wp-rocket.me/article/1146-utiliser-lazyload-images-wp-rocket/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'webp' => [
'en' => [
'id' => '5d72919704286364bc8ed49d',
'url' => 'https://docs.wp-rocket.me/article/1282-webp',
],
],
'lazyload_section' => [
'en' => '5c884cf80428633d2cf38314,54b85754e4b0512429883a86,5418c792e4b0e7b8127bed99,569ec4a69033603f7da32c93,5419e246e4b099def9b5561e,5a299b332c7d3a1a640cb402',
'fr' => '56967a859033603f7da30858,56967952c69791436155e60a,56cb9c9d90336008e9e9e3dc,569676ea9033603f7da3083d,5a3a66f52c7d3a1943676524',
],
'sitemap_preload' => [
'en' => '541780fde4b005ed2d11784c,5a71c8ab2c7d3a4a4198a9b3,55b282ede4b0b0593824f852',
'fr' => '5693d582c69791436155d645',
],
'preload_bot' => [
'en' => '541780fde4b005ed2d11784c,55b282ede4b0b0593824f852,559113eae4b027e1978eba11',
'fr' => '5693d582c69791436155d645,569433d1c69791436155d99c',
],
'bot' => [
'en' => [
'id' => '541780fde4b005ed2d11784c',
'url' => 'https://docs.wp-rocket.me/article/8-how-the-cache-is-preloaded/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '5693d582c69791436155d645',
'url' => 'https://fr.docs.wp-rocket.me/article/188-comment-est-pre-charge-le-cache/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'dns_prefetch' => [
'en' => '541780fde4b005ed2d11784c',
'fr' => '5693d582c69791436155d645',
],
'fonts_preload' => [
'en' => [
'id' => '5eab7729042863474d19f647',
'url' => 'https://docs.wp-rocket.me/article/1317-preload-fonts/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '5eb3add02c7d3a5ea54aa66d',
'url' => 'https://fr.docs.wp-rocket.me/article/1319-precharger-polices/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'preload_links' => [
'en' => [
'id' => '5f35939b042863444aa04df9',
'url' => 'https://docs.wp-rocket.me/article/1348-preload-links/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'never_cache' => [
'en' => '5519ab03e4b061031402119f,559110d0e4b027e1978eba09,56b55ba49033600da1c0b687,553ac7bfe4b0eb143c62af44,587920b5c697915403a0e1f4,5569b671e4b027e1978e3c51',
'fr' => '56941c0cc69791436155d8ab,56943395c69791436155d99a,56cb9ba990336008e9e9e3d9,56942fc3c69791436155d987,5879230cc697915403a0e211,5697d2dc9033603f7da31041',
],
'always_purge_section' => [
'en' => '555c7e9ee4b027e1978e17a,55151406e4b0610314020a3f,5632858890336002f86d903e,5792c0c1903360293603896b',
'fr' => '568f7df49033603f7da2ec72,5694194d9033603f7da2fb00,56951208c69791436155de2a,57a4a0c3c697910783242008',
],
'query_strings' => [
'en' => '590a83610428634b4a32d52c',
'fr' => '597a04fd042863033a1b6da4',
],
'ecommerce' => [
'en' => [
'id' => '555c619ce4b027e1978e1767',
'url' => 'https://docs.wp-rocket.me/article/75-is-wp-rocket-compatible-with-e-commerce-plugins/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '568f8291c69791436155caea',
'url' => 'https://fr.docs.wp-rocket.me/article/176-compatibilite-extensions-e-commerce/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'cache_query_strings' => [
'en' => [
'id' => '590a83610428634b4a32d52c',
'url' => 'https://docs.wp-rocket.me/article/971-caching-query-strings/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '597a04fd042863033a1b6da4',
'url' => 'https://fr.docs.wp-rocket.me/article/1014-cache-query-strings/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'exclude_cache' => [
'en' => [
'id' => '5519ab03e4b061031402119f',
'url' => 'https://docs.wp-rocket.me/article/54-exclude-pages-from-the-cache/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '56941c0cc69791436155d8ab',
'url' => 'https://fr.docs.wp-rocket.me/article/196-exclure-pages-cache/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'always_purge' => [
'en' => [
'id' => '555c7e9ee4b027e1978e17a5',
'url' => 'https://docs.wp-rocket.me/article/78-how-often-is-the-cache-updated/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '568f7df49033603f7da2ec72',
'url' => 'https://fr.docs.wp-rocket.me/article/171-intervalle-cache/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'cleanup' => [
'en' => '55dcaa28e4b01d7a6a9bd373,578cd762c6979160ca1441cd,5569d11ae4b01a224b427725',
'fr' => '5697cebbc69791436155ed5e,58b6e7a0dd8c8e56bfa819f5,5697cd85c69791436155ed50',
],
'slow_admin' => [
'en' => [
'id' => '55dcaa28e4b01d7a6a9bd373',
'url' => 'https://docs.wp-rocket.me/article/121-wp-admin-area-is-slow/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '5697cebbc69791436155ed5e',
'url' => 'https://fr.docs.wp-rocket.me/article/260-la-zone-d-administration-wp-est-lente/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'cdn_section' => [
'en' => '54c7fa3de4b0512429885b5c,54205619e4b0e7b8127bf849,54a6d578e4b047ebb774a687,56b2b4459033603f7da37acf,566f749f9033603f7da28459,5434667fe4b0310ce5ee867a',
'fr' => '5696830b9033603f7da308ac,5696837e9033603f7da308ae,569685749033603f7da308c0,57a4961190336059d4edc9d8,5697d5f8c69791436155ed8e,569684d29033603f7da308b9',
],
'cdn' => [
'en' => [
'id' => '54c7fa3de4b0512429885b5c',
'url' => 'https://docs.wp-rocket.me/article/42-using-wp-rocket-with-a-cdn/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '5696830b9033603f7da308ac',
'url' => 'https://fr.docs.wp-rocket.me/article/246-utiliser-wp-rocket-avec-un-cdn/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'rocketcdn' => [
'en' => [
'id' => '5e4c84bd04286364bc958833',
'url' => 'https://docs.wp-rocket.me/article/1307-rocketcdn/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '5e5e36712c7d3a7e9ae89555',
'url' => 'https://fr.docs.wp-rocket.me/article/1308-rocketcdn/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'exclude_cdn' => [
'en' => [
'id' => '5434667fe4b0310ce5ee867a',
'url' => 'https://docs.wp-rocket.me/article/24-resolving-issues-with-cdn-and-fonts-icons/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '569684d29033603f7da308b9',
'url' => 'https://fr.docs.wp-rocket.me/article/248-resoudre-des-problemes-avec-cdn-et-les-polices-icones/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'cloudflare_credentials' => [
'en' => [
'id' => '54205619e4b0e7b8127bf849',
'url' => 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '5696837e9033603f7da308ae',
'url' => 'https://fr.docs.wp-rocket.me/article/247-utiliser-wp-rocket-avec-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'cloudflare_settings' => [
'en' => [
'id' => '54205619e4b0e7b8127bf849',
'url' => 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '5696837e9033603f7da308ae',
'url' => 'https://fr.docs.wp-rocket.me/article/247-utiliser-wp-rocket-avec-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'cloudflare_credentials_api' => [
'en' => [
'id' => '54205619e4b0e7b8127bf849',
'url' => 'https://docs.wp-rocket.me/article/18-using-wp-rocket-with-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on',
],
'fr' => [
'id' => '5696837e9033603f7da308ae',
'url' => 'https://fr.docs.wp-rocket.me/article/247-utiliser-wp-rocket-avec-cloudflare/?utm_source=wp_plugin&utm_medium=wp_rocket#add-on',
],
],
'sucuri_credentials' => [
'en' => [
'id' => '5bce07be2c7d3a04dd5bf94d',
'url' => 'https://docs.wp-rocket.me/article/1120-sucuri-add-on/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '5bcf39c72c7d3a4db66085b9',
'url' => 'https://fr.docs.wp-rocket.me/article/1122-sucuri-add-on/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'varnish' => [
'en' => [
'id' => '56f48132c6979115a34095bd',
'url' => 'https://docs.wp-rocket.me/article/493-using-varnish-with-wp-rocket/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '56fd2f789033601d6683e574',
'url' => 'https://fr.docs.wp-rocket.me/article/512-varnish-wp-rocket-2-7/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'heartbeat_settings' => [
'en' => [
'id' => '5bcdfecd042863158cc7b672',
'url' => 'https://docs.wp-rocket.me/article/1119-control-wordpress-heartbeat-api/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '5bcf4378042863215a46bc00',
'url' => 'https://fr.docs.wp-rocket.me/article/1124-controler-api-wordpress-heartbeat/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'google_tracking' => [
'en' => [
'id' => '5b4693220428630abc0bf97b',
'url' => 'https://docs.wp-rocket.me/article/1103-google-tracking-add-on/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'facebook_tracking' => [
'en' => [
'id' => '5bc904e7042863158cc79d57',
'url' => 'https://docs.wp-rocket.me/article/1117-facebook-pixel-add-on/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
'fr' => [
'id' => '5bcf3d35042863215a46bb7f',
'url' => 'https://fr.docs.wp-rocket.me/article/1123-add-on-facebook-pixel/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
'google_fonts' => [
'en' => [
'id' => '5e8687c22c7d3a7e9aea4c4a',
'url' => 'https://docs.wp-rocket.me/article/1312-optimize-google-fonts',
],
'fr' => [
'id' => '5e970f512c7d3a7e9aeaf9fb',
'url' => 'https://fr.docs.wp-rocket.me/article/1314-optimiser-les-google-fonts/?utm_source=wp_plugin&utm_medium=wp_rocket',
],
],
];
return isset( $suggest[ $doc_id ][ $this->get_user_locale() ] )
? $suggest[ $doc_id ][ $this->get_user_locale() ]
: $suggest[ $doc_id ]['en'];
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace WP_Rocket\Engine\Admin\Beacon;
use WP_Rocket\Engine\Container\ServiceProvider\AbstractServiceProvider;
/**
* Service Provider for Beacon
*
* @since 3.3
* @author Remy Perona
*/
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 = [
'beacon',
];
/**
* Registers the option array in the container
*
* @since 3.3
* @author Remy Perona
*
* @return void
*/
public function register() {
$this->getContainer()->add( 'beacon', 'WP_Rocket\Engine\Admin\Beacon\Beacon' )
->withArgument( $this->getContainer()->get( 'options' ) )
->withArgument( $this->getContainer()->get( 'template_path' ) . '/settings' )
->withArgument( $this->getContainer()->get( 'support_data' ) );
}
}

View File

@@ -0,0 +1,161 @@
<?php
namespace WP_Rocket\Engine\Admin\Deactivation;
use WP_Rocket\Admin\Options;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Event_Management\Subscriber_Interface;
use WP_Rocket\Interfaces\Render_Interface;
/**
* Deactivation intent form on plugins page
*
* @since 3.0
*/
class DeactivationIntent implements Subscriber_Interface {
/**
* Render Interface
*
* @since 3.0
*
* @var Render_Interface
*/
private $render;
/**
* Options instance.
*
* @var Options
*/
private $options_api;
/**
* Options_Data instance.
*
* @since 3.0
*
* @var Options_Data
*/
private $options;
/**
* Constructor
*
* @since 3.0
*
* @param Render_Interface $render Render interface.
* @param Options $options_api Options instance.
* @param Options_Data $options Options_Data instance.
*/
public function __construct( Render_Interface $render, Options $options_api, Options_Data $options ) {
$this->render = $render;
$this->options_api = $options_api;
$this->options = $options;
}
/**
* Return an array of events that this subscriber wants to listen to.
*
* @since 3.0
*
* @return array
*/
public static function get_subscribed_events() {
return [
'admin_print_footer_scripts-plugins.php' => 'insert_mixpanel_tracking',
'admin_footer' => 'insert_deactivation_intent_form',
'wp_ajax_rocket_safe_mode' => 'activate_safe_mode',
];
}
/**
* Inserts mixpanel tracking on plugins page to send deactivation data
*
* @since 3.0
*
* @return void
*/
public function insert_mixpanel_tracking() {
?>
<!-- start Mixpanel --><script type="text/javascript">(function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=([^&]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,
0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(h=0;h<k.length;h++)e(d,k[h]);a._i.push([b,c,f])};a.__SV=1.2;b=e.createElement("script");b.type="text/javascript";b.async=!0;b.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";c=e.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c)}})(document,window.mixpanel||[]);
mixpanel.init("a36067b00a263cce0299cfd960e26ecf", {
'ip':false,
property_blacklist: ['$initial_referrer', '$current_url', '$initial_referring_domain', '$referrer', '$referring_domain']
} );
mixpanel.track_links( '#mixpanel-send-deactivation', 'Deactivation Intent', function(ele) {
return {
'Reason': document.getElementById('wpr-reason').value,
'Details': document.getElementById('wpr-details').value,
}
} );
</script><!-- end Mixpanel -->
<?php
}
/**
* Inserts the deactivation intent form on plugins page
*
* @since 3.0
*
* @return void
*/
public function insert_deactivation_intent_form() {
$current_screen = get_current_screen();
if ( 'plugins' !== $current_screen->id && 'plugins-network' !== $current_screen->id ) {
return;
}
$this->render->render_form();
}
/**
* Activates WP Rocket safe mode by deactivating possibly layout breaking options
*
* @since 3.0
*
* @return void
*/
public function activate_safe_mode() {
check_ajax_referer( 'rocket-ajax', 'nonce' );
if ( ! current_user_can( 'rocket_manage_options' ) ) {
wp_send_json_error();
return;
}
/**
* Filters the array of options to reset when activating safe mode
*
* @since 3.7
*
* @param array $options Array of options to reset.
*/
$reset_options = apply_filters(
'rocket_safe_mode_reset_options',
[
'embeds' => 0,
'defer_all_js' => 0,
'async_css' => 0,
'lazyload' => 0,
'lazyload_iframes' => 0,
'lazyload_youtube' => 0,
'minify_css' => 0,
'minify_concatenate_css' => 0,
'minify_js' => 0,
'minify_concatenate_js' => 0,
'minify_google_fonts' => 0,
'cdn' => 0,
]
);
$this->options->set_values( $reset_options );
$this->options_api->set( 'settings', $this->options->get_options() );
wp_send_json_success();
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace WP_Rocket\Engine\Admin;
use WP_Rocket\Engine\Container\ServiceProvider\AbstractServiceProvider;
/**
* Service Provider for admin subscribers.
*
* @since 3.3
*/
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 = [
'deactivation_intent_render',
'deactivation_intent_subscriber',
'hummingbird_subscriber',
];
/**
* Registers the option array in the container.
*
* @since 3.3
*/
public function register() {
$options = $this->getContainer()->get( 'options' );
$this->getContainer()->add( 'deactivation_intent_render', 'WP_Rocket\Admin\Deactivation\Render' )
->withArgument( $this->getContainer()->get( 'template_path' ) . '/deactivation-intent' );
$this->getContainer()->share( 'deactivation_intent_subscriber', 'WP_Rocket\Engine\Admin\Deactivation\DeactivationIntent' )
->withArgument( $this->getContainer()->get( 'deactivation_intent_render' ) )
->withArgument( $this->getContainer()->get( 'options_api' ) )
->withArgument( $options );
$this->getContainer()->share( 'hummingbird_subscriber', 'WP_Rocket\ThirdParty\Plugins\Optimization\Hummingbird' )
->withArgument( $options );
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,476 @@
<?php
namespace WP_Rocket\Engine\Admin\Settings;
use WP_Rocket\Abstract_Render;
defined( 'ABSPATH' ) || exit;
/**
* Handle rendering of HTML content for the settings page.
*
* @since 3.5.5 Moves into the new architecture.
* @since 3.0
*/
class Render extends Abstract_render {
/**
* Settings array.
*
* @since 3.0
*
* @var array
*/
private $settings = [];
/**
* Hidden settings array.
*
* @since 3.0
*
* @var array
*/
private $hidden_settings;
/**
* Sets the settings value.
*
* @since 3.0
*
* @param array $settings Array of settings.
* @return void
*/
public function set_settings( $settings ) {
$this->settings = (array) $settings;
}
/**
* Sets the hidden settings value.
*
* @since 3.0
*
* @param array $hidden_settings Array of hidden settings.
*/
public function set_hidden_settings( $hidden_settings ) {
$this->hidden_settings = $hidden_settings;
}
/**
* Renders the page sections navigation.
*
* @since 3.0
*/
public function render_navigation() {
/**
* Filters WP Rocket settings page navigation items.
*
* @since 3.0
*
* @param array $navigation {
* Items to populate the navigation.
*
* @type string $id Page section identifier.
* @type string $title Menu item title.
* @type string $menu_description Menu item description.
* @type string $class Menu item classes
* }
*/
$navigation = (array) apply_filters( 'rocket_settings_menu_navigation', $this->settings );
$default = [
'id' => '',
'title' => '',
'menu_description' => '',
'class' => '',
];
$navigation = array_map(
function( array $item ) use ( $default ) {
$item = wp_parse_args( $item, $default );
if ( ! empty( $item['class'] ) ) {
$item['class'] = implode( ' ', array_map( 'sanitize_html_class', $item['class'] ) );
}
unset( $item['sections'] );
return $item;
},
$navigation
);
echo $this->generate( 'navigation', $navigation ); // phpcs:ignore WordPress.Security.EscapeOutput -- Dynamic content is properly escaped in the view.
}
/**
* Render the page sections.
*
* @since 3.0
*/
public function render_form_sections() {
if ( ! isset( $this->settings ) ) {
return;
}
foreach ( $this->settings as $id => $args ) {
$default = [
'title' => '',
'menu_description' => '',
'class' => '',
];
$args = wp_parse_args( $args, $default );
$id = str_replace( '_', '-', $id );
echo $this->generate( 'page-sections/' . $id, $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
}
/**
* Render the Imagify page section.
*
* @since 3.2
*/
public function render_imagify_section() {
echo $this->generate( 'page-sections/imagify' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Render the Tutorials page section.
*
* @since 3.4
*/
public function render_tutorials_section() {
echo $this->generate( 'page-sections/tutorials' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Render the tools page section.
*
* @since 3.0
*/
public function render_tools_section() {
echo $this->generate( 'page-sections/tools' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Renders the settings sections for a page section.
*
* @since 3.0
*
* @param string $page Page section identifier.
* @return void
*/
public function render_settings_sections( $page ) {
if ( ! isset( $this->settings[ $page ]['sections'] ) ) {
return;
}
foreach ( $this->settings[ $page ]['sections'] as $args ) {
$default = [
'type' => 'fields_container',
'title' => '',
'description' => '',
'class' => '',
'help' => '',
'helper' => '',
'page' => '',
];
$args = wp_parse_args( $args, $default );
if ( ! empty( $args['class'] ) ) {
$args['class'] = implode( ' ', array_map( 'sanitize_html_class', $args['class'] ) );
}
call_user_func_array( [ $this, $args['type'] ], [ $args ] );
}
}
/**
* Renders the settings fields for a setting section and page.
*
* @since 3.0
*
* @param string $page Page section identifier.
* @param string $section Settings section identifier.
* @return void
*/
public function render_settings_fields( $page, $section ) {
if ( ! isset( $this->settings[ $page ]['sections'][ $section ]['fields'] ) ) {
return;
}
foreach ( $this->settings[ $page ]['sections'][ $section ]['fields'] as $args ) {
$default = [
'type' => 'text',
'label' => '',
'description' => '',
'class' => '',
'container_class' => '',
'default' => '',
'helper' => '',
'placeholder' => '',
'parent' => '',
'section' => '',
'page' => '',
'sanitize_callback' => 'sanitize_text_field',
'input_attr' => '',
'warning' => [],
];
$args = wp_parse_args( $args, $default );
if ( ! empty( $args['input_attr'] ) ) {
$input_attr = '';
foreach ( $args['input_attr'] as $key => $value ) {
if ( 'disabled' === $key ) {
if ( 1 === $value ) {
$input_attr .= ' disabled';
}
continue;
}
$input_attr .= ' ' . sanitize_key( $key ) . '="' . esc_attr( $value ) . '"';
}
$args['input_attr'] = $input_attr;
}
if ( ! empty( $args['parent'] ) ) {
$args['parent'] = ' data-parent="' . esc_attr( $args['parent'] ) . '"';
}
if ( ! empty( $args['class'] ) ) {
$args['class'] = implode( ' ', array_map( 'sanitize_html_class', $args['class'] ) );
}
if ( ! empty( $args['container_class'] ) ) {
$args['container_class'] = implode( ' ', array_map( 'sanitize_html_class', $args['container_class'] ) );
}
call_user_func_array( [ $this, $args['type'] ], [ $args ] );
}
}
/**
* Renders hidden fields in the form.
*
* @since 3.0
*/
public function render_hidden_fields() {
foreach ( $this->hidden_settings as $setting ) {
call_user_func_array( [ $this, 'hidden' ], [ $setting ] );
}
}
/**
* Displays the fields container section template.
*
* @since 3.0
* @author Remy Perona
*
* @param array $args Array of arguments to populate the template.
*/
public function fields_container( $args ) {
echo $this->generate( 'sections/fields-container', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays the no container section template.
*
* @since 3.0
*
* @param array $args Array of arguments to populate the template.
*/
public function nocontainer( $args ) {
echo $this->generate( 'sections/nocontainer', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays the add-ons container section template.
*
* @since 3.0
*
* @param array $args Array of arguments to populate the template.
*/
public function addons_container( $args ) {
echo $this->generate( 'sections/addons-container', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays the text field template.
*
* @since 3.0
*
* @param array $args Array of arguments to populate the template.
*/
public function text( $args ) {
echo $this->generate( 'fields/text', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays the checkbox field template.
*
* @since 3.0
* @author Remy Perona
*
* @param array $args Array of arguments to populate the template.
* @return void
*/
public function checkbox( $args ) {
echo $this->generate( 'fields/checkbox', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays the textarea field template.
*
* @since 3.0
*
* @param array $args Array of arguments to populate the template.
*/
public function textarea( $args ) {
if ( is_array( $args['value'] ) ) {
$args['value'] = implode( "\n", $args['value'] );
}
$args['value'] = empty( $args['value'] ) ? '' : $args['value'];
echo $this->generate( 'fields/textarea', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays the sliding checkbox field template.
*
* @since 3.0
*
* @param array $args Array of arguments to populate the template.
*/
public function sliding_checkbox( $args ) {
echo $this->generate( 'fields/sliding-checkbox', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays the number input field template.
*
* @since 3.0
*
* @param array $args Array of arguments to populate the template.
*/
public function number( $args ) {
echo $this->generate( 'fields/number', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays the select field template.
*
* @since 3.0
*
* @param array $args Array of arguments to populate the template.
*/
public function select( $args ) {
echo $this->generate( 'fields/select', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays the clear cache lifespan block template.
*
* @since 3.0
*
* @param array $args Array of arguments to populate the template.
*/
public function cache_lifespan( $args ) {
echo $this->generate( 'fields/cache-lifespan', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays the hidden field template.
*
* @since 3.0
*
* @param array $args Array of arguments to populate the template.
*/
public function hidden( $args ) {
echo $this->generate( 'fields/hidden', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays the CDN CNAMES template.
*
* @since 3.0
*
* @param array $args Array of arguments to populate the template.
*/
public function cnames( $args ) {
echo $this->generate( 'fields/cnames', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays the RocketCDN template.
*
* @since 3.5
*
* @param array $args Array of arguments to populate the template.
*/
public function rocket_cdn( $args ) {
echo $this->generate( 'fields/rocket-cdn', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays the one-click add-on field template.
*
* @since 3.0
*
* @param array $args Array of arguments to populate the template.
*/
public function one_click_addon( $args ) {
echo $this->generate( 'fields/one-click-addon', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays the Rocket add-on field template.
*
* @since 3.0
*
* @param array $args Array of arguments to populate the template.
*/
public function rocket_addon( $args ) {
echo $this->generate( 'fields/rocket-addon', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays the import form template.
*
* @since 3.0
*/
public function render_import_form() {
$args = [];
/**
* Filter the maximum allowed upload size for import files.
*
* @since (WordPress) 2.3.0
*
* @see wp_max_upload_size()
*
* @param int $max_upload_size Allowed upload size. Default 1 MB.
*/
$args['bytes'] = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
$args['size'] = size_format( $args['bytes'] );
$args['upload_dir'] = wp_upload_dir();
$args['action'] = 'rocket_import_settings';
$args['submit_text'] = __( 'Upload file and import settings', 'rocket' );
echo $this->generate( 'fields/import-form', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
/**
* Displays a partial template.
*
* @since 3.0
*
* @param string $part Partial template name.
*/
public function render_part( $part ) {
echo $this->generate( 'partials/' . $part ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace WP_Rocket\Engine\Admin\Settings;
use WP_Rocket\Engine\Container\ServiceProvider\AbstractServiceProvider;
/**
* Service provider for the WP Rocket settings.
*
* @since 3.5.5 Moves into the new architecture.
* @since 3.3
*/
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 = [
'settings',
'settings_render',
'settings_page',
'settings_page_subscriber',
];
/**
* Registers the option array in the container.
*
* @since 3.3
*/
public function register() {
$this->getContainer()->add( 'settings', 'WP_Rocket\Engine\Admin\Settings\Settings' )
->withArgument( $this->getContainer()->get( 'options' ) );
$this->getContainer()->add( 'settings_render', 'WP_Rocket\Engine\Admin\Settings\Render' )
->withArgument( $this->getContainer()->get( 'template_path' ) . '/settings' );
$this->getContainer()->add( 'settings_page', 'WP_Rocket\Engine\Admin\Settings\Page' )
->withArgument( $this->getContainer()->get( 'settings_page_config' ) )
->withArgument( $this->getContainer()->get( 'settings' ) )
->withArgument( $this->getContainer()->get( 'settings_render' ) )
->withArgument( $this->getContainer()->get( 'beacon' ) )
->withArgument( $this->getContainer()->get( 'db_optimization' ) )
->withArgument( $this->getContainer()->get( 'user_client' ) );
$this->getContainer()->share( 'settings_page_subscriber', 'WP_Rocket\Engine\Admin\Settings\Subscriber' )
->withArgument( $this->getContainer()->get( 'settings_page' ) );
}
}

View File

@@ -0,0 +1,667 @@
<?php
namespace WP_Rocket\Engine\Admin\Settings;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Subscriber\Third_Party\Plugins\Security\Sucuri_Subscriber;
/**
* Settings class.
*
* @since 3.5.5 Moves into the new architecture.
*/
class Settings {
/**
* Options_Data instance.
*
* @since 3.0
*
* @var Options_Data
*/
private $options;
/**
* Array of settings to build the settings page.
*
* @since 3.0
*
* @var array
*/
private $settings;
/**
* Hidden settings on the settings page.
*
* @since 3.0
*
* @var array
*/
private $hidden_settings;
/**
* Font formats allowed to be preloaded.
*
* @since 3.6
* @see $this->sanitize_font()
*
* @var string|bool
*/
private $font_formats = [
'otf',
'ttf',
'svg',
'woff',
'woff2',
];
/**
* Array of valid hosts.
*
* @since 3.6
* @see $this->get_hosts()
*
* @var array
*/
private $hosts;
/**
* Constructor
*
* @since 3.0
*
* @param Options_Data $options Options_Data instance.
*/
public function __construct( Options_Data $options ) {
$this->options = $options;
}
/**
* Adds a page section to the settings.
*
* A page section is a top-level block containing settings sections.
*
* @since 3.0
*
* @param string $id Page section identifier.
* @param array $args {
* Data to build the section.
*
* @type string $title Section title.
* @type string $menu_description Description displayed in the navigation.
* }
* @return void
*/
public function add_page_section( $id, $args ) {
$args['id'] = $id;
$this->settings[ $id ] = $args;
}
/**
* Adds settings sections to the settings.
*
* A setting section is a block containing settings fields.
*
* @since 3.0
*
* @param array $settings_sections {
* Data to build the section.
*
* @type string $title Section title.
* @type string $type Type of section.
* @type string $page Page section identifier it belongs to.
* @type string $description Section description.
* @type string $help Helper IDs for beacon.
* }
* @return void
*/
public function add_settings_sections( $settings_sections ) {
foreach ( $settings_sections as $id => $args ) {
$args['id'] = $id;
$this->settings[ $args['page'] ]['sections'][ $id ] = $args;
}
}
/**
* Adds settings fields to the settings.
*
* @since 3.0
*
* @param array $settings_fields {
* Data to build the section.
*
* @type string $id Identifier.
* @type string $title Field title.
* }
* @return void
*/
public function add_settings_fields( $settings_fields ) {
foreach ( $settings_fields as $id => $args ) {
$args['id'] = $id;
$args['value'] = $this->options->get( $id, $args['default'] );
$page = $args['page'];
$section = $args['section'];
unset( $args['page'], $args['section'] );
$this->settings[ $page ]['sections'][ $section ]['fields'][ $id ] = $args;
}
}
/**
* Adds hidden settings fields to the settings.
*
* @since 3.0
*
* @param array $hidden_settings_fields {
* Data to build the section.
*
* @type string $id Identifier.
* }
* @return void
*/
public function add_hidden_settings_fields( $hidden_settings_fields ) {
foreach ( $hidden_settings_fields as $id ) {
$value = $this->options->get( $id );
$this->hidden_settings[] = [
'id' => $id,
'value' => $value,
];
}
}
/**
* Returns the plugin settings
*
* @since 3.0
*
* @return array
*/
public function get_settings() {
return $this->settings;
}
/**
* Returns the plugin hidden settings
*
* @since 3.0
*
* @return array
*/
public function get_hidden_settings() {
return $this->hidden_settings;
}
/**
* Sanitizes the submitted values.
*
* @since 3.0
*
* @param array $input Array of values submitted by the form.
* @return array
*/
public function sanitize_callback( $input ) {
global $wp_settings_errors;
$input['do_beta'] = ! empty( $input['do_beta'] ) ? 1 : 0;
$input['cache_logged_user'] = ! empty( $input['cache_logged_user'] ) ? 1 : 0;
$input['cache_ssl'] = ! empty( $input['cache_ssl'] ) ? 1 : 0;
$input['cache_mobile'] = ! empty( $input['cache_mobile'] ) ? 1 : 0;
$input['do_caching_mobile_files'] = ! empty( $input['do_caching_mobile_files'] ) ? 1 : 0;
$input['minify_google_fonts'] = ! empty( $input['minify_google_fonts'] ) ? 1 : 0;
// Option : Minification CSS & JS.
$input['minify_css'] = ! empty( $input['minify_css'] ) ? 1 : 0;
$input['minify_js'] = ! empty( $input['minify_js'] ) ? 1 : 0;
$input['minify_concatenate_css'] = ! empty( $input['minify_concatenate_css'] ) ? 1 : 0;
$input['minify_concatenate_js'] = ! empty( $input['minify_concatenate_js'] ) ? 1 : 0;
$input['defer_all_js'] = ! empty( $input['defer_all_js'] ) ? 1 : 0;
$input['defer_all_js_safe'] = ! empty( $input['defer_all_js_safe'] ) ? 1 : 0;
$input['delay_js'] = $this->sanitize_checkbox( $input, 'delay_js' );
$input['delay_js_scripts'] = ! empty( $input['delay_js_scripts'] ) ? rocket_sanitize_textarea_field( 'delay_js_scripts', $input['delay_js_scripts'] ) : [];
// If Defer JS is deactivated, set Safe Mode for Jquery to active.
if ( 0 === $input['defer_all_js'] ) {
$input['defer_all_js_safe'] = 1;
}
$input['embeds'] = ! empty( $input['embeds'] ) ? 1 : 0;
$input['emoji'] = ! empty( $input['emoji'] ) ? 1 : 0;
$input['lazyload'] = ! empty( $input['lazyload'] ) ? 1 : 0;
$input['lazyload_iframes'] = ! empty( $input['lazyload_iframes'] ) ? 1 : 0;
$input['lazyload_youtube'] = ! empty( $input['lazyload_youtube'] ) ? 1 : 0;
// If iframes lazyload is not checked, uncheck youtube thumbnail option too.
if ( 0 === $input['lazyload_iframes'] ) {
$input['lazyload_youtube'] = 0;
}
// Option : Purge interval.
$input['purge_cron_interval'] = isset( $input['purge_cron_interval'] ) ? (int) $input['purge_cron_interval'] : $this->options->get( 'purge_cron_interval' );
$allowed_cron_units = [
'MINUTE_IN_SECONDS' => 1,
'HOUR_IN_SECONDS' => 1,
'DAY_IN_SECONDS' => 1,
];
$input['purge_cron_unit'] = isset( $input['purge_cron_unit'], $allowed_cron_units[ $input['purge_cron_unit'] ] ) ? $input['purge_cron_unit'] : $this->options->get( 'purge_cron_unit' );
// Force a minimum 10 minutes value for the purge interval.
if ( $input['purge_cron_interval'] < 10 && 'MINUTE_IN_SECONDS' === $input['purge_cron_unit'] ) {
$input['purge_cron_interval'] = 10;
}
// Option : Prefetch DNS requests.
$input['dns_prefetch'] = $this->sanitize_dns_prefetch( $input );
// Option : Empty the cache of the following pages when updating a post.
if ( ! empty( $input['cache_purge_pages'] ) ) {
$input['cache_purge_pages'] = rocket_sanitize_textarea_field( 'cache_purge_pages', $input['cache_purge_pages'] );
} else {
$input['cache_purge_pages'] = [];
}
// Option : Never cache the following pages.
if ( ! empty( $input['cache_reject_uri'] ) ) {
$input['cache_reject_uri'] = rocket_sanitize_textarea_field( 'cache_reject_uri', $input['cache_reject_uri'] );
} else {
$input['cache_reject_uri'] = [];
}
// Option : Don't cache pages that use the following cookies.
if ( ! empty( $input['cache_reject_cookies'] ) ) {
$input['cache_reject_cookies'] = rocket_sanitize_textarea_field( 'cache_reject_cookies', $input['cache_reject_cookies'] );
} else {
$input['cache_reject_cookies'] = [];
}
// Option : Cache pages that use the following query strings (GET parameters).
if ( ! empty( $input['cache_query_strings'] ) ) {
$input['cache_query_strings'] = rocket_sanitize_textarea_field( 'cache_query_strings', $input['cache_query_strings'] );
} else {
$input['cache_query_strings'] = [];
}
// Option : Never send cache pages for these user agents.
if ( ! empty( $input['cache_reject_ua'] ) ) {
$input['cache_reject_ua'] = rocket_sanitize_textarea_field( 'cache_reject_ua', $input['cache_reject_ua'] );
} else {
$input['cache_reject_ua'] = [];
}
// Option : CSS files to exclude from the minification.
if ( ! empty( $input['exclude_css'] ) ) {
$input['exclude_css'] = rocket_sanitize_textarea_field( 'exclude_css', $input['exclude_css'] );
} else {
$input['exclude_css'] = [];
}
// Option : JS files to exclude from the minification.
if ( ! empty( $input['exclude_js'] ) ) {
$input['exclude_js'] = rocket_sanitize_textarea_field( 'exclude_js', $input['exclude_js'] );
} else {
$input['exclude_js'] = [];
}
// Option: inline JS patterns to exclude from combine JS.
if ( ! empty( $input['exclude_inline_js'] ) ) {
$input['exclude_inline_js'] = rocket_sanitize_textarea_field( 'exclude_inline_js', $input['exclude_inline_js'] );
} else {
$input['exclude_inline_js'] = [];
}
// Option: Async CSS.
$input['async_css'] = ! empty( $input['async_css'] ) ? 1 : 0;
// Option: Critical CSS.
$input['critical_css'] = ! empty( $input['critical_css'] ) ? wp_strip_all_tags( str_replace( [ '<style>', '</style>' ], '', $input['critical_css'] ), [ "\'", '\"' ] ) : '';
// Database options.
$input['database_revisions'] = ! empty( $input['database_revisions'] ) ? 1 : 0;
$input['database_auto_drafts'] = ! empty( $input['database_auto_drafts'] ) ? 1 : 0;
$input['database_trashed_posts'] = ! empty( $input['database_trashed_posts'] ) ? 1 : 0;
$input['database_spam_comments'] = ! empty( $input['database_spam_comments'] ) ? 1 : 0;
$input['database_trashed_comments'] = ! empty( $input['database_trashed_comments'] ) ? 1 : 0;
$input['database_expired_transients'] = ! empty( $input['database_expired_transients'] ) ? 1 : 0;
$input['database_all_transients'] = ! empty( $input['database_all_transients'] ) ? 1 : 0;
$input['database_optimize_tables'] = ! empty( $input['database_optimize_tables'] ) ? 1 : 0;
$input['schedule_automatic_cleanup'] = ! empty( $input['schedule_automatic_cleanup'] ) ? 1 : 0;
$cleanup_frequencies = [
'daily' => 1,
'weekly' => 1,
'monthly' => 1,
];
$input['automatic_cleanup_frequency'] = isset( $input['automatic_cleanup_frequency'], $cleanup_frequencies[ $input['automatic_cleanup_frequency'] ] ) ? $input['automatic_cleanup_frequency'] : $this->options->get( 'automatic_cleanup_frequency' );
if ( 1 !== $input['schedule_automatic_cleanup'] && ( 'daily' !== $input['automatic_cleanup_frequency'] || 'weekly' !== $input['automatic_cleanup_frequency'] || 'monthly' !== $input['automatic_cleanup_frequency'] ) ) {
$input['automatic_cleanup_frequency'] = $this->options->get( 'automatic_cleanup_frequency' );
}
// Options: Activate bot preload.
$input['manual_preload'] = ! empty( $input['manual_preload'] ) ? 1 : 0;
// Option: activate sitemap preload.
$input['sitemap_preload'] = ! empty( $input['sitemap_preload'] ) ? 1 : 0;
// Option : XML sitemaps URLs.
if ( ! empty( $input['sitemaps'] ) ) {
if ( ! is_array( $input['sitemaps'] ) ) {
$input['sitemaps'] = explode( "\n", $input['sitemaps'] );
}
$input['sitemaps'] = array_map( 'trim', $input['sitemaps'] );
$input['sitemaps'] = array_map( 'rocket_sanitize_xml', $input['sitemaps'] );
$input['sitemaps'] = array_filter( $input['sitemaps'] );
$input['sitemaps'] = array_unique( $input['sitemaps'] );
} else {
$input['sitemaps'] = [];
}
// Option : fonts to preload.
$input['preload_fonts'] = ! empty( $input['preload_fonts'] ) ? $this->sanitize_fonts( $input['preload_fonts'] ) : [];
// Options : CloudFlare.
$input['do_cloudflare'] = ! empty( $input['do_cloudflare'] ) ? 1 : 0;
$input['cloudflare_email'] = isset( $input['cloudflare_email'] ) ? sanitize_email( $input['cloudflare_email'] ) : '';
$input['cloudflare_api_key'] = isset( $input['cloudflare_api_key'] ) ? sanitize_text_field( $input['cloudflare_api_key'] ) : '';
$input['cloudflare_zone_id'] = isset( $input['cloudflare_zone_id'] ) ? sanitize_text_field( $input['cloudflare_zone_id'] ) : '';
$input['cloudflare_devmode'] = isset( $input['cloudflare_devmode'] ) && is_numeric( $input['cloudflare_devmode'] ) ? (int) $input['cloudflare_devmode'] : 0;
$input['cloudflare_auto_settings'] = ( isset( $input['cloudflare_auto_settings'] ) && is_numeric( $input['cloudflare_auto_settings'] ) ) ? (int) $input['cloudflare_auto_settings'] : 0;
$input['cloudflare_protocol_rewrite'] = ! empty( $input['cloudflare_protocol_rewrite'] ) ? 1 : 0;
if ( defined( 'WP_ROCKET_CF_API_KEY' ) ) {
$input['cloudflare_api_key'] = WP_ROCKET_CF_API_KEY;
}
// Options: Sucuri cache. And yeah, there's a typo, but now it's too late to fix ^^'.
$input['sucury_waf_cache_sync'] = ! empty( $input['sucury_waf_cache_sync'] ) ? 1 : 0;
if ( defined( 'WP_ROCKET_SUCURI_API_KEY' ) ) {
$input['sucury_waf_api_key'] = WP_ROCKET_SUCURI_API_KEY;
} else {
$input['sucury_waf_api_key'] = isset( $input['sucury_waf_api_key'] ) ? sanitize_text_field( $input['sucury_waf_api_key'] ) : '';
}
$input['sucury_waf_api_key'] = trim( $input['sucury_waf_api_key'] );
if ( ! Sucuri_Subscriber::is_api_key_valid( $input['sucury_waf_api_key'] ) ) {
$input['sucury_waf_api_key'] = '';
if ( $input['sucury_waf_cache_sync'] && empty( $input['ignore'] ) ) {
add_settings_error( 'general', 'sucuri_waf_api_key_invalid', __( 'Sucuri Add-on: The API key for the Sucuri firewall must be in format <code>{32 characters}/{32 characters}</code>.', 'rocket' ), 'error' );
}
}
// Options : Heartbeat.
$choices = [
'' => 1,
'reduce_periodicity' => 1,
'disable' => 1,
];
$input['control_heartbeat'] = ! empty( $input['control_heartbeat'] ) ? 1 : 0;
$input['heartbeat_site_behavior'] = isset( $input['heartbeat_site_behavior'], $choices[ $input['heartbeat_site_behavior'] ] ) ? $input['heartbeat_site_behavior'] : '';
$input['heartbeat_admin_behavior'] = isset( $input['heartbeat_admin_behavior'], $choices[ $input['heartbeat_admin_behavior'] ] ) ? $input['heartbeat_admin_behavior'] : '';
$input['heartbeat_editor_behavior'] = isset( $input['heartbeat_editor_behavior'], $choices[ $input['heartbeat_editor_behavior'] ] ) ? $input['heartbeat_editor_behavior'] : '';
// Option : CDN.
$input['cdn'] = ! empty( $input['cdn'] ) ? 1 : 0;
// Option : CDN Cnames.
if ( isset( $input['cdn_cnames'] ) ) {
$input['cdn_cnames'] = array_map( 'sanitize_text_field', $input['cdn_cnames'] );
$input['cdn_cnames'] = array_filter( $input['cdn_cnames'] );
} else {
$input['cdn_cnames'] = [];
}
if ( ! $input['cdn_cnames'] ) {
$input['cdn_zone'] = [];
} else {
$total_cdn_cnames = max( array_keys( $input['cdn_cnames'] ) );
for ( $i = 0; $i <= $total_cdn_cnames; $i++ ) {
if ( ! isset( $input['cdn_cnames'][ $i ] ) ) {
unset( $input['cdn_zone'][ $i ] );
} else {
$allowed_cdn_zones = [
'all' => 1,
'images' => 1,
'css_and_js' => 1,
'css' => 1,
'js' => 1,
];
$input['cdn_zone'][ $i ] = isset( $allowed_cdn_zones[ $input['cdn_zone'][ $i ] ] ) ? $input['cdn_zone'][ $i ] : 'all';
}
}
$input['cdn_cnames'] = array_values( $input['cdn_cnames'] );
$input['cdn_cnames'] = array_map( 'untrailingslashit', $input['cdn_cnames'] );
ksort( $input['cdn_zone'] );
$input['cdn_zone'] = array_values( $input['cdn_zone'] );
}
// Option : Files to exclude from the CDN process.
if ( ! empty( $input['cdn_reject_files'] ) ) {
$input['cdn_reject_files'] = rocket_sanitize_textarea_field( 'cdn_reject_files', $input['cdn_reject_files'] );
} else {
$input['cdn_reject_files'] = [];
}
$input['varnish_auto_purge'] = ! empty( $input['varnish_auto_purge'] ) ? 1 : 0;
if ( ! rocket_valid_key() ) {
$checked = rocket_check_key();
}
if ( isset( $checked ) && is_array( $checked ) ) {
$input['consumer_key'] = $checked['consumer_key'];
$input['consumer_email'] = $checked['consumer_email'];
$input['secret_key'] = $checked['secret_key'];
}
if ( ! empty( $input['secret_key'] ) && empty( $input['ignore'] ) && rocket_valid_key() ) {
// Add a "Settings saved." admin notice only if not already added.
$notices = array_merge( (array) $wp_settings_errors, (array) get_transient( 'settings_errors' ) );
$notices = array_filter(
$notices,
function( $error ) {
if ( ! $error || ! is_array( $error ) ) {
return false;
}
if ( ! isset( $error['setting'], $error['code'], $error['type'] ) ) {
return false;
}
return 'general' === $error['setting'] && 'settings_updated' === $error['code'] && 'updated' === $error['type'];
}
);
if ( ! $notices ) {
add_settings_error( 'general', 'settings_updated', __( 'Settings saved.', 'rocket' ), 'updated' );
}
}
unset( $input['ignore'] );
return apply_filters( 'rocket_input_sanitize', $input );
}
/**
* Sanitizes the returned value of a checkbox
*
* @since 3.0
*
* @param array $array Options array.
* @param string $key Array key to check.
* @return int
*/
public function sanitize_checkbox( $array, $key ) {
return isset( $array[ $key ] ) && ! empty( $array[ $key ] ) ? 1 : 0;
}
/**
* Sanitizes the DNS Prefetch sub-option value
*
* @since 3.5.1
*
* @param array $input Array of values for the WP Rocket settings option.
* @return array Sanitized array for the DNS Prefetch sub-option
*/
private function sanitize_dns_prefetch( array $input ) {
if ( empty( $input['dns_prefetch'] ) ) {
return [];
}
$value = $input['dns_prefetch'];
if ( ! is_array( $value ) ) {
$value = explode( "\n", $value );
}
$urls = [];
foreach ( $value as $url ) {
$url = trim( $url );
if ( empty( $url ) ) {
continue;
}
$url = preg_replace( '/^(?:https?)?:?\/{3,}/i', 'http://', $url );
$url = esc_url_raw( $url );
if ( empty( $url ) ) {
continue;
}
$urls[] = $url;
}
if ( empty( $urls ) ) {
return [];
}
return array_unique(
array_map(
function( $url ) {
return '//' . wp_parse_url( $url, PHP_URL_HOST );
},
$urls
)
);
}
/**
* Sanitize a list of font file paths.
*
* @since 3.6
*
* @param array|string $files List of filepaths to sanitize. Can be an array of strings or a string listing paths separated by "\n".
* @return array Sanitized filepaths.
*/
private function sanitize_fonts( $files ) {
if ( ! is_array( $files ) ) {
$files = explode( "\n", trim( $files ) );
}
$files = array_map( [ $this, 'sanitize_font' ], $files );
return array_unique( array_filter( $files ) );
}
/**
* Sanitize an entry for the preload fonts option.
*
* @since 3.6
*
* @param string $file URL or path to a font file.
* @return string|bool
*/
private function sanitize_font( $file ) {
if ( ! is_string( $file ) ) {
return false;
}
$file = trim( $file );
if ( empty( $file ) ) {
return false;
}
$parsed_url = wp_parse_url( $file );
$hosts = $this->get_hosts();
if ( ! empty( $parsed_url['host'] ) ) {
$match = false;
foreach ( $hosts as $host ) {
if ( false !== strpos( $file, $host ) ) {
$match = true;
break;
}
}
if ( ! $match ) {
return false;
}
}
$file = str_replace( [ 'http:', 'https:' ], '', $file );
$file = str_replace( $hosts, '', $file );
$file = '/' . ltrim( $file, '/' );
$ext = strtolower( pathinfo( $parsed_url['path'], PATHINFO_EXTENSION ) );
if ( ! in_array( $ext, $this->font_formats, true ) ) {
return false;
}
return $file;
}
/**
* Gets an array of valid hosts.
*
* @since 3.6
*
* @return array
*/
private function get_hosts() {
if ( isset( $this->hosts ) ) {
return $this->hosts;
}
$urls = (array) $this->options->get( 'cdn_cnames', [] );
$urls[] = home_url();
$urls = array_map( 'rocket_add_url_protocol', $urls );
foreach ( $urls as $url ) {
$parsed_url = get_rocket_parse_url( $url );
if ( empty( $parsed_url['host'] ) ) {
continue;
}
$parsed_url['path'] = ( '/' === $parsed_url['path'] ) ? '' : $parsed_url['path'];
$this->hosts[] = "//{$parsed_url['host']}{$parsed_url['path']}";
}
if ( empty( $this->hosts ) ) {
$this->hosts = [];
}
return $this->hosts;
}
}

View File

@@ -0,0 +1,194 @@
<?php
namespace WP_Rocket\Engine\Admin\Settings;
use Imagify_Partner;
use WP_Rocket\Event_Management\Subscriber_Interface;
/**
* WP Rocket settings page subscriber.
*
* @since 3.5.5 Moves into the new architecture.
* @since 3.3
*/
class Subscriber implements Subscriber_Interface {
/**
* Page instance
*
* @var Page
*/
private $page;
/**
* Creates an instance of the object.
*
* @param Page $page Page instance.
*/
public function __construct( Page $page ) {
$this->page = $page;
}
/**
* Return an array of events that this subscriber wants to listen to.
*
* @since 3.3
*
* @return array
*/
public static function get_subscribed_events() {
return [
'admin_menu' => 'add_admin_page',
'admin_init' => 'configure',
'wp_ajax_rocket_refresh_customer_data' => 'refresh_customer_data',
'wp_ajax_rocket_toggle_option' => 'toggle_option',
'rocket_settings_menu_navigation' => [
[ 'add_menu_tools_page' ],
[ 'add_imagify_page', 9 ],
[ 'add_tutorials_page', 11 ],
],
'admin_enqueue_scripts' => 'enqueue_rocket_scripts',
'script_loader_tag' => [ 'async_wistia_script', 10, 2 ],
];
}
/**
* Enqueues WP Rocket scripts on the settings page
*
* @since 3.6
*
* @param string $hook The current admin page.
*
* @return void
*/
public function enqueue_rocket_scripts( $hook ) {
$this->page->enqueue_rocket_scripts( $hook );
}
/**
* Adds the async attribute to the Wistia script
*
* @param string $tag The <script> tag for the enqueued script.
* @param string $handle The script's registered handle.
*
* @return string
*/
public function async_wistia_script( $tag, $handle ) {
return $this->page->async_wistia_script( $tag, $handle );
}
/**
* Adds plugin page to the Settings menu.
*
* @since 3.0
*/
public function add_admin_page() {
add_options_page(
$this->page->get_title(),
/**
* Filters the menu title to display in the Settings sub-menu
*
* @since 3.7.4
*
* @param string $menu_title The text to be used for the menu.
*/
apply_filters( 'rocket_menu_title', $this->page->get_title() ),
$this->page->get_capability(),
$this->page->get_slug(),
[ $this->page, 'render_page' ]
);
}
/**
* Registers the settings, page sections, fields sections and fields.
*
* @since 3.0
*/
public function configure() {
$this->page->configure();
}
/**
* Gets customer data to refresh it on the dashboard with AJAX.
*
* @since 3.0
*
* @return string
*/
public function refresh_customer_data() {
check_ajax_referer( 'rocket-ajax' );
if ( ! current_user_can( 'rocket_manage_options' ) ) {
wp_die();
}
delete_transient( 'wp_rocket_customer_data' );
return wp_send_json_success( $this->page->customer_data() );
}
/**
* Toggle sliding checkboxes option value.
*
* @since 3.0
*/
public function toggle_option() {
$this->page->toggle_option();
}
/**
* Add Tools section to navigation.
*
* @since 3.0
*
* @param array $navigation Array of menu items.
* @return array
*/
public function add_menu_tools_page( $navigation ) {
$navigation['tools'] = [
'id' => 'tools',
'title' => __( 'Tools', 'rocket' ),
'menu_description' => __( 'Import, Export, Rollback', 'rocket' ),
];
return $navigation;
}
/**
* Add Imagify section to navigation.
*
* @since 3.2
*
* @param array $navigation Array of menu items.
* @return array
*/
public function add_imagify_page( $navigation ) {
if ( Imagify_Partner::has_imagify_api_key() ) {
return $navigation;
}
$navigation['imagify'] = [
'id' => 'imagify',
'title' => __( 'Image Optimization', 'rocket' ),
'menu_description' => __( 'Compress your images', 'rocket' ),
];
return $navigation;
}
/**
* Add Tutorials section to navigation.
*
* @since 3.4
*
* @param array $navigation Array of menu items.
* @return array
*/
public function add_tutorials_page( $navigation ) {
$navigation['tutorials'] = [
'id' => 'tutorials',
'title' => __( 'Tutorials', 'rocket' ),
'menu_description' => __( 'Getting started and how to videos', 'rocket' ),
];
return $navigation;
}
}