-
-
- {constants.text.linkPrefetchActivateOnDesktopDescription}
+
+ { /* Desktop Settings */ }
+
+
+
+
+ {
+ constants.text
+ .linkPrefetchActivateOnDesktopDescription
+ }
+
-
- handleChangeOption( 'activeOnDesktop', !settings.activeOnDesktop) }
- />
-
- { settings.activeOnDesktop && (
-
handleChangeOption( 'behavior', v) }
- description={ 'mouseDown' === settings.behavior ? constants.text.linkPrefetchBehaviorMouseDownDescription : constants.text.linkPrefetchBehaviorMouseHoverDescription}
- className='nfd-mb-6'
- >
-
+ handleChangeOption(
+ 'activeOnDesktop',
+ ! settings.activeOnDesktop
+ )
+ }
/>
-
-
- )
- }
- {/* Mobile Settings */}
-
-
-
-
- {constants.text.linkPrefetchActivateOnMobileDescription}
+
+ { settings.activeOnDesktop && (
+
+ handleChangeOption( 'behavior', v )
+ }
+ description={
+ 'mouseDown' === settings.behavior
+ ? constants.text
+ .linkPrefetchBehaviorMouseDownDescription
+ : constants.text
+ .linkPrefetchBehaviorMouseHoverDescription
+ }
+ className="nfd-mb-6"
+ >
+
+
+
+ ) }
+ { /* Mobile Settings */ }
+
+
+
+
+ {
+ constants.text
+ .linkPrefetchActivateOnMobileDescription
+ }
+
-
-
handleChangeOption('activeOnMobile', !settings.activeOnMobile) }
- />
-
- { settings.activeOnMobile && (
-
handleChangeOption( 'mobileBehavior', v) }
- description={'touchstart' === settings.mobileBehavior ? constants.text.linkPrefetchBehaviorMobileTouchstartDescription : constants.text.linkPrefetchBehaviorMobileViewportDescription}
- className='nfd-mb-6'
- >
-
+ handleChangeOption(
+ 'activeOnMobile',
+ ! settings.activeOnMobile
+ )
+ }
/>
-
+ { settings.activeOnMobile && (
+
+ handleChangeOption( 'mobileBehavior', v )
+ }
+ description={
+ 'touchstart' === settings.mobileBehavior
+ ? constants.text
+ .linkPrefetchBehaviorMobileTouchstartDescription
+ : constants.text
+ .linkPrefetchBehaviorMobileViewportDescription
+ }
+ className="nfd-mb-6"
+ >
+
+
+
+ ) }
+ { /* Ignore Keywords */ }
+ { ( settings.activeOnMobile || settings.activeOnDesktop ) && (
+
+ handleChangeOption(
+ 'ignoreKeywords',
+ e.target.value
+ )
+ }
+ value={ settings.ignoreKeywords }
/>
-
- )
- }
- {/* Ignore Keywords */}
- { ( settings.activeOnMobile || settings.activeOnDesktop ) &&
-
handleChangeOption('ignoreKeywords', e.target.value)}
- value={settings.ignoreKeywords}
- />
- }
-
-
+ ) }
+
>
- )
-}
+ );
+};
-export default LinkPrefetch;
\ No newline at end of file
+export default LinkPrefetch;
diff --git a/components/performance/defaultText.js b/components/performance/defaultText.js
index 8b1c399..c286dcd 100644
--- a/components/performance/defaultText.js
+++ b/components/performance/defaultText.js
@@ -1,46 +1,141 @@
+import { __ } from '@wordpress/i18n';
+
const defaultText = {
- cacheLevel0Description: __('No cache enabled. Every page load is fresh. ', 'wp-module-performance'),
- cacheLevel0Label: __('Disabled', 'wp-module-performance'),
- cacheLevel0NoticeText: __('Caching disabled.', 'wp-module-performance'),
- cacheLevel0Recommendation: __('Not recommended.', 'wp-module-performance'),
- cacheLevel1Description: __('Cache static assets like images and the appearance of your site for 1 hour. ', 'wp-module-performance'),
- cacheLevel1Label: __('Assets Only', 'wp-module-performance'),
- cacheLevel1NoticeText: __('Cache enabled for assets only.', 'wp-module-performance'),
- cacheLevel1Recommendation: __('Tuned for online stores and member sites that need to be fresh.', 'wp-module-performance'),
- cacheLevel2Description: __('Cache static assets for 24 hours and web pages for 2 hours. ', 'wp-module-performance'),
- cacheLevel2Label: __('Assets & Web Pages', 'wp-module-performance'),
- cacheLevel2NoticeText: __('Cache enabled for assets and pages.', 'wp-module-performance'),
- cacheLevel2Recommendation: __('Tuned for sites that change at least weekly.', 'wp-module-performance'),
- cacheLevel3Description: __('Cache static assets for 1 week and web pages for 8 hours. ', 'wp-module-performance'),
- cacheLevel3Label: __('Assets & Web Pages - Extended', 'wp-module-performance'),
- cacheLevel3NoticeText: __('Cache enabled for assets and pages (extended).', 'wp-module-performance'),
- cacheLevel3Recommendation: __('Tuned for sites that update a few times a month or less.', 'wp-module-performance'),
- cacheLevelDescription: __('Boost speed and performance by storing a copy of your website content, files, and images online so the pages of your website load faster for your visitors.', 'wp-module-performance'),
- cacheLevelNoticeTitle: __('Cache setting saved', 'wp-module-performance'),
- cacheLevelTitle: __('Cache Level', 'wp-module-performance'),
- clearCacheButton: __('Clear All Cache Now', 'wp-module-performance'),
- clearCacheDescription: __('We automatically clear your cache as you work (creating content, changing settings, installing plugins and more). But you can manually clear it here to be confident it is fresh.', 'wp-module-performance'),
- clearCacheNoticeTitle: __('Cache cleared', 'wp-module-performance'),
- clearCacheTitle: __('Clear Cache', 'wp-module-performance'),
- linkPrefetchDescription: __('Asks the browser to download and cache links on the page ahead of them being clicked on, so that when they are clicked they load almost instantly. ','wp-module-performance'),
- linkPrefetchNoticeTitle: __('Link prefetching setting saved','wp-module-performance'),
- linkPrefetchTitle: __('Link Prefetch','wp-module-performance'),
- linkPrefetchActivateOnDesktopDescription: __('Enable link prefetching on desktop','wp-module-performance'),
- linkPrefetchActivateOnDesktopLabel: __('Activate on desktop','wp-module-performance'),
- linkPrefetchBehaviorDescription: __('Behavior of the prefetch','wp-module-performance'),
- linkPrefetchBehaviorLabel: __('Behavior','wp-module-performance'),
- linkPrefetchBehaviorMouseDownLabel: __('Prefetch on Mouse down','wp-module-performance'),
- linkPrefetchBehaviorMouseDownDescription: __('Prefetch on Mouse Down: Starts loading the page as soon as you click down, for faster response when you release the click.','wp-module-performance'),
- linkPrefetchBehaviorMouseHoverLabel: __('Prefetch on Mouse Hover (Recommended)','wp-module-performance'),
- linkPrefetchBehaviorMouseHoverDescription: __('Prefetch on Mouse Hover: Begins loading the page the moment your cursor hovers over a link','wp-module-performance'),
- linkPrefetchActivateOnMobileDescription: __('Enable link prefetching on Mobile','wp-module-performance'),
- linkPrefetchActivateOnMobileLabel: __('Activate on mobile','wp-module-performance'),
- linkPrefetchBehaviorMobileTouchstartLabel: __('Prefetch on Touchstart (Recommended)','wp-module-performance'),
- linkPrefetchBehaviorMobileTouchstartDescription: __('Prefetch on Touch Start: Instantly starts loading the page as soon as you tap the screen, ensuring a quicker response when you lift your finger.','wp-module-performance'),
- linkPrefetchBehaviorMobileViewportLabel: __('Prefetch Above the Fold','wp-module-performance'),
- linkPrefetchBehaviorMobileViewportDescription: __('Prefetch Above the Fold: Loads links in your current view instantly, ensuring they\'re ready when you need them.','wp-module-performance'),
- linkPrefetchIgnoreKeywordsDescription: __('Exclude Keywords: A comma separated list of words or strings that will exclude a link from being prefetched. For example, excluding "app" will prevent https://example.com/apple from being prefetched.','wp-module-performance'),
- linkPrefetchIgnoreKeywordsLabel: __('Exclude keywords','wp-module-performance'),
+ cacheLevel0Description: __(
+ 'No cache enabled. Every page load is fresh. ',
+ 'wp-module-performance'
+ ),
+ cacheLevel0Label: __( 'Disabled', 'wp-module-performance' ),
+ cacheLevel0NoticeText: __( 'Caching disabled.', 'wp-module-performance' ),
+ cacheLevel0Recommendation: __(
+ 'Not recommended.',
+ 'wp-module-performance'
+ ),
+ cacheLevel1Description: __(
+ 'Cache static assets like images and the appearance of your site for 1 hour. ',
+ 'wp-module-performance'
+ ),
+ cacheLevel1Label: __( 'Assets Only', 'wp-module-performance' ),
+ cacheLevel1NoticeText: __(
+ 'Cache enabled for assets only.',
+ 'wp-module-performance'
+ ),
+ cacheLevel1Recommendation: __(
+ 'Tuned for online stores and member sites that need to be fresh.',
+ 'wp-module-performance'
+ ),
+ cacheLevel2Description: __(
+ 'Cache static assets for 24 hours and web pages for 2 hours. ',
+ 'wp-module-performance'
+ ),
+ cacheLevel2Label: __( 'Assets & Web Pages', 'wp-module-performance' ),
+ cacheLevel2NoticeText: __(
+ 'Cache enabled for assets and pages.',
+ 'wp-module-performance'
+ ),
+ cacheLevel2Recommendation: __(
+ 'Tuned for sites that change at least weekly.',
+ 'wp-module-performance'
+ ),
+ cacheLevel3Description: __(
+ 'Cache static assets for 1 week and web pages for 8 hours. ',
+ 'wp-module-performance'
+ ),
+ cacheLevel3Label: __(
+ 'Assets & Web Pages - Extended',
+ 'wp-module-performance'
+ ),
+ cacheLevel3NoticeText: __(
+ 'Cache enabled for assets and pages (extended).',
+ 'wp-module-performance'
+ ),
+ cacheLevel3Recommendation: __(
+ 'Tuned for sites that update a few times a month or less.',
+ 'wp-module-performance'
+ ),
+ cacheLevelDescription: __(
+ 'Boost speed and performance by storing a copy of your website content, files, and images online so the pages of your website load faster for your visitors.',
+ 'wp-module-performance'
+ ),
+ cacheLevelNoticeTitle: __( 'Cache setting saved', 'wp-module-performance' ),
+ cacheLevelTitle: __( 'Cache Level', 'wp-module-performance' ),
+ clearCacheButton: __( 'Clear All Cache Now', 'wp-module-performance' ),
+ clearCacheDescription: __(
+ 'We automatically clear your cache as you work (creating content, changing settings, installing plugins and more). But you can manually clear it here to be confident it is fresh.',
+ 'wp-module-performance'
+ ),
+ clearCacheNoticeTitle: __( 'Cache cleared', 'wp-module-performance' ),
+ clearCacheTitle: __( 'Clear Cache', 'wp-module-performance' ),
+ linkPrefetchDescription: __(
+ 'Asks the browser to download and cache links on the page ahead of them being clicked on, so that when they are clicked they load almost instantly. ',
+ 'wp-module-performance'
+ ),
+ linkPrefetchNoticeTitle: __(
+ 'Link prefetching setting saved',
+ 'wp-module-performance'
+ ),
+ linkPrefetchTitle: __( 'Link Prefetch', 'wp-module-performance' ),
+ linkPrefetchActivateOnDesktopDescription: __(
+ 'Enable link prefetching on desktop',
+ 'wp-module-performance'
+ ),
+ linkPrefetchActivateOnDesktopLabel: __(
+ 'Activate on desktop',
+ 'wp-module-performance'
+ ),
+ linkPrefetchBehaviorDescription: __(
+ 'Behavior of the prefetch',
+ 'wp-module-performance'
+ ),
+ linkPrefetchBehaviorLabel: __( 'Behavior', 'wp-module-performance' ),
+ linkPrefetchBehaviorMouseDownLabel: __(
+ 'Prefetch on Mouse down',
+ 'wp-module-performance'
+ ),
+ linkPrefetchBehaviorMouseDownDescription: __(
+ 'Prefetch on Mouse Down: Starts loading the page as soon as you click down, for faster response when you release the click.',
+ 'wp-module-performance'
+ ),
+ linkPrefetchBehaviorMouseHoverLabel: __(
+ 'Prefetch on Mouse Hover (Recommended)',
+ 'wp-module-performance'
+ ),
+ linkPrefetchBehaviorMouseHoverDescription: __(
+ 'Prefetch on Mouse Hover: Begins loading the page the moment your cursor hovers over a link',
+ 'wp-module-performance'
+ ),
+ linkPrefetchActivateOnMobileDescription: __(
+ 'Enable link prefetching on Mobile',
+ 'wp-module-performance'
+ ),
+ linkPrefetchActivateOnMobileLabel: __(
+ 'Activate on mobile',
+ 'wp-module-performance'
+ ),
+ linkPrefetchBehaviorMobileTouchstartLabel: __(
+ 'Prefetch on Touchstart (Recommended)',
+ 'wp-module-performance'
+ ),
+ linkPrefetchBehaviorMobileTouchstartDescription: __(
+ 'Prefetch on Touch Start: Instantly starts loading the page as soon as you tap the screen, ensuring a quicker response when you lift your finger.',
+ 'wp-module-performance'
+ ),
+ linkPrefetchBehaviorMobileViewportLabel: __(
+ 'Prefetch Above the Fold',
+ 'wp-module-performance'
+ ),
+ linkPrefetchBehaviorMobileViewportDescription: __(
+ "Prefetch Above the Fold: Loads links in your current view instantly, ensuring they're ready when you need them.",
+ 'wp-module-performance'
+ ),
+ linkPrefetchIgnoreKeywordsDescription: __(
+ 'Exclude Keywords: A comma separated list of words or strings that will exclude a link from being prefetched. For example, excluding "app" will prevent https://example.com/apple from being prefetched.',
+ 'wp-module-performance'
+ ),
+ linkPrefetchIgnoreKeywordsLabel: __(
+ 'Exclude keywords',
+ 'wp-module-performance'
+ ),
};
-export default defaultText;
\ No newline at end of file
+export default defaultText;
diff --git a/components/performance/index.js b/components/performance/index.js
index 76672dd..a7b9878 100644
--- a/components/performance/index.js
+++ b/components/performance/index.js
@@ -7,60 +7,61 @@ import { default as LinkPrefetch } from '../linkPrefetch/';
/**
* Performance Module
* For use in brand plugin apps to display performance page and settings
- *
- * @param {*} props
- * @returns
+ *
+ * @param {*} props
+ * @return
*/
-const Performance = ({methods, constants, Components, ...props}) => {
- const { store, setStore } = methods.useContext(methods.AppStore);
- const [ isError, setError ] = methods.useState(false);
+const Performance = ( { methods, constants, Components, ...props } ) => {
+ const { store, setStore } = methods.useContext( methods.AppStore );
+ const [ isError, setError ] = methods.useState( false );
- let notify = methods.useNotification();
+ const notify = methods.useNotification();
// set default text if not provided
- constants.text = Object.assign(defaultText, constants.text);
+ constants.text = Object.assign( defaultText, constants.text );
- const makeNotice = (id, title, description, variant="success", duration=false) => {
- notify.push(`performance-notice-${id}`, {
- title,
- description: (
-
- {description}
-
- ),
- variant,
- autoDismiss: duration,
- });
- };
- constants.store = store;
- methods.makeNotice = makeNotice;
- methods.setStore = setStore;
- methods.setError = setError;
+ const makeNotice = (
+ id,
+ title,
+ description,
+ variant = 'success',
+ duration = false
+ ) => {
+ notify.push( `performance-notice-${ id }`, {
+ title,
+ description: { description },
+ variant,
+ autoDismiss: duration,
+ } );
+ };
+ constants.store = store;
+ methods.makeNotice = makeNotice;
+ methods.setStore = setStore;
+ methods.setError = setError;
return (
- <>
-
-
-
-
-
-
-
-
-
- >
+ <>
+
+
+
+
+
+
+
+
+
+ >
);
-
};
-export default Performance;
\ No newline at end of file
+export default Performance;
From 736cf482973f2b5a8358245dadaefbda9d1fecd4 Mon Sep 17 00:00:00 2001
From: Alessio Torrisi
Date: Mon, 25 Nov 2024 15:45:53 +0100
Subject: [PATCH 46/66] New: upsell option "Optimize Critical CSS Loading"
---
.../JetpackBoost/SingleOption.js | 97 ++++---
.../advancedSettings/JetpackBoost/index.js | 81 ++++--
components/performance/defaultText.js | 16 ++
includes/Performance.php | 26 ++
includes/RestApi/JetpackController.php | 4 +
package-lock.json | 245 +++++++++++++++++-
package.json | 5 +-
styles/styles.css | 4 +
8 files changed, 422 insertions(+), 56 deletions(-)
diff --git a/components/advancedSettings/JetpackBoost/SingleOption.js b/components/advancedSettings/JetpackBoost/SingleOption.js
index d8ec2c4..70c96e8 100644
--- a/components/advancedSettings/JetpackBoost/SingleOption.js
+++ b/components/advancedSettings/JetpackBoost/SingleOption.js
@@ -3,7 +3,15 @@ import apiFetch from '@wordpress/api-fetch';
import { useRef, useState } from '@wordpress/element';
// Newfold
-import { ToggleField, Textarea } from '@newfold/ui-component-library';
+import {
+ ToggleField,
+ Textarea,
+ FeatureUpsell,
+} from '@newfold/ui-component-library';
+import { NewfoldRuntime } from '@newfold-labs/wp-module-runtime';
+
+// Third-parts
+import parse from 'html-react-parser';
const SingleOption = ( { params, isChild, methods, constants } ) => {
const [ optionDetails, setOptionDetails ] = useState( {
@@ -12,7 +20,8 @@ const SingleOption = ( { params, isChild, methods, constants } ) => {
description: params.description,
value: params.value ? String( params.value ) : '',
type: params.type,
- externalLink: params.externalLink,
+ externalText: params.externalText,
+ premiumUrl: params.premiumUrl ?? '',
children: params.children,
} );
@@ -70,35 +79,63 @@ const SingleOption = ( { params, isChild, methods, constants } ) => {
case 'toggle':
return (
<>
- {
- handleChangeOption( value, option.id );
- } }
- />
- { option.externalLink ? (
-
- { constants.text.jetpackBoostDicoverMore }{ ' ' }
-
- { ' ' }
- { __(
- 'here',
- 'newfold-module-performance'
- ) }{ ' ' }
-
-
- ) : (
- ''
+
+ handleChangeOption(
+ value,
+ option.id
+ )
+ }
+ />
+ { option.externalText ? (
+
+ { parse( option.externalText ) }
+
+ ) : null }
+
+ ) }
+ { ( ! option.premiumUrl ||
+ NewfoldRuntime.sdk.performance
+ .jetpack_boost_premium_is_active ) && (
+ <>
+
+ handleChangeOption( value, option.id )
+ }
+ />
+ { option.externalText ? (
+
+ { parse( option.externalText ) }
+
+ ) : null }
+ >
) }
>
);
diff --git a/components/advancedSettings/JetpackBoost/index.js b/components/advancedSettings/JetpackBoost/index.js
index d754bbe..b781d57 100644
--- a/components/advancedSettings/JetpackBoost/index.js
+++ b/components/advancedSettings/JetpackBoost/index.js
@@ -1,5 +1,6 @@
// Wordpress
import { useState } from '@wordpress/element';
+import { sprintf, __ } from '@wordpress/i18n';
// Newfold
import { FeatureUpsell } from '@newfold/ui-component-library';
@@ -17,7 +18,26 @@ const JetpackBoost = ( { methods, constants } ) => {
description: constants.text.jetpackBoostCriticalCssDescription,
value: NewfoldRuntime.sdk.performance.jetpack_boost_critical_css,
type: 'toggle',
- externalLink: true,
+ externalText: sprintf(
+ // translators: %1$s is the opening tag, %2$s is the closing tag.
+ __( 'Discover more %1$shere%2$s', 'wp-module-performance' ),
+ '',
+ ''
+ ),
+ hideOnPremium: true,
+ },
+ {
+ id: 'critical-css-premium',
+ label: constants.text.jetpackBoostCriticalCssPremiumTitle,
+ description:
+ constants.text.jetpackBoostCriticalCssPremiumDescription,
+ value: NewfoldRuntime.sdk.performance.jetpack_boost_critical_css,
+ type: 'toggle',
+ premiumUrl:
+ window.location.origin +
+ '/wp-admin/admin.php?page=jetpack-boost',
},
{
id: 'render-blocking-js',
@@ -87,28 +107,43 @@ const JetpackBoost = ( { methods, constants } ) => {
) : (
- fields.map( ( field ) => (
-
-
- { field.children?.map( ( subfield ) => (
-
-
-
- ) ) }
-
- ) )
+ fields.map( ( field ) => {
+ if (
+ field.hideOnPremium &&
+ NewfoldRuntime.sdk.performance
+ .jetpack_boost_premium_is_active
+ ) {
+ return null; // Salta questo elemento
+ }
+
+ return (
+
+
+ { field.children?.map( ( subfield ) => (
+
+
+
+ ) ) }
+
+ );
+ } )
) }
>
);
diff --git a/components/performance/defaultText.js b/components/performance/defaultText.js
index 04bf9b9..6c3fe1c 100644
--- a/components/performance/defaultText.js
+++ b/components/performance/defaultText.js
@@ -1,3 +1,5 @@
+import { sprintf, __ } from '@wordpress/i18n';
+
const defaultText = {
cacheLevel0Description: __(
'No cache enabled. Every page load is fresh.',
@@ -80,6 +82,20 @@ const defaultText = {
'Move important styling information to the start of the page, which helps pages display your content sooner, so your users don’t have to wait for the entire page to load.',
'wp-module-performance'
),
+ jetpackBoostCriticalCssPremiumTitle: __(
+ 'Optimize Critical CSS Loading (UPGRADED)',
+ 'wp-module-performance'
+ ),
+ jetpackBoostCriticalCssPremiumDescription: sprintf(
+ // translators: %1$s is a line break (
), %2$s is the opening
tag, %3$s is the closing tag.
+ __(
+ 'Move important styling information to the start of the page, which helps pages display your content sooner, so your users don’t have to wait for the entire page to load.%1$s %2$sBoost will automatically generate your Critical CSS%3$s whenever you make changes to the HTML or CSS structure of your site.',
+ 'wp-module-performance'
+ ),
+ '
',
+ '
',
+ ''
+ ),
jetpackBoostRenderBlockingTitle: __(
'Defer Non-Essential JavaScript',
'wp-module-performance'
diff --git a/includes/Performance.php b/includes/Performance.php
index 8679c6c..e810e7e 100644
--- a/includes/Performance.php
+++ b/includes/Performance.php
@@ -10,6 +10,8 @@
use NewfoldLabs\WP\Module\Performance\Permissions;
use NewfoldLabs\WP\Module\Installer\Services\PluginInstaller;
+use Automattic\Jetpack\Current_Plan;
+
/**
* Performance Class
*/
@@ -323,6 +325,7 @@ public function adminBarMenu( \WP_Admin_Bar $wp_admin_bar ) {
public function add_to_runtime( $sdk ) {
$values = array(
'jetpack_boost_is_active' => defined( 'JETPACK_BOOST_VERSION' ),
+ 'jetpack_boost_premium_is_active' => $this->isJetPackBoostActive(),
'jetpack_boost_critical_css' => get_option( 'jetpack_boost_status_critical-css' ),
'jetpack_boost_blocking_js' => get_option( 'jetpack_boost_status_render-blocking-js' ),
'jetpack_boost_minify_js' => get_option( 'jetpack_boost_status_minify-js', array() ),
@@ -331,6 +334,29 @@ public function add_to_runtime( $sdk ) {
'jetpack_boost_minify_css_excludes' => implode( ',', get_option( 'jetpack_boost_ds_minify_css_excludes', array() ) ),
'install_token' => PluginInstaller::rest_get_plugin_install_hash(),
);
+
return array_merge( $sdk, array( 'performance' => $values ) );
}
+
+
+ /**
+ * Check if Jetpack Boost premium is active.
+ *
+ * @return boolean
+ */
+ public function isJetPackBoostActive() {
+ $exists = false;
+
+ if ( class_exists( 'Automattic\Jetpack\Current_Plan' ) ) {
+ $products = Current_Plan::get_products();
+ foreach ( $products as $product ) {
+ if ( isset( $product['product_slug'] ) && strpos( $product['product_slug'], 'jetpack-boost' ) !== false ) {
+ $exists = true;
+ break;
+ }
+ }
+ }
+
+ return $exists;
+ }
}
diff --git a/includes/RestApi/JetpackController.php b/includes/RestApi/JetpackController.php
index 82d465d..53ce8f4 100644
--- a/includes/RestApi/JetpackController.php
+++ b/includes/RestApi/JetpackController.php
@@ -82,6 +82,10 @@ public function set_options( $request ) {
);
}
+ if ( 'critical-css-premium' === $field['id'] ) {
+ $field['id'] = 'critical-css';
+ }
+
$option_key = 'jetpack_boost_status_' . $field['id'];
$option_value = $field['value'];
diff --git a/package-lock.json b/package-lock.json
index 8dc9e06..767fb18 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -10,7 +10,8 @@
"@heroicons/react": "^2.0.18",
"@newfold-labs/wp-module-runtime": "^1.0.0",
"@newfold/ui-component-library": "^1.0.1",
- "@tailwindcss/forms": "^0.5.8"
+ "@tailwindcss/forms": "^0.5.8",
+ "html-react-parser": "^5.1.18"
},
"devDependencies": {
"@testing-library/cypress": "^9.0.0",
@@ -1594,6 +1595,61 @@
"integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==",
"dev": true
},
+ "node_modules/dom-serializer": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz",
+ "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==",
+ "license": "MIT",
+ "dependencies": {
+ "domelementtype": "^2.3.0",
+ "domhandler": "^5.0.2",
+ "entities": "^4.2.0"
+ },
+ "funding": {
+ "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1"
+ }
+ },
+ "node_modules/domelementtype": {
+ "version": "2.3.0",
+ "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz",
+ "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==",
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/fb55"
+ }
+ ],
+ "license": "BSD-2-Clause"
+ },
+ "node_modules/domhandler": {
+ "version": "5.0.3",
+ "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz",
+ "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==",
+ "license": "BSD-2-Clause",
+ "dependencies": {
+ "domelementtype": "^2.3.0"
+ },
+ "engines": {
+ "node": ">= 4"
+ },
+ "funding": {
+ "url": "https://github.com/fb55/domhandler?sponsor=1"
+ }
+ },
+ "node_modules/domutils": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.1.0.tgz",
+ "integrity": "sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==",
+ "license": "BSD-2-Clause",
+ "dependencies": {
+ "dom-serializer": "^2.0.0",
+ "domelementtype": "^2.3.0",
+ "domhandler": "^5.0.3"
+ },
+ "funding": {
+ "url": "https://github.com/fb55/domutils?sponsor=1"
+ }
+ },
"node_modules/dot-case": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/dot-case/-/dot-case-3.0.4.tgz",
@@ -1648,6 +1704,18 @@
"node": ">=8.6"
}
},
+ "node_modules/entities": {
+ "version": "4.5.0",
+ "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",
+ "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==",
+ "license": "BSD-2-Clause",
+ "engines": {
+ "node": ">=0.12"
+ },
+ "funding": {
+ "url": "https://github.com/fb55/entities?sponsor=1"
+ }
+ },
"node_modules/es-get-iterator": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/es-get-iterator/-/es-get-iterator-1.1.3.tgz",
@@ -2146,6 +2214,56 @@
"tslib": "^2.0.3"
}
},
+ "node_modules/html-dom-parser": {
+ "version": "5.0.10",
+ "resolved": "https://registry.npmjs.org/html-dom-parser/-/html-dom-parser-5.0.10.tgz",
+ "integrity": "sha512-GwArYL3V3V8yU/mLKoFF7HlLBv80BZ2Ey1BzfVNRpAci0cEKhFHI/Qh8o8oyt3qlAMLlK250wsxLdYX4viedvg==",
+ "license": "MIT",
+ "dependencies": {
+ "domhandler": "5.0.3",
+ "htmlparser2": "9.1.0"
+ }
+ },
+ "node_modules/html-react-parser": {
+ "version": "5.1.18",
+ "resolved": "https://registry.npmjs.org/html-react-parser/-/html-react-parser-5.1.18.tgz",
+ "integrity": "sha512-65BwC0zzrdeW96jB2FRr5f1ovBhRMpLPJNvwkY5kA8Ay5xdL9t/RH2/uUTM7p+cl5iM88i6dDk4LXtfMnRmaJQ==",
+ "license": "MIT",
+ "dependencies": {
+ "domhandler": "5.0.3",
+ "html-dom-parser": "5.0.10",
+ "react-property": "2.0.2",
+ "style-to-js": "1.1.16"
+ },
+ "peerDependencies": {
+ "@types/react": "0.14 || 15 || 16 || 17 || 18",
+ "react": "0.14 || 15 || 16 || 17 || 18"
+ },
+ "peerDependenciesMeta": {
+ "@types/react": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/htmlparser2": {
+ "version": "9.1.0",
+ "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-9.1.0.tgz",
+ "integrity": "sha512-5zfg6mHUoaer/97TxnGpxmbR7zJtPwIYFMZ/H5ucTlPZhKvtum05yiPK3Mgai3a0DyVxv7qYqoweaEd2nrYQzQ==",
+ "funding": [
+ "https://github.com/fb55/htmlparser2?sponsor=1",
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/fb55"
+ }
+ ],
+ "license": "MIT",
+ "dependencies": {
+ "domelementtype": "^2.3.0",
+ "domhandler": "^5.0.3",
+ "domutils": "^3.1.0",
+ "entities": "^4.5.0"
+ }
+ },
"node_modules/http-signature": {
"version": "1.3.6",
"resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.3.6.tgz",
@@ -2232,6 +2350,12 @@
"node": ">=10"
}
},
+ "node_modules/inline-style-parser": {
+ "version": "0.2.4",
+ "resolved": "https://registry.npmjs.org/inline-style-parser/-/inline-style-parser-0.2.4.tgz",
+ "integrity": "sha512-0aO8FkhNZlj/ZIbNi7Lxxr12obT7cL1moPfE4tg1LkX7LlLfC6DeX4l2ZEud1ukP9jNQyNnfzQVqwbwmAATY4Q==",
+ "license": "MIT"
+ },
"node_modules/internal-slot": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.5.tgz",
@@ -3629,6 +3753,12 @@
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
"dev": true
},
+ "node_modules/react-property": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/react-property/-/react-property-2.0.2.tgz",
+ "integrity": "sha512-+PbtI3VuDV0l6CleQMsx2gtK0JZbZKbpdu5ynr+lbsuvtmgbNcS3VM0tuY2QjFNOcWxvXeHjDpy42RO+4U2rug==",
+ "license": "MIT"
+ },
"node_modules/read-cache": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz",
@@ -4041,6 +4171,24 @@
"node": ">=6"
}
},
+ "node_modules/style-to-js": {
+ "version": "1.1.16",
+ "resolved": "https://registry.npmjs.org/style-to-js/-/style-to-js-1.1.16.tgz",
+ "integrity": "sha512-/Q6ld50hKYPH3d/r6nr117TZkHR0w0kGGIVfpG9N6D8NymRPM9RqCUv4pRpJ62E5DqOYx2AFpbZMyCPnjQCnOw==",
+ "license": "MIT",
+ "dependencies": {
+ "style-to-object": "1.0.8"
+ }
+ },
+ "node_modules/style-to-object": {
+ "version": "1.0.8",
+ "resolved": "https://registry.npmjs.org/style-to-object/-/style-to-object-1.0.8.tgz",
+ "integrity": "sha512-xT47I/Eo0rwJmaXC4oilDGDWLohVhR6o/xAQcPQN8q6QBuZVL8qMYL85kLmST5cPjAorwvqIA4qXTRQoYHaL6g==",
+ "license": "MIT",
+ "dependencies": {
+ "inline-style-parser": "0.2.4"
+ }
+ },
"node_modules/sucrase": {
"version": "3.35.0",
"resolved": "https://registry.npmjs.org/sucrase/-/sucrase-3.35.0.tgz",
@@ -5704,6 +5852,39 @@
"integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==",
"dev": true
},
+ "dom-serializer": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz",
+ "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==",
+ "requires": {
+ "domelementtype": "^2.3.0",
+ "domhandler": "^5.0.2",
+ "entities": "^4.2.0"
+ }
+ },
+ "domelementtype": {
+ "version": "2.3.0",
+ "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz",
+ "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw=="
+ },
+ "domhandler": {
+ "version": "5.0.3",
+ "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz",
+ "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==",
+ "requires": {
+ "domelementtype": "^2.3.0"
+ }
+ },
+ "domutils": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.1.0.tgz",
+ "integrity": "sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==",
+ "requires": {
+ "dom-serializer": "^2.0.0",
+ "domelementtype": "^2.3.0",
+ "domhandler": "^5.0.3"
+ }
+ },
"dot-case": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/dot-case/-/dot-case-3.0.4.tgz",
@@ -5754,6 +5935,11 @@
"strip-ansi": "^6.0.1"
}
},
+ "entities": {
+ "version": "4.5.0",
+ "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",
+ "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw=="
+ },
"es-get-iterator": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/es-get-iterator/-/es-get-iterator-1.1.3.tgz",
@@ -6119,6 +6305,37 @@
"tslib": "^2.0.3"
}
},
+ "html-dom-parser": {
+ "version": "5.0.10",
+ "resolved": "https://registry.npmjs.org/html-dom-parser/-/html-dom-parser-5.0.10.tgz",
+ "integrity": "sha512-GwArYL3V3V8yU/mLKoFF7HlLBv80BZ2Ey1BzfVNRpAci0cEKhFHI/Qh8o8oyt3qlAMLlK250wsxLdYX4viedvg==",
+ "requires": {
+ "domhandler": "5.0.3",
+ "htmlparser2": "9.1.0"
+ }
+ },
+ "html-react-parser": {
+ "version": "5.1.18",
+ "resolved": "https://registry.npmjs.org/html-react-parser/-/html-react-parser-5.1.18.tgz",
+ "integrity": "sha512-65BwC0zzrdeW96jB2FRr5f1ovBhRMpLPJNvwkY5kA8Ay5xdL9t/RH2/uUTM7p+cl5iM88i6dDk4LXtfMnRmaJQ==",
+ "requires": {
+ "domhandler": "5.0.3",
+ "html-dom-parser": "5.0.10",
+ "react-property": "2.0.2",
+ "style-to-js": "1.1.16"
+ }
+ },
+ "htmlparser2": {
+ "version": "9.1.0",
+ "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-9.1.0.tgz",
+ "integrity": "sha512-5zfg6mHUoaer/97TxnGpxmbR7zJtPwIYFMZ/H5ucTlPZhKvtum05yiPK3Mgai3a0DyVxv7qYqoweaEd2nrYQzQ==",
+ "requires": {
+ "domelementtype": "^2.3.0",
+ "domhandler": "^5.0.3",
+ "domutils": "^3.1.0",
+ "entities": "^4.5.0"
+ }
+ },
"http-signature": {
"version": "1.3.6",
"resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.3.6.tgz",
@@ -6175,6 +6392,11 @@
"integrity": "sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA==",
"dev": true
},
+ "inline-style-parser": {
+ "version": "0.2.4",
+ "resolved": "https://registry.npmjs.org/inline-style-parser/-/inline-style-parser-0.2.4.tgz",
+ "integrity": "sha512-0aO8FkhNZlj/ZIbNi7Lxxr12obT7cL1moPfE4tg1LkX7LlLfC6DeX4l2ZEud1ukP9jNQyNnfzQVqwbwmAATY4Q=="
+ },
"internal-slot": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.5.tgz",
@@ -7125,6 +7347,11 @@
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
"dev": true
},
+ "react-property": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/react-property/-/react-property-2.0.2.tgz",
+ "integrity": "sha512-+PbtI3VuDV0l6CleQMsx2gtK0JZbZKbpdu5ynr+lbsuvtmgbNcS3VM0tuY2QjFNOcWxvXeHjDpy42RO+4U2rug=="
+ },
"read-cache": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz",
@@ -7424,6 +7651,22 @@
"integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==",
"dev": true
},
+ "style-to-js": {
+ "version": "1.1.16",
+ "resolved": "https://registry.npmjs.org/style-to-js/-/style-to-js-1.1.16.tgz",
+ "integrity": "sha512-/Q6ld50hKYPH3d/r6nr117TZkHR0w0kGGIVfpG9N6D8NymRPM9RqCUv4pRpJ62E5DqOYx2AFpbZMyCPnjQCnOw==",
+ "requires": {
+ "style-to-object": "1.0.8"
+ }
+ },
+ "style-to-object": {
+ "version": "1.0.8",
+ "resolved": "https://registry.npmjs.org/style-to-object/-/style-to-object-1.0.8.tgz",
+ "integrity": "sha512-xT47I/Eo0rwJmaXC4oilDGDWLohVhR6o/xAQcPQN8q6QBuZVL8qMYL85kLmST5cPjAorwvqIA4qXTRQoYHaL6g==",
+ "requires": {
+ "inline-style-parser": "0.2.4"
+ }
+ },
"sucrase": {
"version": "3.35.0",
"resolved": "https://registry.npmjs.org/sucrase/-/sucrase-3.35.0.tgz",
diff --git a/package.json b/package.json
index 596d8fa..88928a2 100644
--- a/package.json
+++ b/package.json
@@ -12,9 +12,10 @@
],
"dependencies": {
"@heroicons/react": "^2.0.18",
- "@newfold/ui-component-library": "^1.0.1",
"@newfold-labs/wp-module-runtime": "^1.0.0",
- "@tailwindcss/forms": "^0.5.8"
+ "@newfold/ui-component-library": "^1.0.1",
+ "@tailwindcss/forms": "^0.5.8",
+ "html-react-parser": "^5.1.18"
},
"devDependencies": {
"@testing-library/cypress": "^9.0.0",
diff --git a/styles/styles.css b/styles/styles.css
index 9608974..ba3b647 100644
--- a/styles/styles.css
+++ b/styles/styles.css
@@ -43,3 +43,7 @@
.nfd-performance-jetpack-boost-single-option-container{
margin-bottom: 20px;
}
+
+.margin20{
+ margin: 20px 0;
+}
\ No newline at end of file
From 3bbc47a1f4acc33e7a661795bcc93ca32054f59d Mon Sep 17 00:00:00 2001
From: Alessio Torrisi
Date: Mon, 25 Nov 2024 15:49:48 +0100
Subject: [PATCH 47/66] Removed useless comment
---
components/advancedSettings/JetpackBoost/index.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/components/advancedSettings/JetpackBoost/index.js b/components/advancedSettings/JetpackBoost/index.js
index b781d57..992afe1 100644
--- a/components/advancedSettings/JetpackBoost/index.js
+++ b/components/advancedSettings/JetpackBoost/index.js
@@ -113,7 +113,7 @@ const JetpackBoost = ( { methods, constants } ) => {
NewfoldRuntime.sdk.performance
.jetpack_boost_premium_is_active
) {
- return null; // Salta questo elemento
+ return null;
}
return (
From 2f0e7d711835348dbf6b24fe40c0426b4c086559 Mon Sep 17 00:00:00 2001
From: Alessio Torrisi
Date: Tue, 26 Nov 2024 13:05:24 +0100
Subject: [PATCH 48/66] Fix: hide premium option "Critical CSS" when module is
disabled
---
.../advancedSettings/JetpackBoost/index.js | 26 +++++++++++++------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/components/advancedSettings/JetpackBoost/index.js b/components/advancedSettings/JetpackBoost/index.js
index 992afe1..a60143a 100644
--- a/components/advancedSettings/JetpackBoost/index.js
+++ b/components/advancedSettings/JetpackBoost/index.js
@@ -27,6 +27,7 @@ const JetpackBoost = ( { methods, constants } ) => {
''
),
hideOnPremium: true,
+ showOnModuleDisabled: true,
},
{
id: 'critical-css-premium',
@@ -38,6 +39,7 @@ const JetpackBoost = ( { methods, constants } ) => {
premiumUrl:
window.location.origin +
'/wp-admin/admin.php?page=jetpack-boost',
+ showOnModuleDisabled: false,
},
{
id: 'render-blocking-js',
@@ -45,6 +47,7 @@ const JetpackBoost = ( { methods, constants } ) => {
description: constants.text.jetpackBoostRenderBlockingDescription,
value: NewfoldRuntime.sdk.performance.jetpack_boost_blocking_js,
type: 'toggle',
+ showOnModuleDisabled: true,
},
{
id: 'minify-js',
@@ -52,6 +55,7 @@ const JetpackBoost = ( { methods, constants } ) => {
description: constants.text.jetpackBoostMinifyJsDescription,
value: NewfoldRuntime.sdk.performance.jetpack_boost_minify_js,
type: 'toggle',
+ showOnModuleDisabled: true,
children: [
{
id: 'minify-js-excludes',
@@ -69,6 +73,7 @@ const JetpackBoost = ( { methods, constants } ) => {
description: constants.text.jetpackBoostMinifyCssDescription,
value: NewfoldRuntime.sdk.performance.jetpack_boost_minify_css,
type: 'toggle',
+ showOnModuleDisabled: true,
children: [
{
id: 'minify-css-excludes',
@@ -96,14 +101,19 @@ const JetpackBoost = ( { methods, constants } ) => {
setModuleStatus={ setModuleStatus }
/>
- { fields.map( ( field ) => (
-
- ) ) }
+ { fields.map( ( field ) => {
+ if ( field.showOnModuleDisabled ) {
+ return (
+
+ );
+ }
+ return null;
+ } ) }
) : (
From 0e5d09a6a5061f686ae1f42f43ae77a7e39f6d51 Mon Sep 17 00:00:00 2001
From: Alessio Torrisi