From 67e5038470d08eca0854542b4854b811bf792209 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 28 Jul 2019 16:31:57 +0000 Subject: [PATCH] Rewrite Rules: Add a comment to `# BEGIN/END` `.htaccess` markers to clarify that the directives are dynamically generated, and should only be modified via WordPress filters. Introduce `insert_with_markers_inline_instructions` filter to modify the default instructions text. Props bradleyt, SergeyBiryukov. Fixes #47466. Built from https://develop.svn.wordpress.org/trunk@45694 git-svn-id: http://core.svn.wordpress.org/trunk@45505 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/misc.php | 34 ++++++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/wp-admin/includes/misc.php b/wp-admin/includes/misc.php index 5c5560d60f..26f5233802 100644 --- a/wp-admin/includes/misc.php +++ b/wp-admin/includes/misc.php @@ -79,6 +79,9 @@ function extract_from_markers( $filename, $marker ) { $state = false; } if ( $state ) { + if ( '#' === substr( $markerline, 0, 1 ) ) { + continue; + } $result[] = $markerline; } if ( false !== strpos( $markerline, '# BEGIN ' . $marker ) ) { @@ -119,6 +122,37 @@ function insert_with_markers( $filename, $marker, $insertion ) { $insertion = explode( "\n", $insertion ); } + $switched_locale = switch_to_locale( get_locale() ); + + $instructions = sprintf( + /* translators: 1: marker */ + __( 'The directives (lines) between `BEGIN %1$s` and `END %1$s` are +dynamically generated, and should only be modified via WordPress filters. +Any changes to the directives between these markers will be overwritten.' ), + $marker + ); + + $instructions = explode( "\n", $instructions ); + foreach ( $instructions as $line => $text ) { + $instructions[ $line ] = '# ' . $text; + } + + /** + * Filters the inline instructions inserted before the dynamically generated content. + * + * @since 5.3.0 + * + * @param string[] $instructions Array of lines with inline instructions. + * @param string $marker The marker being inserted. + */ + $instructions = apply_filters( 'insert_with_markers_inline_instructions', $instructions, $marker ); + + if ( $switched_locale ) { + restore_previous_locale(); + } + + $insertion = array_merge( $instructions, $insertion ); + $start_marker = "# BEGIN {$marker}"; $end_marker = "# END {$marker}"; diff --git a/wp-includes/version.php b/wp-includes/version.php index 83a99004f6..9de0833042 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-alpha-45693'; +$wp_version = '5.3-alpha-45694'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.