Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 3.15.9 #6422

Merged
merged 10 commits into from
Feb 1, 2024
2 changes: 1 addition & 1 deletion assets/js/wpr-admin.js.min.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/wpr-admin.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dynamic-lists-delayjs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dynamic-lists.json

Large diffs are not rendered by default.

43 changes: 24 additions & 19 deletions inc/Engine/Admin/Settings/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ private function cloudflare_section() {
if ( ! defined( 'WP_ROCKET_CF_API_KEY_HIDDEN' ) || ! WP_ROCKET_CF_API_KEY_HIDDEN ) {
$this->settings->add_settings_fields(
[
'cloudflare_api_key' => [
'cloudflare_api_key_mask' => [
'label' => _x( 'Global API key:', 'Cloudflare', 'rocket' ),
'description' => sprintf( '<a href="%1$s" target="_blank">%2$s</a>', esc_url( $beacon_cf_credentials_api['url'] ), _x( 'Find your API key', 'Cloudflare', 'rocket' ) ),
'default' => '',
Expand All @@ -2032,7 +2032,7 @@ private function cloudflare_section() {
'section' => 'cloudflare_credentials',
'page' => 'cloudflare',
],
'cloudflare_zone_id' => [
'cloudflare_zone_id_mask' => [
'label' => _x( 'Zone ID', 'Cloudflare', 'rocket' ),
'default' => '',
'container_class' => [
Expand Down Expand Up @@ -2130,6 +2130,27 @@ private function sucuri_section() {
* @since 3.0
*/
private function hidden_fields() {

$hidden_fields = [
'consumer_key',
'consumer_email',
'secret_key',
'license',
'secret_cache_key',
'minify_css_key',
'minify_js_key',
'version',
'cloudflare_old_settings',
'cache_ssl',
'minify_google_fonts',
'emoji',
'remove_unused_css',
'async_css',
'minify_concatenate_css',
'cloudflare_api_key',
'cloudflare_zone_id',
];

$this->settings->add_hidden_settings_fields(
/**
* Filters the hidden settings fields
Expand All @@ -2141,23 +2162,7 @@ private function hidden_fields() {
*/
apply_filters(
'rocket_hidden_settings_fields',
[
'consumer_key',
'consumer_email',
'secret_key',
'license',
'secret_cache_key',
'minify_css_key',
'minify_js_key',
'version',
'cloudflare_old_settings',
'cache_ssl',
'minify_google_fonts',
'emoji',
'remove_unused_css',
'async_css',
'minify_concatenate_css',
]
$hidden_fields
)
);
}
Expand Down
10 changes: 3 additions & 7 deletions inc/Engine/License/Renewal.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function display_renewal_soon_banner() {

$data = $this->get_banner_data();
$data['countdown'] = $this->get_countdown_data();
$discount = esc_html( '$' . number_format_i18n( $this->get_discount_percent(), 2 ) );
$discount = esc_html( $this->get_discount_percent() . '%' );
$price = esc_html( '$' . number_format_i18n( $this->get_price(), 2 ) );

$data['message'] = sprintf(
Expand Down Expand Up @@ -152,7 +152,7 @@ public function display_renewal_expired_banner() {
esc_html__( 'Renew your license for 1 year now and get %1$s%3$s OFF%2$s immediately: you will only pay %1$s%4$s%2$s!', 'rocket' ),
'<strong>',
'</strong>',
esc_html( '$' . number_format_i18n( $this->get_discount_percent(), 2 ) ),
esc_html( $this->get_discount_percent() . '%' ),
$price
);
}
Expand Down Expand Up @@ -325,11 +325,7 @@ private function get_discount_percent() {
$prices = $prices->prices;

if ( $renewals['is_grandfather'] ) {
return isset( $prices->renewal->is_grandfather, $prices->renewal->not_grandfather ) ? $prices->renewal->not_grandfather - $prices->renewal->is_grandfather : 0;
}

if ( $renewals['is_grandmother'] ) {
return isset( $prices->renewal->is_grandmother, $prices->renewal->not_grandfather ) ? $prices->renewal->not_grandfather - $prices->renewal->is_grandmother : 0;
return $renewals['discount_percent']->is_grandfather;
}

return 0;
Expand Down
6 changes: 3 additions & 3 deletions inc/Engine/License/views/renewal-expired-banner-ocd.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
defined( 'ABSPATH' ) || exit;
?>
<section class="rocket-renewal-expired-banner" id="rocket-renewal-banner">
<h3 class="rocket-expired-title"><?php esc_html_e( 'You will soon lose access to some features', 'rocket' ); ?></h3>
<h3 class="rocket-expired-title"><?php esc_html_e( 'You will soon lose access to some features.', 'rocket' ); ?></h3>
<div class="rocket-renewal-expired-banner-container">
<div class="rocket-expired-message">
<p>
<?php
<?php
printf(
// translators: %1$s = <strong>, %2$s = </strong>.
esc_html__( 'You need an %1$sactive license to continue optimizing your CSS delivery%2$s.', 'rocket' ),
Expand All @@ -26,7 +26,7 @@
<?php
printf(
// translators: %1$s = <strong>, %2$s = </strong>, %3$s = date.
esc_html__( 'They will be %1$sautomatically disabled on %3$s%2$s.', 'rocket' ),
esc_html__( 'These features will be %1$sautomatically disabled on %3$s%2$s.', 'rocket' ),
'<strong>',
'</strong>',
esc_html( $data['disabled_date'] )
Expand Down
6 changes: 5 additions & 1 deletion inc/Engine/Media/Lazyload/CSS/Front/ContentFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public function fetch( string $path, string $destination ) {
*/
protected function fetch_content( string $path ) {
if ( ! wp_http_validate_url( $path ) ) {
return $this->filesystem->get_contents( $path );
$file_extension = pathinfo( $path, PATHINFO_EXTENSION );

if ( strtolower( $file_extension ) !== 'php' ) {
return $this->filesystem->get_contents( $path );
}
}
return wp_remote_retrieve_body( wp_remote_get( $path ) );
}
Expand Down
12 changes: 10 additions & 2 deletions inc/Engine/Preload/Database/Queries/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,16 @@ public function remove_all_not_accessed_rows( float $delay = 1, string $unit = '
* @return array
*/
public function get_pending_jobs( int $total = 45 ) {
$inprogress_count = $this->query(
[
'count' => true,
'status' => 'in-progress',
'is_locked' => false,
],
false
);

if ( $total <= 0 ) {
if ( $total <= 0 || $inprogress_count >= $total ) {
return [];
}

Expand All @@ -358,7 +366,7 @@ public function get_pending_jobs( int $total = 45 ) {

return $this->query(
[
'number' => $total,
'number' => ( $total - $inprogress_count ),
'status' => 'pending',
'fields' => [
'id',
Expand Down
6 changes: 6 additions & 0 deletions inc/Engine/WPRocketUninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class WPRocketUninstall {
'wp_rocket_rucss_errors_count',
'wpr_dynamic_lists_incompatible_plugins',
'rocket_divi_notice',
'rocket_rucss_processing',
'rocket_mod_pagespeed_enabled',
'wp_rocket_pricing',
'wp_rocket_pricing_timeout',
'wp_rocket_pricing_timeout_active',
'rocket_get_refreshed_fragments_cache',
];

/**
Expand Down
61 changes: 60 additions & 1 deletion inc/ThirdParty/Plugins/ContactForm7.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class ContactForm7 implements Subscriber_Interface {
*/
const REQUIRED_CF7_VERSION = '5.8.1';

/**
* CF7 scripts load status.
*
* @var bool
*/
private $load_js;

/**
* Subscribed events.
*/
Expand All @@ -27,6 +34,16 @@ public static function get_subscribed_events() {
* Optimize ContactForm7 scripts.
*/
public function maybe_optimize_contact_form_7() {
/**
* Filters register this compatibility events or not.
*
* @param bool $status Load the compatibility file or not, default is True.
* @param string $thirdparty Thirdparty id.
*/
if ( ! apply_filters( 'rocket_thirdparty_load', true, 'contact-form-7' ) ) {
return;
}

// The wpcf7_shortcode_callback action was added in CF7 version 5.8.1.
if ( ! defined( 'WPCF7_VERSION' ) || version_compare( WPCF7_VERSION, self::REQUIRED_CF7_VERSION, '<' ) ) {
return;
Expand All @@ -35,6 +52,10 @@ public function maybe_optimize_contact_form_7() {
// Force scripts and styles to not load by default.
add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );
$this->load_js = false;

add_action( 'wp_enqueue_scripts', [ $this, 'load_scripts_fallback' ], PHP_INT_MAX );
add_action( 'wpcf7_enqueue_scripts', [ $this, 'scripts_loaded' ] );

// Conditionally enqueue scripts.
add_action( 'wpcf7_shortcode_callback', [ $this, 'conditionally_enqueue_scripts' ] );
Expand All @@ -45,7 +66,7 @@ public function maybe_optimize_contact_form_7() {
* Enqueue scripts if not already enqueued.
*/
public function conditionally_enqueue_scripts() {
if ( did_action( 'wpcf7_enqueue_scripts' ) ) { // Prevent double-enqueueing when multiple forms present.
if ( $this->load_js ) { // Prevent double-enqueueing when multiple forms present.
return;
}
if ( did_action( 'wp_enqueue_scripts' ) ) {
Expand All @@ -68,4 +89,42 @@ public function conditionally_enqueue_styles() {
}
add_filter( 'wpcf7_load_css', '__return_true', 11 );
}

/**
* Load CF7 scripts only when CF7 main script is added as a dependency.
*
* @return void
*/
public function load_scripts_fallback() {
if ( $this->load_js || ! $this->cf7_script_enqueued_as_dependency() ) {
return;
}

wpcf7_enqueue_scripts();
}

/**
* Check if CF7 main script is added as a dependency for any script.
*
* @return bool
*/
private function cf7_script_enqueued_as_dependency() {
foreach ( wp_scripts()->registered as $script ) {
foreach ( $script->deps as $dep ) {
if ( 'contact-form-7' === $dep ) {
return true;
}
}
}
return false;
}

/**
* Set a flag that scripts are loaded.
*
* @return void
*/
public function scripts_loaded() {
$this->load_js = true;
}
}
3 changes: 3 additions & 0 deletions inc/admin/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ function rocket_pre_main_option( $newvalue, $oldvalue ) {
'cdn_reject_files' => __( 'Exclude files from CDN', 'rocket' ),
];

// unset the *_mask value as we don't need to save them.
unset( $newvalue['cloudflare_api_key_mask'], $newvalue['cloudflare_zone_id_mask'] );

foreach ( $pattern_labels as $pattern_field => $label ) {
if ( empty( $newvalue[ $pattern_field ] ) ) {
// The field is empty.
Expand Down
30 changes: 8 additions & 22 deletions inc/functions/i18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ function get_rocket_wpml_langs_for_admin_bar() { // phpcs:ignore WordPress.Nami
global $sitepress;
$langlinks = [];

// Making all languages the first option either when it's set or not.
$langlinks[] = [
'code' => 'all',
'current' => 'all' === $sitepress->get_current_language(),
'anchor' => __( 'All languages', 'rocket' ),
'flag' => '<img class="icl_als_iclflag" src="' . ICL_PLUGIN_URL . '/res/img/icon16.png" alt="all" width="16" height="16" />',
];

foreach ( $sitepress->get_active_languages() as $lang ) {
// Get flag.
$flag = $sitepress->get_flag( $lang['code'] );
Expand All @@ -31,28 +39,6 @@ function get_rocket_wpml_langs_for_admin_bar() { // phpcs:ignore WordPress.Nami
];
}

if ( isset( $_GET['lang'] ) && 'all' === $_GET['lang'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
array_unshift(
$langlinks,
[
'code' => 'all',
'current' => 'all' === $sitepress->get_current_language(),
'anchor' => __( 'All languages', 'rocket' ),
'flag' => '<img class="icl_als_iclflag" src="' . ICL_PLUGIN_URL . '/res/img/icon16.png" alt="all" width="16" height="16" />',
]
);
} else {
array_push(
$langlinks,
[
'code' => 'all',
'current' => 'all' === $sitepress->get_current_language(),
'anchor' => __( 'All languages', 'rocket' ),
'flag' => '<img class="icl_als_iclflag" src="' . ICL_PLUGIN_URL . '/res/img/icon16.png" alt="all" width="16" height="16" />',
]
);
}

return $langlinks;
}

Expand Down
62 changes: 61 additions & 1 deletion src/js/global/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,67 @@ $(document).ready(function(){
return wprIsParentActive( $parent.closest( '.wpr-field' ) );
}

// Display/Hide childern fields on checkbox change.
/**
* Masks sensitive information in an input field by replacing all but the last 4 characters with asterisks.
*
* @param {string} id_selector - The ID of the input field to be masked.
* @returns {void} - Modifies the input field value in-place.
*
* @example
* // HTML: <input type="text" id="creditCardInput" value="1234567890123456">
* maskField('creditCardInput');
* // Result: Updates the input field value to '************3456'.
*/
function maskField(proxy_selector, concrete_selector) {
var concrete = {
'val': concrete_selector.val(),
'length': concrete_selector.val().length
}

if (concrete.length > 4) {

var hiddenPart = '\u2022'.repeat(Math.max(0, concrete.length - 4));
var visiblePart = concrete.val.slice(-4);

// Combine the hidden and visible parts
var maskedValue = hiddenPart + visiblePart;

proxy_selector.val(maskedValue);
}
// Ensure events are not added more than once
if (!proxy_selector.data('eventsAttached')) {
proxy_selector.on('input', handleInput);
proxy_selector.on('focus', handleFocus);
proxy_selector.data('eventsAttached', true);
}

/**
* Handle the input event
*/
function handleInput() {
var proxyValue = proxy_selector.val();
if (proxyValue.indexOf('\u2022') === -1) {
concrete_selector.val(proxyValue);
}
}

/**
* Handle the focus event
*/
function handleFocus() {
var concrete_value = concrete_selector.val();
proxy_selector.val(concrete_value);
}

}

// Update the concrete field when the proxy is updated.


maskField($('#cloudflare_api_key_mask'), $('#cloudflare_api_key'));
maskField($('#cloudflare_zone_id_mask'), $('#cloudflare_zone_id'));

// Display/Hide childern fields on checkbox change.
$( '.wpr-isParent input[type=checkbox]' ).on('change', function() {
wprShowChildren($(this));
});
Expand Down