Skip to content

Commit 00ed622

Browse files
KhadrealwordpressfanjeawhanleeMiraeldMathieuLamiot
authored
Merge 3.19 feature to develop (#7314)
Co-authored-by: WordPressFan <ahmed@wp-media.me> Co-authored-by: WordPress Fan <146129302+wordpressfan@users.noreply.github.com> Co-authored-by: Michael Lee <38788055+jeawhanlee@users.noreply.github.com> Co-authored-by: Gaël Robin <robin.gael@gmail.com> Co-authored-by: Michael Lee <michaelleemichaellee408@gmail.com> Co-authored-by: Mathieu Lamiot <mathieu.lamiot@free.fr>
1 parent 3c046b5 commit 00ed622

File tree

139 files changed

+7046
-608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+7046
-608
lines changed

assets/js/wpr-beacon.js

Lines changed: 782 additions & 4 deletions
Large diffs are not rendered by default.

assets/js/wpr-beacon.min.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/wpr-beacon.min.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inc/Engine/Admin/Beacon/Beacon.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -483,16 +483,6 @@ public function get_suggest( $doc_id ) {
483483
'url' => 'https://fr.docs.wp-rocket.me/article/188-comment-est-pre-charge-le-cache/?utm_source=wp_plugin&utm_medium=wp_rocket',
484484
],
485485
],
486-
'dns_prefetch' => [
487-
'en' => [
488-
'id' => '5e055a602c7d3a7e9ae5881c',
489-
'url' => 'https://docs.wp-rocket.me/article/1302-prefetch-dns-requests/?utm_source=wp_plugin&utm_medium=wp_rocket',
490-
],
491-
'fr' => [
492-
'id' => '5e1891892c7d3a7e9ae60983',
493-
'url' => 'https://fr.docs.wp-rocket.me/article/1303-prechargement-requetes-dns/?utm_source=wp_plugin&utm_medium=wp_rocket',
494-
],
495-
],
496486
'fonts_preload' => [
497487
'en' => [
498488
'id' => '5eab7729042863474d19f647',
@@ -821,16 +811,6 @@ public function get_suggest( $doc_id ) {
821811
'url' => 'https://fr.docs.wp-rocket.me/article/1833-impossible-creer-table-rucssusedcss/?utm_source=wp_plugin&utm_medium=wp_rocket',
822812
],
823813
],
824-
'lazy_render_content' => [
825-
'en' => [
826-
'id' => '66b11e26a62a7505fcf339e7',
827-
'url' => 'https://docs.wp-rocket.me/article/1835-lazy-render-content/?utm_source=wp_plugin&utm_medium=wp_rocket',
828-
],
829-
'fr' => [
830-
'id' => '66ba0e8e082392452a0773ea',
831-
'url' => 'https://fr.docs.wp-rocket.me/article/1836-rendu-differe-automatique/?utm_source=wp_plugin&utm_medium=wp_rocket',
832-
],
833-
],
834814
'host_fonts_locally' => [
835815
'en' => [
836816
'id' => '673358b02ddbd952f6241b38',
@@ -841,6 +821,16 @@ public function get_suggest( $doc_id ) {
841821
'url' => 'https://fr.docs.wp-rocket.me/article/1852-auto-heberger-google-fonts?utm_source=wp_plugin&utm_medium=wp_rocket',
842822
],
843823
],
824+
'preconnect_domains' => [
825+
'en' => [
826+
'id' => '681b61d889bd957cd04bd2d9',
827+
'url' => 'https://docs.wp-rocket.me/article/1869-preconnect-to-external-domains',
828+
],
829+
'fr' => [
830+
'id' => '681da5ae11561a04f5de356e',
831+
'url' => 'https://fr.docs.wp-rocket.me/article/1870-preconnexion-aux-domaines-externes',
832+
],
833+
],
844834
];
845835

846836
return isset( $suggest[ $doc_id ][ $this->get_user_locale() ] )

inc/Engine/Admin/Settings/Page.php

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ private function media_section() {
847847
$exclude_lazyload = $this->beacon->get_suggest( 'exclude_lazyload' );
848848
$dimensions = $this->beacon->get_suggest( 'image_dimensions' );
849849
$fonts = $this->beacon->get_suggest( 'host_fonts_locally' );
850+
$fonts_preload = $this->beacon->get_suggest( 'fonts_preload' );
850851

851852
$this->settings->add_page_section(
852853
'media',
@@ -936,12 +937,10 @@ private function media_section() {
936937
'page' => 'media',
937938
],
938939
'font_optimization_section' => [
939-
'title' => __( 'Fonts', 'rocket' ),
940-
'type' => 'fields_container',
941-
// translators: %1$s = opening <a> tag, %2$s = closing </a> tag.
942-
'description' => sprintf( __( 'Download and serve fonts directly from your server. Reduces connections to external servers and minimizes font shifts. %1$sMore info%2$s', 'rocket' ), '<a href="' . esc_url( $fonts['url'] ) . '" data-beacon-article="' . esc_attr( $fonts['id'] ) . '" target="_blank" rel="noopener noreferrer">', '</a>' ),
943-
'help' => $fonts,
944-
'page' => 'media',
940+
'title' => __( 'Fonts', 'rocket' ),
941+
'type' => 'fields_container',
942+
'help' => $fonts,
943+
'page' => 'media',
945944
],
946945
]
947946
);
@@ -1041,9 +1040,21 @@ private function media_section() {
10411040
'default' => 0,
10421041
'sanitize_callback' => 'sanitize_checkbox',
10431042
],
1043+
'auto_preload_fonts' => [
1044+
'type' => 'checkbox',
1045+
'label' => __( 'Preload fonts', 'rocket' ),
1046+
// translators: %1$s = opening <a> tag, %2$s = closing </a> tag.
1047+
'description' => sprintf( __( 'Preload above-the-fold fonts to enhance layout stability and optimize text-based LCP elements. %1$sMore info%2$s', 'rocket' ), '<a href="' . esc_url( $fonts_preload['url'] ) . '" data-beacon-article="' . esc_attr( $fonts_preload['id'] ) . '" target="_blank" rel="noopener noreferrer">', '</a>' ),
1048+
'section' => 'font_optimization_section',
1049+
'page' => 'media',
1050+
'default' => 0,
1051+
'sanitize_callback' => 'sanitize_checkbox',
1052+
],
10441053
'host_fonts_locally' => [
10451054
'type' => 'checkbox',
10461055
'label' => __( 'Self-host Google Fonts', 'rocket' ),
1056+
// translators: %1$s = opening <a> tag, %2$s = closing </a> tag.
1057+
'description' => sprintf( __( 'Download and serve fonts directly from your server. Reduces connections to external servers and minimizes font shifts. %1$sMore info%2$s', 'rocket' ), '<a href="' . esc_url( $fonts['url'] ) . '" data-beacon-article="' . esc_attr( $fonts['id'] ) . '" target="_blank" rel="noopener noreferrer">', '</a>' ),
10471058
'section' => 'font_optimization_section',
10481059
'page' => 'media',
10491060
'default' => 0,
@@ -1063,7 +1074,7 @@ private function preload_section() {
10631074
'preload',
10641075
[
10651076
'title' => __( 'Preload', 'rocket' ),
1066-
'menu_description' => __( 'Generate cache files, preload fonts', 'rocket' ),
1077+
'menu_description' => __( 'Generate cache files', 'rocket' ),
10671078
]
10681079
);
10691080

@@ -1096,24 +1107,6 @@ private function preload_section() {
10961107
],
10971108
'page' => 'preload',
10981109
],
1099-
'dns_prefetch_section' => [
1100-
'title' => __( 'Prefetch DNS Requests', 'rocket' ),
1101-
'type' => 'fields_container',
1102-
'description' => __( 'DNS prefetching can make external files load faster, especially on mobile networks', 'rocket' ),
1103-
'help' => $this->beacon->get_suggest( 'dns_prefetch' ),
1104-
'page' => 'preload',
1105-
],
1106-
'preload_fonts_section' => [
1107-
'title' => __( 'Preload Fonts', 'rocket' ),
1108-
'type' => 'fields_container',
1109-
// translators: %1$s = opening <a> tag, %2$s = closing </a> tag.
1110-
'description' => sprintf( __( 'Improves performance by helping browsers discover fonts in CSS files. %1$sMore info%2$s', 'rocket' ), '<a href="' . esc_url( $fonts_preload['url'] ) . '" data-beacon-article="' . esc_attr( $fonts_preload['id'] ) . '" target="_blank">', '</a>' ),
1111-
'help' => [
1112-
'id' => $fonts_preload['id'],
1113-
'url' => $fonts_preload['url'],
1114-
],
1115-
'page' => 'preload',
1116-
],
11171110
]
11181111
);
11191112

@@ -1146,27 +1139,6 @@ private function preload_section() {
11461139
'default' => [],
11471140
'sanitize_callback' => 'sanitize_textarea',
11481141
],
1149-
'dns_prefetch' => [
1150-
'type' => 'textarea',
1151-
'label' => __( 'URLs to prefetch', 'rocket' ),
1152-
'description' => __( 'Specify external hosts to be prefetched (no <code>http:</code>, one per line)', 'rocket' ),
1153-
'placeholder' => '//example.com',
1154-
'section' => 'dns_prefetch_section',
1155-
'page' => 'preload',
1156-
'default' => [],
1157-
'sanitize_callback' => 'sanitize_textarea',
1158-
],
1159-
'preload_fonts' => [
1160-
'type' => 'textarea',
1161-
'label' => __( 'Fonts to preload', 'rocket' ),
1162-
'description' => __( 'Specify urls of the font files to be preloaded (one per line). Fonts must be hosted on your own domain, or the domain you have specified on the CDN tab.', 'rocket' ),
1163-
'helper' => __( 'The domain part of the URL will be stripped automatically.<br/>Allowed font extensions: otf, ttf, svg, woff, woff2.', 'rocket' ),
1164-
'placeholder' => '/wp-content/themes/your-theme/assets/fonts/font-file.woff',
1165-
'section' => 'preload_fonts_section',
1166-
'page' => 'preload',
1167-
'default' => [],
1168-
'sanitize_callback' => 'sanitize_textarea',
1169-
],
11701142
'preload_links' => [
11711143
'type' => 'checkbox',
11721144
'label' => __( 'Enable link preloading', 'rocket' ),
@@ -2116,6 +2088,7 @@ private function hidden_fields() {
21162088
'minify_concatenate_css',
21172089
'cloudflare_api_key',
21182090
'cloudflare_zone_id',
2091+
'dns_prefetch',
21192092
];
21202093

21212094
$this->settings->add_hidden_settings_fields(
@@ -2266,29 +2239,24 @@ public function display_update_notice() {
22662239

22672240
$previous_version = $this->options->get( 'previous_version' );
22682241

2269-
// Bail-out for fresh install.
2270-
if ( empty( $previous_version ) ) {
2242+
// Bail-out if previous version is greater than or equal to 3.19.
2243+
if ( version_compare( $previous_version, '3.19', '>=' ) ) {
22712244
return;
22722245
}
22732246

2274-
// Bail-out if previous version is greater than 3.17.
2275-
if ( $previous_version > '3.17' ) {
2276-
return;
2277-
}
2278-
2279-
$lazy_render_content = $this->beacon->get_suggest( 'lazy_render_content' );
2247+
$preconnect_content = $this->beacon->get_suggest( 'preconnect_domains' );
22802248

22812249
rocket_notice_html(
22822250
[
22832251
'status' => 'info',
22842252
'dismissible' => '',
22852253
'message' => sprintf(
2286-
// translators: %1$s: opening strong tag, %2$s: closing strong tag, %3$s: opening a tag, %4$s: opening a tag.
2287-
__( '%1$sWP Rocket:%2$s the plugin has been updated to the 3.17 version. New feature: %3$sAutomatic Lazy Rendering%4$s. Check out our documentation to learn more about it.', 'rocket' ),
2288-
'<strong>',
2289-
'</strong>',
2290-
'<a href="' . esc_url( $lazy_render_content['url'] ) . '" data-beacon-article="' . esc_attr( $lazy_render_content['id'] ) . '" target="_blank" rel="noopener noreferrer">',
2291-
'</a>'
2254+
// translators: %1$s: opening strong tag, %2$s: closing strong tag, %3$s: opening a tag, %4$s: closing a tag.
2255+
__( '%1$sWP Rocket:%2$s the plugin has been updated to the 3.19 version. New feature: %3$sPreconnect to external domains%4$s. Check out our documentation to learn more about it.', 'rocket' ),
2256+
'<strong>',
2257+
'</strong>',
2258+
'<a href="' . esc_url( $preconnect_content['url'] ) . '" data-beacon-article="' . esc_attr( $preconnect_content['id'] ) . '" target="_blank" rel="noopener noreferrer">',
2259+
'</a>'
22922260
),
22932261
'dismiss_button' => 'rocket_update_notice',
22942262
]

inc/Engine/Admin/Settings/Render.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ public function cache_lifespan( $args ) {
428428
* @param array $args Array of arguments to populate the template.
429429
*/
430430
public function hidden( $args ) {
431+
if ( is_array( $args['value'] ) ) {
432+
$args['value'] = implode( "\n", $args['value'] );
433+
}
434+
431435
echo $this->generate( 'fields/hidden', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
432436
}
433437

inc/Engine/Admin/Settings/Settings.php

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,6 @@ class Settings {
3737
*/
3838
private $hidden_settings;
3939

40-
/**
41-
* Font formats allowed to be preloaded.
42-
*
43-
* @since 3.6
44-
* @see $this->sanitize_font()
45-
*
46-
* @var array
47-
*/
48-
private $font_formats = [
49-
'otf',
50-
'ttf',
51-
'svg',
52-
'woff',
53-
'woff2',
54-
];
55-
56-
/**
57-
* Array of valid hosts.
58-
*
59-
* @since 3.6
60-
* @see $this->get_hosts()
61-
*
62-
* @var array
63-
*/
64-
private $hosts;
65-
6640
/**
6741
* Constructor
6842
*
@@ -342,9 +316,6 @@ public function sanitize_callback( $input ) {
342316
// Options: Activate bot preload.
343317
$input['manual_preload'] = ! empty( $input['manual_preload'] ) ? 1 : 0;
344318

345-
// Option : fonts to preload.
346-
$input['preload_fonts'] = ! empty( $input['preload_fonts'] ) ? $this->sanitize_fonts( $input['preload_fonts'] ) : [];
347-
348319
// Options: Sucuri cache. And yeah, there's a typo, but now it's too late to fix ^^'.
349320
$input['sucury_waf_cache_sync'] = ! empty( $input['sucury_waf_cache_sync'] ) ? 1 : 0;
350321

@@ -530,101 +501,6 @@ function ( $url ) {
530501
);
531502
}
532503

533-
/**
534-
* Sanitize a list of font file paths.
535-
*
536-
* @since 3.6
537-
*
538-
* @param array|string $files List of filepaths to sanitize. Can be an array of strings or a string listing paths separated by "\n".
539-
* @return array Sanitized filepaths.
540-
*/
541-
private function sanitize_fonts( $files ) {
542-
if ( ! is_array( $files ) ) {
543-
$files = explode( "\n", trim( $files ) );
544-
}
545-
546-
$files = array_map( [ $this, 'sanitize_font' ], $files );
547-
548-
return array_unique( array_filter( $files ) );
549-
}
550-
551-
/**
552-
* Sanitize an entry for the preload fonts option.
553-
*
554-
* @since 3.6
555-
*
556-
* @param string $file URL or path to a font file.
557-
* @return string|bool
558-
*/
559-
private function sanitize_font( string $file ) {
560-
$file = trim( $file );
561-
562-
if ( empty( $file ) ) {
563-
return false;
564-
}
565-
566-
$parsed_url = wp_parse_url( $file );
567-
$hosts = $this->get_hosts();
568-
569-
if ( ! empty( $parsed_url['host'] ) ) {
570-
$match = false;
571-
572-
foreach ( $hosts as $host ) {
573-
if ( false !== strpos( $file, $host ) ) {
574-
$match = true;
575-
break;
576-
}
577-
}
578-
579-
if ( ! $match ) {
580-
return false;
581-
}
582-
}
583-
584-
$file = str_replace( [ 'http:', 'https:' ], '', $file );
585-
$file = str_replace( $hosts, '', $file );
586-
$file = '/' . ltrim( $file, '/' );
587-
588-
$ext = strtolower( pathinfo( $parsed_url['path'], PATHINFO_EXTENSION ) );
589-
590-
if ( ! in_array( $ext, $this->font_formats, true ) ) {
591-
return false;
592-
}
593-
594-
return $file;
595-
}
596-
597-
/**
598-
* Gets an array of valid hosts.
599-
*
600-
* @since 3.6
601-
*
602-
* @return array
603-
*/
604-
private function get_hosts() {
605-
$urls = (array) $this->options->get( 'cdn_cnames', [] );
606-
$urls[] = home_url();
607-
$urls = array_map( 'rocket_add_url_protocol', $urls );
608-
609-
foreach ( $urls as $url ) {
610-
$parsed_url = get_rocket_parse_url( $url );
611-
612-
if ( empty( $parsed_url['host'] ) ) {
613-
continue;
614-
}
615-
616-
$parsed_url['path'] = ( '/' === $parsed_url['path'] ) ? '' : $parsed_url['path'];
617-
618-
$this->hosts[] = "//{$parsed_url['host']}{$parsed_url['path']}";
619-
}
620-
621-
if ( empty( $this->hosts ) ) {
622-
$this->hosts = [];
623-
}
624-
625-
return $this->hosts;
626-
}
627-
628504
/**
629505
* Sets radio buttons sub fields value from wp options.
630506
*

inc/Engine/Admin/Settings/Subscriber.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,21 @@ public static function get_subscribed_events() {
7070
'admin_notices' => 'display_update_notice',
7171
];
7272

73-
return array_merge( $events, PluginFamily::get_subscribed_events() );
73+
foreach ( PluginFamily::get_subscribed_events() as $hook => $callback ) {
74+
if ( isset( $events[ $hook ] ) ) {
75+
// Make sure it's an array of callbacks.
76+
if ( ! is_array( $events[ $hook ][0] ) ) {
77+
$events[ $hook ] = [ $events[ $hook ] ];
78+
}
79+
80+
// Wrap single callback in array if needed.
81+
$events[ $hook ][] = is_array( $callback ) ? $callback : [ $callback ];
82+
} else {
83+
$events[ $hook ] = is_array( $callback ) ? $callback : [ [ $callback ] ];
84+
}
85+
}
86+
87+
return $events;
7488
}
7589

7690
/**

0 commit comments

Comments
 (0)