From d7ec5b4ac0c075b63d5e7c807bb2dc02fe1bf320 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 28 Jul 2019 16:30:46 +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. git-svn-id: https://develop.svn.wordpress.org/trunk@45694 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/misc.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/wp-admin/includes/misc.php b/src/wp-admin/includes/misc.php index 5c5560d60f..26f5233802 100644 --- a/src/wp-admin/includes/misc.php +++ b/src/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}";