--- a/wp/wp-admin/options-permalink.php Tue Dec 15 15:52:01 2020 +0100
+++ b/wp/wp-admin/options-permalink.php Wed Sep 21 18:19:35 2022 +0200
@@ -72,7 +72,7 @@
$prefix = '/index.php';
}
-/**
+/*
* In a subdirectory configuration of multisite, the `/blog` prefix is used by
* default on the main site to avoid collisions with other sites created on that
* network. If the `permalink_structure` option has been changed to remove this
@@ -82,36 +82,17 @@
$blog_prefix = '/blog';
}
-$category_base = get_option( 'category_base' );
-$tag_base = get_option( 'tag_base' );
-$update_required = false;
+$category_base = get_option( 'category_base' );
+$tag_base = get_option( 'tag_base' );
-if ( $iis7_permalinks ) {
- if ( ( ! file_exists( $home_path . 'web.config' ) && win_is_writable( $home_path ) ) || win_is_writable( $home_path . 'web.config' ) ) {
- $writable = true;
- } else {
- $writable = false;
- }
-} elseif ( $is_nginx ) {
- $writable = false;
-} else {
- if ( ( ! file_exists( $home_path . '.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path . '.htaccess' ) ) {
- $writable = true;
- } else {
- $writable = false;
- $existing_rules = array_filter( extract_from_markers( $home_path . '.htaccess', 'WordPress' ) );
- $new_rules = array_filter( explode( "\n", $wp_rewrite->mod_rewrite_rules() ) );
- $update_required = ( $new_rules !== $existing_rules );
- }
-}
-
-$using_index_permalinks = $wp_rewrite->using_index_permalinks();
+$structure_updated = false;
+$htaccess_update_required = false;
if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) ) {
check_admin_referer( 'update-permalink' );
if ( isset( $_POST['permalink_structure'] ) ) {
- if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] ) {
+ if ( isset( $_POST['selection'] ) && 'custom' !== $_POST['selection'] ) {
$permalink_structure = $_POST['selection'];
} else {
$permalink_structure = $_POST['permalink_structure'];
@@ -129,46 +110,78 @@
$permalink_structure = sanitize_option( 'permalink_structure', $permalink_structure );
$wp_rewrite->set_permalink_structure( $permalink_structure );
+
+ $structure_updated = true;
}
if ( isset( $_POST['category_base'] ) ) {
$category_base = $_POST['category_base'];
+
if ( ! empty( $category_base ) ) {
$category_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $category_base ) );
}
+
$wp_rewrite->set_category_base( $category_base );
}
if ( isset( $_POST['tag_base'] ) ) {
$tag_base = $_POST['tag_base'];
+
if ( ! empty( $tag_base ) ) {
$tag_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $tag_base ) );
}
+
$wp_rewrite->set_tag_base( $tag_base );
}
+}
+if ( $iis7_permalinks ) {
+ if ( ( ! file_exists( $home_path . 'web.config' ) && win_is_writable( $home_path ) ) || win_is_writable( $home_path . 'web.config' ) ) {
+ $writable = true;
+ } else {
+ $writable = false;
+ }
+} elseif ( $is_nginx ) {
+ $writable = false;
+} else {
+ if ( ( ! file_exists( $home_path . '.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path . '.htaccess' ) ) {
+ $writable = true;
+ } else {
+ $writable = false;
+ $existing_rules = array_filter( extract_from_markers( $home_path . '.htaccess', 'WordPress' ) );
+ $new_rules = array_filter( explode( "\n", $wp_rewrite->mod_rewrite_rules() ) );
+
+ $htaccess_update_required = ( $new_rules !== $existing_rules );
+ }
+}
+
+$using_index_permalinks = $wp_rewrite->using_index_permalinks();
+
+if ( $structure_updated ) {
$message = __( 'Permalink structure updated.' );
- if ( $iis7_permalinks ) {
- if ( $permalink_structure && ! $using_index_permalinks && ! $writable ) {
+ if ( ! is_multisite() && $permalink_structure && ! $using_index_permalinks ) {
+ if ( $iis7_permalinks ) {
+ if ( ! $writable ) {
+ $message = sprintf(
+ /* translators: %s: web.config */
+ __( 'You should update your %s file now.' ),
+ '<code>web.config</code>'
+ );
+ } else {
+ $message = sprintf(
+ /* translators: %s: web.config */
+ __( 'Permalink structure updated. Remove write access on %s file now!' ),
+ '<code>web.config</code>'
+ );
+ }
+ } elseif ( ! $is_nginx && $htaccess_update_required && ! $writable ) {
$message = sprintf(
- /* translators: %s: web.config */
+ /* translators: %s: .htaccess */
__( 'You should update your %s file now.' ),
- '<code>web.config</code>'
- );
- } elseif ( $permalink_structure && ! $using_index_permalinks && $writable ) {
- $message = sprintf(
- /* translators: %s: web.config */
- __( 'Permalink structure updated. Remove write access on %s file now!' ),
- '<code>web.config</code>'
+ '<code>.htaccess</code>'
);
}
- } elseif ( ! $is_nginx && $permalink_structure && ! $using_index_permalinks && ! $writable && $update_required ) {
- $message = sprintf(
- /* translators: %s: .htaccess */
- __( 'You should update your %s file now.' ),
- '<code>.htaccess</code>'
- );
}
if ( ! get_settings_errors() ) {
@@ -344,7 +357,7 @@
if ( isset( $_POST['submit'] ) && $permalink_structure && ! $using_index_permalinks && ! $writable ) :
if ( file_exists( $home_path . 'web.config' ) ) :
?>
-<p>
+<p id="iis-description-a">
<?php
printf(
/* translators: 1: web.config, 2: Documentation URL, 3: CTRL + a, 4: Element code. */
@@ -358,7 +371,7 @@
</p>
<form action="options-permalink.php" method="post">
<?php wp_nonce_field( 'update-permalink' ); ?>
- <p><textarea rows="9" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_textarea( $wp_rewrite->iis7_url_rewrite_rules() ); ?></textarea></p>
+ <p><label for="rules"><?php _e( 'Rewrite rules:' ); ?></label><br /><textarea rows="9" class="large-text readonly" name="rules" id="rules" readonly="readonly" aria-describedby="iis-description-a"><?php echo esc_textarea( $wp_rewrite->iis7_url_rewrite_rules() ); ?></textarea></p>
</form>
<p>
<?php
@@ -370,7 +383,7 @@
?>
</p>
<?php else : ?>
-<p>
+<p id="iis-description-b">
<?php
printf(
/* translators: 1: Documentation URL, 2: web.config, 3: CTRL + a */
@@ -383,7 +396,7 @@
</p>
<form action="options-permalink.php" method="post">
<?php wp_nonce_field( 'update-permalink' ); ?>
- <p><textarea rows="18" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_textarea( $wp_rewrite->iis7_url_rewrite_rules( true ) ); ?></textarea></p>
+ <p><label for="rules"><?php _e( 'Rewrite rules:' ); ?></label><br /><textarea rows="18" class="large-text readonly" name="rules" id="rules" readonly="readonly" aria-describedby="iis-description-b"><?php echo esc_textarea( $wp_rewrite->iis7_url_rewrite_rules( true ) ); ?></textarea></p>
</form>
<p>
<?php
@@ -400,9 +413,9 @@
<p><?php _e( '<a href="https://wordpress.org/support/article/nginx/">Documentation on Nginx configuration</a>.' ); ?></p>
<?php
else :
- if ( $permalink_structure && ! $using_index_permalinks && ! $writable && $update_required ) :
+ if ( $permalink_structure && ! $using_index_permalinks && ! $writable && $htaccess_update_required ) :
?>
-<p>
+<p id="htaccess-description">
<?php
printf(
/* translators: 1: .htaccess, 2: Documentation URL, 3: CTRL + a */
@@ -415,7 +428,7 @@
</p>
<form action="options-permalink.php" method="post">
<?php wp_nonce_field( 'update-permalink' ); ?>
- <p><textarea rows="6" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_textarea( $wp_rewrite->mod_rewrite_rules() ); ?></textarea></p>
+ <p><label for="rules"><?php _e( 'Rewrite rules:' ); ?></label><br /><textarea rows="8" class="large-text readonly" name="rules" id="rules" readonly="readonly" aria-describedby="htaccess-description"><?php echo esc_textarea( $wp_rewrite->mod_rewrite_rules() ); ?></textarea></p>
</form>
<?php endif; ?>
<?php endif; ?>