Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/optimole-wp/assets/build/dashboard/index.asset.php
+++ b/optimole-wp/assets/build/dashboard/index.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('lodash', 'react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-notices', 'wp-primitives', 'wp-url'), 'version' => 'aaf59b15b30219371466');
+<?php return array('dependencies' => array('lodash', 'react', 'wp-api-fetch', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-notices', 'wp-primitives', 'wp-url'), 'version' => '449dee29a82da5305cdd');
--- a/optimole-wp/assets/build/media/admin-page.asset.php
+++ b/optimole-wp/assets/build/media/admin-page.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array(), 'version' => 'a3a71300f1d46094a647');
+<?php return array('dependencies' => array(), 'version' => 'b826645541c0aca78e79');
--- a/optimole-wp/assets/build/optimizer/optimizer.asset.php
+++ b/optimole-wp/assets/build/optimizer/optimizer.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array(), 'version' => 'e1e27deb29e70cdbf23e');
+<?php return array('dependencies' => array(), 'version' => '49251f1a0db7a33f6549');
--- a/optimole-wp/assets/build/video-player/editor/editor.asset.php
+++ b/optimole-wp/assets/build/video-player/editor/editor.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-primitives'), 'version' => 'a982de77e72e30e6e6bc');
+<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-primitives'), 'version' => '5a17eef04b672e8408e1');
--- a/optimole-wp/assets/build/video-player/frontend/frontend.asset.php
+++ b/optimole-wp/assets/build/video-player/frontend/frontend.asset.php
@@ -1 +1 @@
-<?php return array('dependencies' => array(), 'version' => '58f7bc1ffff894f1cb27');
+<?php return array('dependencies' => array(), 'version' => '6558c3fee9ff69c114d3');
--- a/optimole-wp/inc/admin.php
+++ b/optimole-wp/inc/admin.php
@@ -717,7 +717,7 @@
?>
</p>
<p style="margin: 1.5% 0;">
- <a href="<?php echo esc_url( tsdk_translate_link( self::get_upgrade_base_link() ) ); ?>"
+ <a href="<?php echo esc_url( self::get_upgrade_base_link() ); ?>"
target="_blank"
style="border-radius: 4px;padding: 9px 10px;border: 2px solid #FFF;color: white;text-decoration: none;"><?php _e( 'Check upgrade plans', 'optimole-wp' ); ?>
</a>
@@ -772,6 +772,8 @@
/**
* Build upgrade URL with current user's encoded email.
*
+ * The URL is already localized, so callers must not pass it through tsdk_translate_link() again.
+ *
* @return string Upgrade URL.
*/
public static function get_upgrade_base_link() {
@@ -787,6 +789,42 @@
}
/**
+ * Build a docs.optimole.com link with UTMs.
+ *
+ * Links go to the final docs URL: the old /article/ URLs redirect, and the redirect drops the UTMs.
+ *
+ * @param string $path Docs page path, e.g. 'wordpress-plugin/best-format'.
+ * @param string $campaign The feature the link explains (utm_campaign).
+ * @param string $medium Where the link is shown (utm_medium).
+ *
+ * @return string Docs URL with UTMs.
+ */
+ public static function docs_url( $path, $campaign, $medium ) {
+ return tsdk_utmify( 'https://docs.optimole.com/' . ltrim( $path, '/' ), $campaign, $medium );
+ }
+
+ /**
+ * Get docs links used by the dashboard app.
+ *
+ * @return array<string, string> Docs URLs with UTMs, by key.
+ */
+ public static function get_dashboard_docs_links() {
+ return [
+ 'home' => self::docs_url( '', 'documentation', 'help' ),
+ 'visitors_count' => self::docs_url( 'account/how-optimole-counts-the-number-of-visitors', 'visitors-count', 'help' ),
+ 'plan_limits' => self::docs_url( 'account/what-happens-if-i-exceed-plan-limits', 'plan-limits', 'help' ),
+ 'visitors_plan' => self::docs_url( 'account/visitors-based-plan', 'visitors-plan', 'help' ),
+ 'getting_started' => self::docs_url( 'wordpress-plugin/how-to-get-started-with-optimole-in-just-3-steps', 'getting-started', 'help' ),
+ 'webp' => self::docs_url( 'image-processing/how-optimole-can-serve-webp-images', 'webp', 'help' ),
+ 'watermarks' => self::docs_url( 'image-processing/adding-watermarks-to-your-images', 'watermark', 'help' ),
+ 'cloud_library' => self::docs_url( 'wordpress-plugin/cloud-library-browsing', 'cloud-library', 'help' ),
+ 'exclusions' => self::docs_url( 'wordpress-plugin/exclude-from-optimizing-or-lazy-loading', 'exclusions', 'help' ),
+ 'custom_integration' => self::docs_url( 'image-processing/how-to-use-the-custom-integration-in-optimole', 'custom-integration', 'help' ),
+ 'watermark_settings' => self::docs_url( 'image-processing/adding-watermarks-to-your-images', 'watermark', 'settings' ),
+ ];
+ }
+
+ /**
* Get contact URL.
*
* @return string Contact URL.
@@ -1536,6 +1574,7 @@
'optimoleDashBilling' => tsdk_translate_link( 'https://dashboard.optimole.com/settings/billing', 'query' ),
'optimoleDashMetrics' => tsdk_translate_link( tsdk_utmify( 'https://dashboard.optimole.com/metrics', 'wp-plugin', 'shortcut' ) ),
'offload_upgrade_url' => tsdk_translate_link( tsdk_utmify( 'https://optimole.com/pricing/', 'offload' ) ),
+ 'docs_links' => self::get_dashboard_docs_links(),
'days_since_install' => round( ( time() - get_option( 'optimole_wp_install', 0 ) ) / DAY_IN_SECONDS ),
'is_offload_media_available' => $is_offload_media_available,
'auto_connect' => $auto_connect,
@@ -1741,7 +1780,7 @@
'<span class="border-b border-0 border-white border-dashed text-promo-orange">' . $promo_code . '</span>',
'<span class="text-promo-orange uppercase">' . __( '25% discount', 'optimole-wp' ) . '</span>'
),
- 'cta_link' => esc_url_raw( tsdk_utmify( tsdk_translate_link( self::get_upgrade_base_link() ), 'bfcm', 'sidebarnotice' ) ),
+ 'cta_link' => esc_url_raw( tsdk_utmify( self::get_upgrade_base_link(), 'bfcm', 'sidebarnotice' ) ),
];
// The banner shares the SDK dismissal, which resets every year.
@@ -1864,13 +1903,13 @@
'<strong>',
'</strong>',
number_format_i18n( 2000 ),
- '<a href="https://docs.optimole.com/article/1134-how-optimole-counts-the-number-of-visitors" target="_blank">',
+ '<a href="' . esc_url( self::docs_url( 'account/how-optimole-counts-the-number-of-visitors', 'visitors-count', 'connect' ) ) . '" target="_blank">',
'</a>'
),
'account_needed_subtitle_3' => sprintf(
/* translators: 1 is the starting anchor tag for the docs link, 2 is the ending anchor tag. */
__( 'Need help? %1$sGetting Started with Optimole%2$s', 'optimole-wp' ),
- '<a target="_blank" href="https://docs.optimole.com/article/1173-how-to-get-started-with-optimole-in-just-3-steps">',
+ '<a target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/how-to-get-started-with-optimole-in-just-3-steps', 'getting-started', 'connect' ) ) . '">',
'</a>'
),
'account_needed_subtitle_2' => sprintf(
@@ -1914,7 +1953,7 @@
'notice_disabled_account' => sprintf(
/* translators: 1 anchor tag to pricing, 2 is the ending endin anchor tag, 3 is the bold tag start, 4 ending bold tag, 5 new line tag */
__( '%3$sYour account has been disabled due to exceeding quota.%4$s All images are being redirected to the original unoptimized URL. %5$sPlease %1$supgrade%2$s to re-activate the account.', 'optimole-wp' ),
- '<b><a href="' . esc_url( tsdk_translate_link( self::get_upgrade_base_link() ) ) . '">',
+ '<b><a href="' . esc_url( self::get_upgrade_base_link() ) . '">',
'</a></b>',
'<b>',
'</b>',
@@ -2014,7 +2053,7 @@
'best_format_desc' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'When enabled, Optimole chooses the best format for your images, balancing quality with speed. It tries options like AVIF and WebP to keep visuals sharp and pages fast, though uncached images may take a bit longer to process. %1$sLearn more%2$s.', 'optimole-wp' ),
- '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1942-best-format">',
+ '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/best-format', 'best-format', 'settings' ) ) . '">',
'</a>'
),
'add_filter' => __( 'Add filter', 'optimole-wp' ),
@@ -2024,7 +2063,7 @@
'cache_desc' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'Clears all Optimole’s cached resources (images, JS, CSS). Useful if you made changes to your images and don't see those applying on your site. %1$sLearn more%2$s', 'optimole-wp' ),
- '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1941-clear-cached-resources">',
+ '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/clear-cached-resources', 'clear-cache', 'settings' ) ) . '">',
'</a>'
),
'cache_title' => __( 'Clear Cached Resources', 'optimole-wp' ),
@@ -2032,7 +2071,7 @@
'image_size_notice' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'Use this option if you notice images are not cropped correctly after using Optimole. Add the affected image sizes here to automatically adjust and correct their cropping for optimal display. %1$sLearn more%2$s', 'optimole-wp' ),
- '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1947-add-new-image-crop-size">',
+ '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/add-new-image-crop-size', 'image-sizes', 'settings' ) ) . '">',
'</a>'
),
'clear_cache_images' => __( 'Clear cached images', 'optimole-wp' ),
@@ -2046,13 +2085,13 @@
'enable_avif_desc' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'Enable this to automatically convert images to the AVIF format on browsers that support it. This format provides quality images with reduced file sizes, and faster webpage loading. %1$sLearn more%2$s', 'optimole-wp' ),
- '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1943-avif-conversion">',
+ '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/best-format', 'avif', 'settings' ) ) . '">',
'</a>'
),
'enable_bg_lazyload_desc' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'Apply lazy loading to CSS background images. The toggle below enables it globally. The selector list is optional and only needed to extend coverage if certain elements are missed. %1$sLearn more%2$s', 'optimole-wp' ),
- '<a class="inline-block text-purple-gray underline" target="_blank" href="https://docs.optimole.com/article/1169-how-to-enable-the-background-lazyload-feature-for-certain-background-images">',
+ '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/how-to-enable-the-background-lazyload-feature-for-certain-background-images', 'bg-lazyload', 'settings' ) ) . '">',
'</a>'
),
'enable_bg_lazyload_title' => __( 'CSS Background Lazy Load', 'optimole-wp' ),
@@ -2061,26 +2100,26 @@
'enable_noscript_desc' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'Enables fallback images for browsers that can't handle JavaScript-based lazy loading or related features. Disabling it may resolve conflicts with other plugins or configurations and decrease HTML page size. %1$sLearn more%2$s', 'optimole-wp' ),
- '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1959-noscript-tag">',
+ '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/noscript-tag', 'noscript', 'settings' ) ) . '">',
'</a>'
),
// translators: %s is the name of the html tag (e.g: <noscript> );
'enable_noscript_title' => sprintf( __( 'Enable %s fallback', 'optimole-wp' ), '<custom_component/>' ),
'enable_gif_replace_title' => __( 'GIF to Video Conversion', 'optimole-wp' ),
'enable_offload_media_title' => __( 'Store Your Images in Optimole Cloud', 'optimole-wp' ),
- 'enable_offload_media_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'Free up space on your server by transferring your images to Optimole Cloud; you can transfer them back anytime. Once moved, the images will still be visible in the Media Library and can be used as before. %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1967-store-your-images-in-optimole-cloud">', '</a>' ),
+ 'enable_offload_media_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'Free up space on your server by transferring your images to Optimole Cloud; you can transfer them back anytime. Once moved, the images will still be visible in the Media Library and can be used as before. %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/store-your-images-in-optimole-cloud', 'offload-media', 'settings' ) ) . '">', '</a>' ),
'enable_cloud_images_title' => __( 'Unified Image Access', 'optimole-wp' ),
'enable_cloud_images_desc' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'Enable this setting to access all your Optimole images, including those from other websites connected to your Optimole account, directly on this site. They will be available for browsing in the Cloud Library tab. %1$sLearn more%2$s', 'optimole-wp' ),
- '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1323-cloud-library-browsing">',
+ '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/cloud-library-browsing', 'cloud-library', 'settings' ) ) . '">',
'</a>'
),
'enable_image_replace' => __( 'Enable Optimole Image Handling', 'optimole-wp' ),
'enable_lazyload_placeholder_desc' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'Enable this to use a generic transparent placeholder instead of the blurry images during lazy loading. %1$sLearn more%2$s', 'optimole-wp' ),
- '<a class="inline-block underline text-white" target=”_blank” href="https://docs.optimole.com/article/1192-lazy-load-generic-placeholder">',
+ '<a class="inline-block underline text-white" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/lazy-load-generic-placeholder', 'lazyload-placeholder', 'settings' ) ) . '">',
'</a>'
),
@@ -2088,7 +2127,7 @@
'lazyload_behaviour_desc' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'Choose how Optimole will handle lazy loading for images on your website. %1$sLearn more%2$s', 'optimole-wp' ),
- '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1958-lazy-loading-behaviour">',
+ '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/bypass-lazy-load-for-first-images', 'lazyload-behaviour', 'settings' ) ) . '">',
'</a>'
),
'lazyload_behaviour_all' => __( 'Lazy Load All Images', 'optimole-wp' ),
@@ -2101,28 +2140,28 @@
'enable_network_opt_desc' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'When enabled, Optimole will automatically reduce the image quality when it detects a slower network, making your images load faster on low-speed internet connections. %1$sLearn more%2$s', 'optimole-wp' ),
- '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1945-network-based-optimizations">',
+ '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/network-based-optimizations', 'network-optimization', 'settings' ) ) . '">',
'</a>'
),
'enable_network_opt_title' => __( 'Network-based Optimizations', 'optimole-wp' ),
'enable_resize_smart_desc' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'When enabled, Optimole automatically detects the most interesting or important part of your images. When pictures are resized or cropped, this feature ensures the focus stays on the most interesting part of the picture. %1$sLearn more%2$s', 'optimole-wp' ),
- '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1871-how-to-use-the-smart-cropping-in-optimole">',
+ '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/how-to-use-the-smart-cropping-in-optimole', 'smart-cropping', 'settings' ) ) . '">',
'</a>'
),
'enable_resize_smart_title' => __( 'Smart Cropping', 'optimole-wp' ),
'enable_retina_desc' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'Optimizes images for Retina (high-DPI) screens for sharper results. Always enabled for images under 150px wide. %1$sLearn more%2$s', 'optimole-wp' ),
- '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1391-what-is-a-retina-image">',
+ '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/what-is-a-retina-image', 'retina', 'settings' ) ) . '">',
'</a>'
),
'enable_retina_title' => __( 'Retina Quality', 'optimole-wp' ),
'enable_limit_dimensions_desc' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'Define the max width or height limits for images on your website. Larger images will be automatically adjusted to fit within these parameters while preserving their original aspect ratio. %1$sLearn more%2$s', 'optimole-wp' ),
- '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1946-limit-image-sizes">',
+ '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/limit-image-sizes', 'limit-dimensions', 'settings' ) ) . '">',
'</a>'
),
'enable_limit_dimensions_title' => __( 'Limit Image Sizes', 'optimole-wp' ),
@@ -2136,7 +2175,7 @@
'enable_badge_description' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'Get 20.000 more visits for free by enabling the Optimole badge on your websites. %1$sLearn more%2$s', 'optimole-wp' ),
- '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1940-optimole-badge">',
+ '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/optimole-badge', 'badge', 'settings' ) ) . '">',
'</a>'
),
'image_sizes_title' => __( 'Your cropped image sizes', 'optimole-wp' ),
@@ -2161,14 +2200,14 @@
'exclude_desc_optimize' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'Here you can define exceptions, in case you don't want some images to be optimised. %1$sLearn more%2$s', 'optimole-wp' ),
- '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1191-exclude-from-optimizing-or-lazy-loading">',
+ '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/exclude-from-optimizing-or-lazy-loading', 'exclusions', 'settings' ) ) . '">',
'</a>'
),
'exclude_title_lazyload' => __( 'Don't lazy-load images if', 'optimole-wp' ),
'exclude_desc_lazyload' => sprintf(
/* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */
__( 'Define exceptions, in case you don't want the lazy-load to be active on certain images. %1$sLearn more%2$s', 'optimole-wp' ),
- '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1191-exclude-from-optimizing-or-lazy-loading">',
+ '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/exclude-from-optimizing-or-lazy-loading', 'exclusions', 'settings' ) ) . '">',
'</a>'
),
'exclude_title_optimize' => __( 'Don't optimize and don't lazy-load images if', 'optimole-wp' ),
@@ -2191,7 +2230,7 @@
'exclude_first' => __( 'Exclude first', 'optimole-wp' ),
'images' => __( 'images', 'optimole-wp' ),
'exclude_first_images_title' => __( 'Bypass Lazy Load for First Images', 'optimole-wp' ),
- 'exclude_first_images_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'Indicate how many images at the top of each page should bypass lazy loading, ensuring they’re instantly visible. Enter 0 to not exclude any images from the lazy loading process. %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1948-bypass-lazy-load-for-first-images">', '</a>' ),
+ 'exclude_first_images_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'Indicate how many images at the top of each page should bypass lazy loading, ensuring they’re instantly visible. Enter 0 to not exclude any images from the lazy loading process. %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/bypass-lazy-load-for-first-images', 'first-images', 'settings' ) ) . '">', '</a>' ),
'filter_class' => __( 'Image class', 'optimole-wp' ),
'filter_ext' => __( 'Image extension', 'optimole-wp' ),
'filter_filename' => __( 'Image filename', 'optimole-wp' ),
@@ -2200,7 +2239,7 @@
'filter_operator_is' => __( 'is', 'optimole-wp' ),
'filter_url' => __( 'Page URL', 'optimole-wp' ),
'filter_helper' => __( 'For homepage use `home` keyword.', 'optimole-wp' ),
- 'gif_replacer_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'Enable this to automatically convert GIF images to Video files (MP4 and WebM). %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1171-gif-to-video-conversion">', '</a>' ),
+ 'gif_replacer_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'Enable this to automatically convert GIF images to Video files (MP4 and WebM). %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/settings-reference', 'gif-to-video', 'settings' ) ) . '">', '</a>' ),
'height_field' => __( 'Height', 'optimole-wp' ),
'add_image_size_button' => __( 'Add size', 'optimole-wp' ),
'add_image_size_desc' => __( 'Add New Image Crop Size', 'optimole-wp' ),
@@ -2209,7 +2248,7 @@
'high_q_title' => __( 'High', 'optimole-wp' ),
'image_1_label' => __( 'Original', 'optimole-wp' ),
'image_2_label' => __( 'Optimized', 'optimole-wp' ),
- 'lazyload_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'Images load only when they're about to enter the viewport. %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1948-bypass-lazy-load-for-first-images">', '</a>' ),
+ 'lazyload_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'Images load only when they're about to enter the viewport. %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/bypass-lazy-load-for-first-images', 'lazyload', 'settings' ) ) . '">', '</a>' ),
'filter_length_error' => __( 'The filter should be at least 3 characters long.', 'optimole-wp' ),
'scale_desc' => __( 'Automatically resize the images based on device and viewport', 'optimole-wp' ),
'low_q_title' => __( 'Low', 'optimole-wp' ),
@@ -2217,14 +2256,14 @@
'no_images_found' => __( 'You dont have any images in your Media Library. Add one and check how the Optimole will perform.', 'optimole-wp' ),
'native_desc' => __( 'Uses the browser's built-in lazy loading feature. Enabling this will disable the auto scale.', 'optimole-wp' ),
'option_saved' => __( 'Option saved.', 'optimole-wp' ),
- 'ml_quality_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'Optimole ML algorithms will predict the optimal image quality to get the smallest possible size with minimum perceived quality losses. When disabled, you can control the quality manually. %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1016-what-is-the-difference-between-the-auto-high-medium-low-compression-levels">', '</a>' ),
+ 'ml_quality_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'Optimole ML algorithms will predict the optimal image quality to get the smallest possible size with minimum perceived quality losses. When disabled, you can control the quality manually. %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/what-is-the-difference-between-the-auto-high-medium-low-compression-levels', 'compression', 'settings' ) ) . '">', '</a>' ),
'quality_desc' => __( 'Lower image quality might boost your loading speed by lowering the size. However, the low image quality may negatively impact the visual appearance of the images. Try experimenting with the setting, then click the View sample image link to see what option works best for you.', 'optimole-wp' ),
'quality_selected_value' => __( 'Selected value', 'optimole-wp' ),
'quality_slider_desc' => __( 'See one sample image which will help you choose the right quality of the compression.', 'optimole-wp' ),
'quality_title' => __( 'Auto Quality Powered by ML(Machine Learning)', 'optimole-wp' ),
'strip_meta_title' => __( 'Strip Image Metadata', 'optimole-wp' ),
- 'strip_meta_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'Removes extra information from images, including EXIF and IPTC data (like camera settings and copyright info). This makes the pictures lighter and helps your website load faster. %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1944-strip-image-metadata">', '</a>' ),
- 'replacer_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'When enabled, Optimole will manage, optimize, and serve all the images on your website. If disabled, optimization, lazy loading, and other features will no longer be available. %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1218-how-to-turn-off-image-replacement-in-optimoles-wordpress-plugin">', '</a>' ),
+ 'strip_meta_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'Removes extra information from images, including EXIF and IPTC data (like camera settings and copyright info). This makes the pictures lighter and helps your website load faster. %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/strip-image-metadata', 'strip-metadata', 'settings' ) ) . '">', '</a>' ),
+ 'replacer_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'When enabled, Optimole will manage, optimize, and serve all the images on your website. If disabled, optimization, lazy loading, and other features will no longer be available. %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/how-to-turn-off-image-replacement-in-optimoles-wordpress-plugin', 'image-replacement', 'settings' ) ) . '">', '</a>' ),
'sample_image_loading' => __( 'Loading a sample image.', 'optimole-wp' ),
'save_changes' => __( 'Save changes', 'optimole-wp' ),
'show' => __( 'Show', 'optimole-wp' ),
@@ -2262,7 +2301,7 @@
'width_field' => __( 'Width', 'optimole-wp' ),
'crop' => __( 'crop', 'optimole-wp' ),
'toggle_cdn' => __( 'Serve CSS & JS Through Optimole', 'optimole-wp' ),
- 'cdn_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'When enabled, Optimole will optimize your CSS and JS files and, if they contain images, the images as well, then deliver them via the CDN for faster webpage loading. %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target=”_blank” href="https://docs.optimole.com/article/1966-serve-css-js-through-optimole">', '</a>' ),
+ 'cdn_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'When enabled, Optimole will optimize your CSS and JS files and, if they contain images, the images as well, then deliver them via the CDN for faster webpage loading. %1$sLearn more%2$s', 'optimole-wp' ), '<a class="inline-block text-purple-gray underline" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/serve-css-js-through-optimole', 'css-js', 'settings' ) ) . '">', '</a>' ),
'enable_css_minify_title' => __( 'Minify CSS files', 'optimole-wp' ),
'css_minify_desc' => __( 'Once Optimole will serve your CSS files, it will also minify the files and serve them via CDN.', 'optimole-wp' ),
'enable_js_minify_title' => __( 'Minify JS files', 'optimole-wp' ),
@@ -2294,7 +2333,7 @@
'sync_media_error_desc' => __( 'You can try again to offload the rest of the images to Optimole.', 'optimole-wp' ),
'offload_disable_warning_title' => __( 'Important! Please read carefully', 'optimole-wp' ),
'offload_disable_warning_desc' => __( 'If you turn off this option, you will not be able to see the images in the Media Library without restoring the images first. Do you want to restore the images to your site upon turning off the option?', 'optimole-wp' ),
- 'offload_enable_info_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'You are not required to use the offload functionality for the plugin to work, use it if you want to save on hosting space. %1$s More details%2$s', 'optimole-wp' ), '<a style="white-space: nowrap;" target=”_blank” href="https://docs.optimole.com/article/1323-cloud-library-browsing">', '<span style="font-size:15px; margin-top:2px;" class="dashicons dashicons-external"></span></a>' ),
+ 'offload_enable_info_desc' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'You are not required to use the offload functionality for the plugin to work, use it if you want to save on hosting space. %1$s More details%2$s', 'optimole-wp' ), '<a style="white-space: nowrap;" target="_blank" href="' . esc_url( self::docs_url( 'wordpress-plugin/cloud-library-browsing', 'offload-info', 'settings' ) ) . '">', '<span style="font-size:15px; margin-top:2px;" class="dashicons dashicons-external"></span></a>' ),
'offload_conflicts_part_1' => __( 'We have detected the following plugins that conflict with the offload features:', 'optimole-wp' ),
'offload_conflicts_part_2' => __( 'Please disable those plugins temporarily in order for Optimole to rollback the images to your site.', 'optimole-wp' ),
'offloading_success' => sprintf( /* translators: 1 is the starting bold tag, 2 is the ending bold tag */ __( '%s Your images are now stored in Optimole Cloud.', 'optimole-wp' ), '<strong>' . __( 'Transfer Complete.', 'optimole-wp' ) . '</strong>' ),
@@ -2329,7 +2368,7 @@
'cloud_library_btn_text' => __( 'Go to Cloud Library', 'optimole-wp' ),
'cloud_library_btn_link' => add_query_arg( 'page', 'optimole-dam', admin_url( 'admin.php' ) ),
'exceed_plan_quota_notice_title' => __( 'Your site has already reached over 50% of your monthly visits limit within just two weeks.', 'optimole-wp' ),
- 'exceed_plan_quota_notice_description' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'Based on this trend, you are likely to exceed your free quota before the month ends. To avoid any disruption in service, we strongly recommend %1$supgrading%2$s your plan or waiting until your traffic stabilizes before offloading your images. Do you still wish to proceed?', 'optimole-wp' ), '<a style="white-space: nowrap;" target=”_blank” href="https://dashboard.optimole.com/settings/billing/">', '</a>' ),
+ 'exceed_plan_quota_notice_description' => sprintf( /* translators: 1 is the starting anchor tag, 2 is the ending anchor tag */ __( 'Based on this trend, you are likely to exceed your free quota before the month ends. To avoid any disruption in service, we strongly recommend %1$supgrading%2$s your plan or waiting until your traffic stabilizes before offloading your images. Do you still wish to proceed?', 'optimole-wp' ), '<a style="white-space: nowrap;" target="_blank" href="https://dashboard.optimole.com/settings/billing/">', '</a>' ),
'exceed_plan_quota_notice_start_action' => __( 'Yes, Transfer to Optimole Cloud', 'optimole-wp' ),
'exceed_plan_quota_notice_secondary_action' => __( 'No, keep images on my website', 'optimole-wp' ),
'plan_update_notice_title' => __( 'Plan Update', 'optimole-wp' ),
@@ -2450,7 +2489,7 @@
'optimization_tips' => sprintf(
/* translators: 1 is the opening anchor tag, 2 is the closing anchor tag */
__( '%1$sView all optimization tips%2$s', 'optimole-wp' ),
- '<a class="flex justify-center items-center font-semibold" href="https://docs.optimole.com/article/2238-optimization-tips" target="_blank"> ',
+ '<a class="flex justify-center items-center font-semibold" href="' . esc_url( self::docs_url( 'image-processing/optimization-tips', 'optimization-tips', 'dashboard' ) ) . '" target="_blank"> ',
'<span style="text-decoration:none; font-size:15px; margin-top:2px;" class="dashicons dashicons-external"></span></a>'
),
'contact_support' => [
--- a/optimole-wp/inc/api.php
+++ b/optimole-wp/inc/api.php
@@ -192,7 +192,7 @@
if ( intval( $response['code'] ) !== 200 ) {
if ( isset( $response['error'] ) && $response['error'] === 'domain_not_accessible' ) {
- return new WP_Error( 'domain_not_accessible', sprintf( /* translators: 1 start of the italic tag, 2 is the end of italic tag, 3 is starting anchor tag, 4 is the ending anchor tag. */ __( 'It seems Optimole is having trouble reaching your website. This issue often occurs if your website is private, local, or protected by a firewall. But don't stress – it's an easy fix! Ensure your website is live and accessible to the public. If a firewall is in place, just tweak the settings to allow the %1$sOptimole(1.0)%2$s user agent access to your website. %3$sLearn More%4$s', 'optimole-wp' ), '<i>', '</i>', '<a href="https://docs.optimole.com/article/1976-resolving-optimole-access-to-your-website" target="_blank">', '</a>' ) );
+ return new WP_Error( 'domain_not_accessible', sprintf( /* translators: 1 start of the italic tag, 2 is the end of italic tag, 3 is starting anchor tag, 4 is the ending anchor tag. */ __( 'It seems Optimole is having trouble reaching your website. This issue often occurs if your website is private, local, or protected by a firewall. But don't stress – it's an easy fix! Ensure your website is live and accessible to the public. If a firewall is in place, just tweak the settings to allow the %1$sOptimole(1.0)%2$s user agent access to your website. %3$sLearn More%4$s', 'optimole-wp' ), '<i>', '</i>', '<a href="' . esc_url( Optml_Admin::docs_url( 'wordpress-plugin/resolving-optimole-access-to-your-website', 'domain-access', 'connect' ) ) . '" target="_blank">', '</a>' ) );
}
if ( $path === 'optml/v2/account/complete_register_remote' && isset( $response['error'] ) ) {
if ( strpos( $response['error'], 'This email address is already registered.' ) !== false ) {
@@ -246,7 +246,6 @@
'method' => $method,
'timeout' => 45,
'user-agent' => 'Optimle WP (v' . OPTML_VERSION . ') ',
- 'sslverify' => false,
'headers' => $headers,
];
if ( $method !== 'GET' ) {
@@ -297,7 +296,6 @@
],
'timeout' => 60,
'blocking' => true,
- 'sslverify' => false,
'data_format' => 'body',
];
return wp_remote_post( $this->onboard_api_root, $options );
@@ -405,7 +403,6 @@
'headers' => [ 'Content-Type' => 'application/json' ],
'timeout' => 15,
'blocking' => true,
- 'sslverify' => false,
'data_format' => 'body',
'body' => [
'error_body' => wp_json_encode( $body ),
--- a/optimole-wp/inc/dam.php
+++ b/optimole-wp/inc/dam.php
@@ -429,12 +429,12 @@
display: none !important;
}
</style>
- <iframe id="om-dam" style="display: none;" src="<?php echo( $this->build_iframe_url() ); ?>" allow="clipboard-read; clipboard-write"></iframe>
<div class="om-dam-loader">
<img src="<?php echo esc_url( OPTML_URL . 'assets/img/logo.png' ); ?>" alt="Optimole Logo"
class="om-dam-logo">
<p><?php echo esc_html__( 'Loading', 'optimole-wp' ); ?>...</p>
</div>
+ <iframe id="om-dam" style="display: none;" src="<?php echo( $this->build_iframe_url() ); ?>" allow="clipboard-read; clipboard-write"></iframe>
<?php
}
@@ -521,7 +521,7 @@
OPTML_URL . 'assets/build/media/admin-page.js',
$asset_file['dependencies'],
$asset_file['version'],
- true
+ false
);
wp_localize_script(
@@ -704,7 +704,7 @@
$replacement = self::URL_DAM_FLAG . $replacement;
}
- return preg_replace( '//w:(.*)/h:(.*)/q:/', $replacement, $subject );
+ return preg_replace( '//w:(.*)/h:(.*)/q:/', $this->to_literal_replacement( $replacement ), $subject );
}
/**
--- a/optimole-wp/inc/lazyload_replacer.php
+++ b/optimole-wp/inc/lazyload_replacer.php
@@ -31,6 +31,26 @@
const SVG_PLACEHOLDER = 'data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%20#width#%20#height#%22%20width%3D%22#width#%22%20height%3D%22#height#%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%22#width#%22%20height%3D%22#height#%22%20fill%3D%22#fill#%22%2F%3E%3C%2Fsvg%3E';
/**
+ * What precedes a start tag attribute: whitespace or, as browsers allow, directly a quoted value.
+ */
+ private const TAG_ATTRIBUTE_SEPARATOR = '(?:s+|(?<=["']))';
+ /**
+ * One start tag attribute with its separator.
+ *
+ * A quoted value is matched whole, so text inside it is never read as an attribute. An iframe whose
+ * attribute value starts with a backslash is not matched, so JSON-escaped iframe markup is left as written.
+ */
+ private const TAG_ATTRIBUTE = self::TAG_ATTRIBUTE_SEPARATOR . '[^s"'>/=]+(?:s*=s*(?:"[^"]*"|'[^']*'|[^s"'>\\][^s>]*))?';
+ /**
+ * An unquoted image tag attribute value. It does not start with a backslash, which begins an escape in
+ * JSON-encoded markup.
+ */
+ private const IMAGE_TAG_UNQUOTED_VALUE = '[^s"'>\\][^s>]*';
+ /**
+ * One image tag attribute with its separator, whose value may be JSON-escaped, with quotes written as " or '.
+ */
+ private const IMAGE_TAG_ATTRIBUTE = self::TAG_ATTRIBUTE_SEPARATOR . '[^s"'>/=\\]+(?:s*=s*(?:"[^"]*"|'[^']*'|\\"[^"]*?\\"|\\'[^']*?\\'|' . self::IMAGE_TAG_UNQUOTED_VALUE . '))?';
+ /**
* If frame lazyload is present on page.
*
* @var bool Whether or not at least one iframe has been lazyloaded.
@@ -271,22 +291,32 @@
);
}
+ $loading = [];
+ // Most tags do not hold the word at all, and need no pattern.
+ $has_loading = stripos( $new_tag, 'loading' ) !== false && preg_match( $this->image_attribute_pattern( 'loading' ), $new_tag, $loading ) === 1;
+ // Only a quoted value that is not JSON-escaped is changed; any other loading attribute is kept as written.
+ $after_loading = ( $loading[3] ?? '' ) !== '' ? substr( $new_tag, strlen( $loading[0] ) ) : null;
+
if ( self::instance()->settings->get( 'native_lazyload' ) === 'enabled' ) {
- // First check if loading attribute already exists
- if ( strpos( $new_tag, 'loading=' ) !== false ) {
- // Replace existing loading attribute with lazy
- $loading_attr = $is_slashed ? 'loading="lazy"' : 'loading="lazy"';
- $new_tag = preg_replace( '/loading=(["'])[^"']*1/i', $loading_attr, $new_tag );
- } else {
+ if ( ! $has_loading ) {
// No loading attribute exists, add it after <img
$loading_attr = $is_slashed ? ' loading="lazy"' : ' loading="lazy"';
- $new_tag = preg_replace( '/<img/i', '<img' . $loading_attr, $new_tag, 1 );
+
+ return preg_replace( '/<img/i', '<img' . $loading_attr, $new_tag, 1 );
}
- return $new_tag;
+ if ( null === $after_loading ) {
+ return $new_tag;
+ }
+ // The value keeps the quote it was written with, which stays valid where the markup is JSON-encoded.
+ $quote = $loading[3][0];
+
+ return $loading[1] . $loading[2] . 'loading=' . $quote . 'lazy' . $quote . $after_loading;
}
- // we remove the loading attribute if it exists with strpos
- $new_tag = preg_replace( '/loading=(["'])[^"']*1/i', '', $new_tag );
+ // we remove the loading attribute if it exists
+ if ( null !== $after_loading ) {
+ $new_tag = $loading[1] . $loading[2] . $after_loading;
+ }
$should_ignore_rescale = ! $this->is_valid_mimetype_from_url( $original_url, [ 'gif' => true, 'svg' => true ] );
@@ -343,16 +373,27 @@
'/<img/im',
],
[
- "$1$low_url",
- '<img' . $opt_src,
+ '$1' . $this->to_literal_replacement( $low_url ),
+ '<img' . $this->to_literal_replacement( $opt_src ),
],
$new_tag,
1
);
// We remove srcset and sizes attributes since our lazyload does not need them.
- $pattern = '/s+(?:srcset|sizes)=("[^"]*"|'[^']*'|\\"[^\\"]*\\")/i';
- $new_tag = preg_replace( $pattern, '', $new_tag );
+ foreach ( [ 'srcset', 'sizes' ] as $attribute ) {
+ if ( stripos( $new_tag, $attribute ) !== false ) {
+ $new_tag = preg_replace_callback(
+ $this->image_attribute_pattern( $attribute ),
+ static function ( $attribute_match ) {
+ // An unquoted value is left as written.
+ return isset( $attribute_match[3] ) ? $attribute_match[1] : $attribute_match[0];
+ },
+ $new_tag,
+ 1
+ ) ?? $new_tag;
+ }
+ }
// We keep this for srcset lazyload compatibility that might break our mechanism.
$new_tag = str_replace( 'srcset=', 'old-srcset=', $new_tag );
@@ -364,6 +405,27 @@
return $new_tag . '<noscript>' . $no_script_tag . '</noscript>';
}
/**
+ * Build the pattern that finds an attribute of an image tag.
+ *
+ * Every attribute before it is matched whole, so the same text inside another attribute's value is not taken
+ * for the attribute. Group 1 is the tag up to the attribute's separator and group 2 the separator. Group 3 is
+ * the value when it is quoted, and group 4 when it is JSON-escaped: double-quoted with no backslash inside.
+ * Neither is set for an unquoted value.
+ *
+ * @param string $name Attribute name.
+ *
+ * @return string The pattern.
+ */
+ private function image_attribute_pattern( string $name ): string {
+ static $patterns = [];
+
+ if ( ! isset( $patterns[ $name ] ) ) {
+ $patterns[ $name ] = '#^((?:<noscripts*>s*)?<img(?>(?:(?!s*' . $name . 's*=)' . self::IMAGE_TAG_ATTRIBUTE . ')*))(' . self::TAG_ATTRIBUTE_SEPARATOR . ')' . $name . 's*=s*(?:("[^"]*"|'[^']*')|(\\"[^\\"]*\\")|' . self::IMAGE_TAG_UNQUOTED_VALUE . ')#i';
+ }
+
+ return $patterns[ $name ];
+ }
+ /**
* Replaces video embeds with lazyload embeds.
*
* @param string $content Html page content.
@@ -374,14 +436,16 @@
$video_tags = [];
$iframes = [];
$videos = [];
- preg_match_all( '#(?:<noscripts*>s*)?<iframe(.*?)></iframe>(?:s*</noscripts*>)?#is', $content, $iframes );
+ // Only iframes with no fallback content; one with fallback text is left as written.
+ preg_match_all( '#(?:<noscripts*>s*)?<iframe(?>(?:' . self::TAG_ATTRIBUTE . ')*)s*/?></iframe>(?:s*</noscripts*>)?#i', $content, $iframes );
preg_match_all( '#(?:<noscripts*>s*)?<video(.*?)>.*?</video>(?:s*</noscripts*>)?#is', $content, $videos );
+ $iframe_count = count( $iframes[0] );
$video_tags = array_merge( $iframes[0], $videos[0] );
$search = [];
$replace = [];
- foreach ( $video_tags as $video_tag ) {
+ foreach ( $video_tags as $index => $video_tag ) {
if ( ! $this->should_lazyload_iframe( $video_tag ) ) {
continue;
@@ -389,23 +453,12 @@
if ( preg_match( "/ data-opt-src=['"]/is", $video_tag ) ) {
continue;
}
- $should_add_noscript = true;
$original_tag = $video_tag;
- // replace the src and add the data-opt-src attribute
- if ( strpos( $video_tag, 'iframe' ) !== false ) {
- $video_tag = preg_replace( '/iframe(.*?)src=/is', 'iframe$1 src="about:blank" data-opt-src=', $video_tag );
- } elseif ( strpos( $video_tag, 'video' ) !== false ) {
- if ( strpos( $video_tag, 'source' ) !== false ) {
- if ( strpos( $video_tag, 'preload' ) === false ) {
- $video_tag = preg_replace( '/video(.*?)>/is', 'video$1 preload="metadata">', $video_tag, 1 );
- $should_add_noscript = false;
- } else {
- continue;
- }
- } else {
- $video_tag = preg_replace( '/video(.*?)src=/is', 'video$1 data-opt-src=', $video_tag );
- }
+ $lazyloaded = $this->lazyload_media_element( $video_tag, $index < $iframe_count );
+ if ( null === $lazyloaded ) {
+ continue;
}
+ list( $video_tag, $should_add_noscript ) = $lazyloaded;
if ( $this->should_add_noscript( $video_tag ) && $should_add_noscript ) {
$video_tag .= '<noscript>' . $original_tag . '</noscript>';
}
@@ -420,6 +473,46 @@
}
/**
+ * Move the src of a matched iframe or video to data-opt-src, or ask a sourced video to preload metadata only.
+ *
+ * @param string $element The iframe or video element.
+ * @param bool $is_iframe Whether the element was matched as an iframe.
+ *
+ * @return array{0: string, 1: bool}|null The element and whether it gets a noscript copy, or null to leave it untouched.
+ */
+ private function lazyload_media_element( string $element, bool $is_iframe ): ?array {
+ if ( $is_iframe && strpos( $element, 'iframe' ) !== false ) {
+ return [ $this->replace_start_tag_src( $element, 'iframe', ' src="about:blank" data-opt-src' ), true ];
+ }
+ if ( $is_iframe || strpos( $element, 'video' ) === false ) {
+ return [ $element, true ];
+ }
+ if ( strpos( $element, 'source' ) === false ) {
+ return [ $this->replace_start_tag_src( $element, 'video', ' data-opt-src' ), true ];
+ }
+ if ( strpos( $element, 'preload' ) !== false ) {
+ return null;
+ }
+
+ return [ preg_replace( '#^((?:<noscripts*>s*)?<video(?>(?:' . self::TAG_ATTRIBUTE . ')*)s*/?)>#i', '$1 preload="metadata">', $element, 1 ) ?? $element, false ];
+ }
+
+ /**
+ * Replace the name of the src attribute in the element's start tag.
+ *
+ * @param string $element Element markup, starting with its start tag.
+ * @param string $tag_name The element's tag name.
+ * @param string $replacement Markup written in place of the attribute name, before its `=`.
+ *
+ * @return string The element, unchanged when its start tag has no src attribute.
+ */
+ private function replace_start_tag_src( string $element, string $tag_name, string $replacement ): string {
+ $pattern = '#^((?:<noscripts*>s*)?<' . $tag_name . '(?>(?:(?!s*srcs*=)' . self::TAG_ATTRIBUTE . ')*)' . self::TAG_ATTRIBUTE_SEPARATOR . ')src(?=s*=)#i';
+
+ return preg_replace( $pattern, '$1' . $replacement, $element, 1 ) ?? $element;
+ }
+
+ /**
* Check if the lazyload is allowed for this url.
*
* @param string $url Url.
--- a/optimole-wp/inc/logger.php
+++ b/optimole-wp/inc/logger.php
@@ -11,6 +11,11 @@
const LOG_SEPARATOR = '==========';
/**
+ * The option that holds the random part of this site's log file names.
+ */
+ const FILE_TOKEN_OPTION = 'optml_log_file_token';
+
+ /**
* Upload directory.
*
* @var string
@@ -18,9 +23,9 @@
private $upload_dir;
/**
- * Log filenames.
+ * The log types, with the fixed file name each was stored under before file names carried a token.
*
- * @var array
+ * @var array<string, string>
*/
private $log_filenames = [
self::LOG_TYPE_OFFLOAD => 'offload.log',
@@ -28,6 +33,13 @@
];
/**
+ * The random part of this site's log file names.
+ *
+ * @var string
+ */
+ private $file_token;
+
+ /**
* The single instance of the class.
*
* @var Optml_Logger
@@ -56,6 +68,9 @@
private function __construct() {
$upload_dir = wp_upload_dir();
$this->upload_dir = trailingslashit( $upload_dir['basedir'] ) . 'optimole-logs/';
+ // Read with the directory, so both belong to the same site of a network for as long as the logger lives.
+ $stored_token = get_option( self::FILE_TOKEN_OPTION );
+ $this->file_token = is_string( $stored_token ) && '' !== $stored_token ? $stored_token : $this->create_file_token();
if ( ! file_exists( $this->upload_dir ) ) {
if ( false === wp_mkdir_p( $this->upload_dir ) ) {
@@ -64,9 +79,72 @@
}
add_action( 'wp_ajax_optml_fetch_logs', [ $this, 'fetch_logs_ajax_handler' ] );
+ add_action( 'admin_init', [ $this, 'protect_log_files' ] );
+
+ // The site just got its token: logs still stored under the earlier fixed names are moved on this request.
+ if ( $this->file_token !== $stored_token ) {
+ $this->protect_log_files();
+ }
}
/**
+ * Create and store the random part of this site's log file names.
+ *
+ * @return string
+ */
+ private function create_file_token() {
+ $token = bin2hex( random_bytes( 16 ) );
+ update_option( self::FILE_TOKEN_OPTION, $token );
+
+ return $token;
+ }
+ /**
+ * Get the path of a log file.
+ *
+ * The file name carries a random token stored for this site, so the log cannot be requested by guessing its
+ * URL. A log written under the earlier fixed name is moved to the new one.
+ *
+ * @param string $type Type of log (offload/rollback).
+ *
+ * @return string Absolute path of the log file.
+ */
+ private function get_file_path( $type ) {
+ $legacy_path = $this->upload_dir . $this->log_filenames[ $type ];
+ $file_path = $this->upload_dir . $type . '-' . $this->file_token . '.log';
+
+ // A log that cannot be moved is deleted, so nothing stays under the old name.
+ if ( file_exists( $legacy_path ) && ( file_exists( $file_path ) || ! @rename( $legacy_path, $file_path ) ) ) {
+ wp_delete_file( $legacy_path );
+ }
+
+ return $file_path;
+ }
+ /**
+ * Move the logs written under the earlier fixed names, and add the files that keep a web server from listing
+ * or serving the log directory. A file that already exists is kept as it is.
+ *
+ * @return void
+ */
+ public function protect_log_files() {
+ if ( ! $this->has_permission() ) {
+ return;
+ }
+
+ foreach ( array_keys( $this->log_filenames ) as $type ) {
+ $this->get_file_path( $type );
+ }
+
+ $files = [
+ 'index.html' => '',
+ '.htaccess' => "<IfModule mod_authz_core.c>ntRequire all deniedn</IfModule>n<IfModule !mod_authz_core.c>ntDeny from alln</IfModule>n",
+ ];
+ foreach ( $files as $name => $content ) {
+ if ( ! file_exists( $this->upload_dir . $name ) ) {
+ file_put_contents( $this->upload_dir . $name, $content );
+ }
+ }
+ }
+ /**
* Adds a log entry.
*
* @param string $type Type of log (offload/rollback).
@@ -84,7 +162,7 @@
return false;
}
- $file_path = $this->upload_dir . $this->log_filenames[ $type ];
+ $file_path = $this->get_file_path( $type );
$handle = @fopen( $file_path, 'a' );
if ( $handle === false ) {
@@ -110,9 +188,9 @@
return false;
}
- $file_path = $this->upload_dir . $this->log_filenames[ $type ];
+ $file_path = $this->get_file_path( $type );
- if ( $this->has_logs( $type ) ) {
+ if ( file_exists( $file_path ) ) {
$data = $this->tailCustom( $file_path, $lines, true, $separator );
return nl2br( esc_textarea( $data ) );
}
@@ -131,7 +209,7 @@
return false;
}
- $file_path = $this->upload_dir . $this->log_filenames[ $type ];
+ $file_path = $this->get_file_path( $type );
return file_exists( $file_path );
}
@@ -215,8 +293,8 @@
*/
public function fetch_logs_ajax_handler() {
// Check for nonce security
- $nonce = $_REQUEST['nonce'];
- if ( ! wp_verify_nonce( $nonce, 'wp_rest' ) ) {
+ $nonce = isset( $_REQUEST['nonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['nonce'] ) ) : '';
+ if ( ! wp_verify_nonce( $nonce, 'wp_rest' ) || ! current_user_can( 'manage_options' ) ) {
wp_die( __( 'Security check failed', 'optimole-wp' ) );
}
--- a/optimole-wp/inc/main.php
+++ b/optimole-wp/inc/main.php
@@ -108,6 +108,7 @@
add_filter( 'optml_register_conflicts', [ __CLASS__, 'register_conflicts' ] );
add_filter( 'optimole_wp_logger_data', [ __CLASS__, 'add_settings' ] );
add_filter( 'optimole_wp_ai_connect_metadata', [ __CLASS__, 'add_ai_connect_metadata' ] );
+ add_filter( 'optimole_wp_support_hub_metadata', [ __CLASS__, 'add_support_hub_metadata' ] );
self::$_instance = new self();
self::$_instance->manager = Optml_Manager::instance();
self::$_instance->rest = new Optml_Rest();
@@ -201,6 +202,31 @@
}
/**
+ * Opt in to the SDK Support Hub: the Help form links and its mailto fallback.
+ *
+ * @return array{is_pro: bool, support_email: string, links: array<int, array{icon: string, text: string, url: string}>}
+ */
+ public static function add_support_hub_metadata() {
+ return [
+ 'is_pro' => self::is_paid_plan(),
+ // The mailto fallback: Optimole users write to this address.
+ 'support_email' => 'friends@optimole.com',
+ 'links' => [
+ [
+ 'icon' => 'book-alt',
+ 'text' => __( 'Documentation', 'optimole-wp' ),
+ 'url' => Optml_Admin::docs_url( '', 'supporthub', 'help' ),
+ ],
+ [
+ 'icon' => 'groups',
+ 'text' => __( 'Community Forum', 'optimole-wp' ),
+ 'url' => 'https://wordpress.org/support/plugin/optimole-wp/',
+ ],
+ ],
+ ];
+ }
+
+ /**
* Register product into SDK.
*
* @param array $products All products.
@@ -308,12 +334,20 @@
* @access public
*/
public static function sdk_hide_promo_notice( $should_show ) {
- if ( self::$_instance->admin->settings->is_connected() ) {
- $service_data = self::$_instance->admin->settings->get( 'service_data' );
- if ( isset( $service_data['plan'] ) && 'free' !== $service_data['plan'] ) {
- return true;
- }
+ return self::is_paid_plan() ? true : $should_show;
+ }
+
+ /**
+ * Whether the site is connected to a paid Optimole plan.
+ *
+ * @return bool
+ */
+ private static function is_paid_plan() {
+ if ( ! self::$_instance->admin->settings->is_connected() ) {
+ return false;
}
- return $should_show;
+ $service_data = self::$_instance->admin->settings->get( 'service_data' );
+
+ return isset( $service_data['plan'] ) && 'free' !== $service_data['plan'];
}
}
--- a/optimole-wp/inc/manager.php
+++ b/optimole-wp/inc/manager.php
@@ -524,7 +524,7 @@
$missing = $this->page_profiler->missing_devices( $profile_id );
$time = time();
$url = esc_url( esc_js( $this->get_current_url() ) );
- $hmac = wp_hash( $profile_id . $time . $url, 'nonce' );
+ $hmac = Profile::sign( $profile_id, $time, $url );
$js_optimizer = str_replace(
[ Profile::PLACEHOLDER, Profile::PLACEHOLDER_MISSING, Profile::PLACEHOLDER_TIME, Profile::PLACEHOLDER_HMAC, Profile::PLACEHOLDER_URL ],
[ $profile_id, implode( ',', $missing ), strval( $time ), $hmac, $url ],
@@ -564,7 +564,7 @@
}
$marker = Lazyload::get_marker();
- if ( ! empty( $personalized_bg_css ) && ( $start_pos = strpos( $html, $marker ) ) !== false ) { // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.Found
+ if ( null !== $personalized_bg_css && ( $start_pos = strpos( $html, $marker ) ) !== false ) { // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.Found
// We replace the general bg css with the personalized one.
if ( ( $end_pos = strpos(