Skip to content

Commit

Permalink
Release v3.14.1 PR #6025
Browse files Browse the repository at this point in the history
Release v3.14.1
  • Loading branch information
engahmeds3ed authored Jul 4, 2023
2 parents dd11428 + 4b50481 commit b5e13c1
Show file tree
Hide file tree
Showing 42 changed files with 1,391 additions and 176 deletions.
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.

31 changes: 24 additions & 7 deletions inc/Addon/Cloudflare/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ public static function get_subscribed_events() {
'update_option_' . $slug => [
[ 'save_cloudflare_options', 10, 2 ],
[ 'update_dev_mode', 11, 2 ],
[ 'display_settings_notice', 11, 2 ],
],
'pre_update_option_' . $slug => [
[ 'change_auth', 8, 2 ],
[ 'delete_connection_transient', 10, 2 ],
[ 'save_cloudflare_old_settings', 10, 2 ],
[ 'display_settings_notice', 11, 2 ],
],
'rocket_buffer' => [ 'protocol_rewrite', PHP_INT_MAX ],
'wp_calculate_image_srcset' => [ 'protocol_rewrite_srcset', PHP_INT_MAX ],
'rocket_cdn_helper_addons' => 'add_cdn_helper_message',
];
}

Expand Down Expand Up @@ -601,13 +602,13 @@ public function delete_connection_transient( $value, $old_value ) {
'cloudflare_protocol_rewrite',
];

$out = false;
$change = false;

foreach ( $fields as $field ) {
$out &= ! isset( $old_value[ $field ], $value[ $field ] ) || $old_value[ $field ] !== $value[ $field ];
$change |= ! isset( $old_value[ $field ], $value[ $field ] ) || $old_value[ $field ] !== $value[ $field ];
}

if ( $out ) {
if ( ! $change ) {
return $value;
}

Expand All @@ -620,19 +621,24 @@ public function delete_connection_transient( $value, $old_value ) {
/**
* Display the error notice.
*
* @param array $old_value An array of submitted values for the settings.
* @param array $value An array of previous values for the settings.
* @param array $old_value An array of submitted values for the settings.
*
* @return mixed
*/
public function display_settings_notice( $old_value, $value ) {
public function display_settings_notice( $value, $old_value ) {

if ( ! key_exists( 'cloudflare_zone_id', $value ) ) {
return $value;
}

$connection = $this->cloudflare->check_connection( $value['cloudflare_zone_id'] );

if ( is_wp_error( $connection ) ) {
add_settings_error( 'general', 'cloudflare_api_key_invalid', __( 'WP Rocket: ', 'rocket' ) . '</strong>' . $connection->get_error_message() . '<strong>', 'error' );
}

return $old_value;
return $value;
}

/**
Expand Down Expand Up @@ -693,4 +699,15 @@ private function can_protocol_rewrite(): bool {
apply_filters( 'do_rocket_protocol_rewrite', false ) // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
);
}

/**
* Add the helper message on the CDN settings.
*
* @param string[] $addons Name from the addon that requires the helper message.
* @return string[]
*/
public function add_cdn_helper_message( array $addons ): array {
$addons[] = 'Cloudflare';
return $addons;
}
}
17 changes: 17 additions & 0 deletions inc/Addon/Sucuri/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static function get_subscribed_events() {
'after_rocket_clean_files' => 'maybe_clean_firewall_cache',
'admin_post_rocket_purge_sucuri' => 'do_admin_post_rocket_purge_sucuri',
'admin_notices' => 'maybe_print_notice',
'rocket_cdn_helper_addons' => 'add_cdn_helper_message',
];
}

Expand Down Expand Up @@ -339,6 +340,22 @@ private function request_api( $params = [] ) {
return $data;
}

/**
* Add the helper message on the CDN settings.
*
* @param string[] $addons Name from the addon that requires the helper message.
* @return string[]
*/
public function add_cdn_helper_message( array $addons ): array {

if ( ! $this->options->get( 'sucury_waf_cache_sync', false ) ) {
return $addons;
}

$addons[] = 'Sucuri';
return $addons;
}

/**
* An i18n-friendly alternative to the built-in PHP method `http_build_query()`.
*
Expand Down
18 changes: 12 additions & 6 deletions inc/Engine/Admin/Settings/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -1625,16 +1625,22 @@ private function cdn_section() {
);

$maybe_display_cdn_helper = '';
$addons = [];

if ( get_rocket_option( 'do_cloudflare' ) ) {
$addons[] = 'Cloudflare';
}
/**
* Name from addons requiring the helper message.
*
* @param string[] addons.
*
* @return string []
*/
$addons = apply_filters( 'rocket_cdn_helper_addons', [] );

if ( get_rocket_option( 'sucury_waf_cache_sync' ) ) {
$addons[] = 'Sucuri';
if ( ! is_array( $addons ) ) {
$addons = [];
}

$addons = array_unique( $addons );

if ( ! empty( $addons ) ) {
$maybe_display_cdn_helper = wp_sprintf(
// translators: %1$s = opening em tag, %2$l = list of add-on name(s), %3$s = closing em tag.
Expand Down
16 changes: 8 additions & 8 deletions inc/Engine/Optimization/DelayJS/Admin/SiteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function prepare_delayjs_ui_list() {

$active_plugins = $this->get_active_plugins();
foreach ( $this->get_plugins_from_list() as $plugin_key => $plugin ) {
if ( ! in_array( strtolower( $plugin->condition ), $active_plugins, true ) ) {
if ( ! in_array( $plugin->condition, $active_plugins, true ) ) {
continue;
}

Expand All @@ -233,7 +233,7 @@ public function prepare_delayjs_ui_list() {

$active_theme = $this->get_active_theme();
foreach ( $this->get_themes_from_list() as $theme_key => $theme ) {
if ( strtolower( $theme->condition ) !== $active_theme ) {
if ( $theme->condition !== $active_theme ) {
continue;
}

Expand Down Expand Up @@ -307,7 +307,7 @@ public function refresh_exclusions_option() {
private function get_plugin_item_ids( string $plugin_base ) {
$item_ids = [];
foreach ( $this->get_plugins_from_list() as $plugin_key => $plugin ) {
if ( strtolower( $plugin_base ) !== strtolower( $plugin->condition ) ) {
if ( $plugin_base !== $plugin->condition ) {
continue;
}
$item_ids[ $plugin_key ] = $plugin->is_default;
Expand Down Expand Up @@ -406,10 +406,10 @@ public function remove_plugin_selection( $plugin_base ) {
private function get_theme_name( WP_Theme $theme ) {
$parent = $theme->get_template();
if ( ! empty( $parent ) ) {
return strtolower( $parent );
return $parent;
}

return strtolower( $theme->get( 'Name' ) );
return $theme->get( 'Name' );
}

/**
Expand All @@ -422,7 +422,7 @@ private function get_theme_name( WP_Theme $theme ) {
private function get_theme_item_ids( $theme_name ) {
$item_ids = [];
foreach ( $this->get_themes_from_list() as $theme_key => $theme ) {
if ( strtolower( $theme_name ) !== strtolower( $theme->condition ) ) {
if ( $theme_name !== $theme->condition ) {
continue;
}

Expand Down Expand Up @@ -506,7 +506,7 @@ public function get_default_exclusions() {

$active_plugins = $this->get_active_plugins();
foreach ( $this->get_plugins_from_list() as $plugin_key => $plugin ) {
if ( ! in_array( strtolower( $plugin->condition ), $active_plugins, true ) || ! $plugin->is_default ) {
if ( ! in_array( $plugin->condition, $active_plugins, true ) || ! $plugin->is_default ) {
continue;
}

Expand All @@ -515,7 +515,7 @@ public function get_default_exclusions() {

$active_theme = $this->get_active_theme();
foreach ( $this->get_themes_from_list() as $theme_key => $theme ) {
if ( strtolower( $theme->condition ) !== $active_theme || ! $theme->is_default ) {
if ( $theme->condition !== $active_theme || ! $theme->is_default ) {
continue;
}

Expand Down
20 changes: 19 additions & 1 deletion inc/Engine/Optimization/RUCSS/Controller/UsedCSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,20 @@ public function add_url_to_the_queue( string $url, bool $is_mobile ) {
*/
$safelist = apply_filters( 'rocket_rucss_safelist', $this->options->get( 'remove_unused_css_safelist', [] ) );

/**
* Filters the styles attributes to be skipped (blocked) by RUCSS.
*
* @since 3.14
*
* @param array $skipped_attr Array of safelist values.
*/
$skipped_attr = apply_filters( 'rocket_rucss_skip_styles_with_attr', [] );
$skipped_attr = ( is_array( $skipped_attr ) ) ? $skipped_attr : [];

$config = [
'treeshake' => 1,
'rucss_safelist' => $safelist,
'skip_attr' => $skipped_attr,
'is_mobile' => $is_mobile,
'is_home' => $this->is_home( $url ),
];
Expand Down Expand Up @@ -824,7 +835,14 @@ public function clear_failed_urls() {

foreach ( $rows as $row ) {
$failed_urls[] = $row->url;
$this->used_css_query->revert_to_pending( $row->id );

$id = (int) $row->id;

if ( empty( $id ) ) {
continue;
}

$this->used_css_query->revert_to_pending( $id );
}

/**
Expand Down
11 changes: 7 additions & 4 deletions inc/Engine/Preload/Controller/CheckExcludedTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,24 @@ public function add_cache_reject_uri_to_excluded( array $regexes ): array {
*/
protected function is_excluded_by_filter( string $url ): bool {
global $wp_rewrite;

$pagination_regex = "/$wp_rewrite->pagination_base/\d+";
$url = strtok( $url, '?' );
$url = user_trailingslashit( $url );

/**
* Regex to exclude URI from preload.
*
* @param string[] regexes to check
* @param string[] $regexes Regexes to check.
* @param string $url Current preloading url.
*/
$regexes = (array) apply_filters( 'rocket_preload_exclude_urls', [ $pagination_regex ] );
$regexes = (array) apply_filters( 'rocket_preload_exclude_urls', [ $pagination_regex ], $url );

if ( empty( $regexes ) ) {
return false;
}

$regexes = array_unique( $regexes );
$url = strtok( $url, '?' );
$url = user_trailingslashit( $url );

foreach ( $regexes as $regex ) {
if ( ! is_string( $regex ) ) {
Expand Down
66 changes: 65 additions & 1 deletion inc/Engine/Preload/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public static function get_subscribed_events() {
],
'rocket_after_process_buffer' => 'update_cache_row',
'rocket_deactivation' => 'on_deactivation',
'rocket_reset_preload' => 'on_permalink_changed',
'permalink_structure_changed' => 'on_permalink_changed',
'wp_rocket_upgrade' => [ 'on_update', 16, 2 ],
'rocket_rucss_complete_job_status' => 'clean_url',
Expand All @@ -120,8 +121,10 @@ public static function get_subscribed_events() {
'rocket_preload_exclude_urls' => [
[ 'add_preload_excluded_uri' ],
[ 'add_cache_reject_uri_to_excluded' ],
[ 'exclude_private_post_uri' ],
],
'rocket_rucss_after_clearing_failed_url' => [ 'clean_urls', 20 ],
'transition_post_status' => [ 'remove_private_post', 10, 3 ],
];
}

Expand Down Expand Up @@ -234,7 +237,7 @@ public function delete_url_on_not_found() {
public function on_permalink_changed() {
$this->query->remove_all();
$this->queue->cancel_pending_jobs();
$this->controller->load_initial_sitemap();
$this->queue->add_job_preload_job_load_initial_sitemap_async();
}

/**
Expand Down Expand Up @@ -451,4 +454,65 @@ public function add_preload_excluded_uri( $regexes ): array {

return array_merge( $regexes, $preload_excluded_uri );
}

/**
* Remove private post from cache.
*
* @param string $new_status New post status.
* @param string $old_status Old post status.
* @param WP_Post $post Wp post object.
* @return void
*/
public function remove_private_post( string $new_status, string $old_status, $post ) {

if ( $new_status === $old_status ) {
return;
}

if ( 'private' !== $new_status ) {
return;
}

$this->delete_post_preload_cache( $post->ID );
}

/**
* Exclude private urls.
*
* @param array $regexes regexes containing excluded uris.
* @return array
*/
public function exclude_private_post_uri( $regexes ) : array {
static $private_urls;

if ( ! is_array( $regexes ) ) {
$regexes = (array) $regexes;
}

if ( isset( $private_urls ) ) {
return $private_urls;
}

$arg = [
'post_type' => 'any',
'post_status' => 'private',
'posts_per_page' => -1,
];
$query = new \WP_Query( $arg );

if ( ! $query->have_posts() ) {
return $regexes;
}

$private_post_urls = [];
foreach ( $query->posts as $post ) {
// Temporarily cast publish status to get pretty url.
$post->post_status = 'publish';
$private_post_urls[] = get_permalink( $post );
}

$private_urls = array_merge( $regexes, $private_post_urls );

return $private_urls;
}
}
15 changes: 15 additions & 0 deletions inc/ThirdParty/Plugins/CDN/Cloudflare.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static function get_subscribed_events() {
'rocket_rucss_complete_job_status' => 'purge_cloudflare_after_usedcss',
'rocket_rucss_after_clearing_usedcss' => 'purge_cloudflare_after_usedcss',
'admin_post_rocket_enable_separate_mobile_cache' => 'enable_separate_mobile_cache',
'rocket_cdn_helper_addons' => 'add_cdn_helper_message',
];
}

Expand Down Expand Up @@ -449,4 +450,18 @@ private function is_apo_enabled(): bool {

return (bool) $is_apo_enabled['value'];
}

/**
* Add the helper message on the CDN settings.
*
* @param string[] $addons Name from the addon that requires the helper message.
* @return string[]
*/
public function add_cdn_helper_message( array $addons ): array {
if ( ! $this->is_plugin_active() ) {
return $addons;
}
$addons[] = 'Cloudflare';
return $addons;
}
}
Loading

0 comments on commit b5e13c1

Please sign in to comment.