Skip to content

Commit 7bc790c

Browse files
Permalinks: Correct the check whether .htaccess update is required when saving permalink settings.
The check should be performed after the permalink structure update, not before. Fixes #50834. git-svn-id: https://develop.svn.wordpress.org/trunk@48710 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c77373e commit 7bc790c

1 file changed

Lines changed: 38 additions & 27 deletions

File tree

src/wp-admin/options-permalink.php

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
$prefix = '/index.php';
7373
}
7474

75-
/*
75+
/**
7676
* In a subdirectory configuration of multisite, the `/blog` prefix is used by
7777
* default on the main site to avoid collisions with other sites created on that
7878
* network. If the `permalink_structure` option has been changed to remove this
@@ -82,36 +82,17 @@
8282
$blog_prefix = '/blog';
8383
}
8484

85-
$category_base = get_option( 'category_base' );
86-
$tag_base = get_option( 'tag_base' );
87-
$update_required = false;
85+
$category_base = get_option( 'category_base' );
86+
$tag_base = get_option( 'tag_base' );
8887

89-
if ( $iis7_permalinks ) {
90-
if ( ( ! file_exists( $home_path . 'web.config' ) && win_is_writable( $home_path ) ) || win_is_writable( $home_path . 'web.config' ) ) {
91-
$writable = true;
92-
} else {
93-
$writable = false;
94-
}
95-
} elseif ( $is_nginx ) {
96-
$writable = false;
97-
} else {
98-
if ( ( ! file_exists( $home_path . '.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path . '.htaccess' ) ) {
99-
$writable = true;
100-
} else {
101-
$writable = false;
102-
$existing_rules = array_filter( extract_from_markers( $home_path . '.htaccess', 'WordPress' ) );
103-
$new_rules = array_filter( explode( "\n", $wp_rewrite->mod_rewrite_rules() ) );
104-
$update_required = ( $new_rules !== $existing_rules );
105-
}
106-
}
107-
108-
$using_index_permalinks = $wp_rewrite->using_index_permalinks();
88+
$structure_updated = false;
89+
$htaccess_update_required = false;
10990

11091
if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) ) {
11192
check_admin_referer( 'update-permalink' );
11293

11394
if ( isset( $_POST['permalink_structure'] ) ) {
114-
if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] ) {
95+
if ( isset( $_POST['selection'] ) && 'custom' !== $_POST['selection'] ) {
11596
$permalink_structure = $_POST['selection'];
11697
} else {
11798
$permalink_structure = $_POST['permalink_structure'];
@@ -129,24 +110,54 @@
129110
$permalink_structure = sanitize_option( 'permalink_structure', $permalink_structure );
130111

131112
$wp_rewrite->set_permalink_structure( $permalink_structure );
113+
114+
$structure_updated = true;
132115
}
133116

134117
if ( isset( $_POST['category_base'] ) ) {
135118
$category_base = $_POST['category_base'];
119+
136120
if ( ! empty( $category_base ) ) {
137121
$category_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $category_base ) );
138122
}
123+
139124
$wp_rewrite->set_category_base( $category_base );
140125
}
141126

142127
if ( isset( $_POST['tag_base'] ) ) {
143128
$tag_base = $_POST['tag_base'];
129+
144130
if ( ! empty( $tag_base ) ) {
145131
$tag_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $tag_base ) );
146132
}
133+
147134
$wp_rewrite->set_tag_base( $tag_base );
148135
}
136+
}
137+
138+
if ( $iis7_permalinks ) {
139+
if ( ( ! file_exists( $home_path . 'web.config' ) && win_is_writable( $home_path ) ) || win_is_writable( $home_path . 'web.config' ) ) {
140+
$writable = true;
141+
} else {
142+
$writable = false;
143+
}
144+
} elseif ( $is_nginx ) {
145+
$writable = false;
146+
} else {
147+
if ( ( ! file_exists( $home_path . '.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path . '.htaccess' ) ) {
148+
$writable = true;
149+
} else {
150+
$writable = false;
151+
$existing_rules = array_filter( extract_from_markers( $home_path . '.htaccess', 'WordPress' ) );
152+
$new_rules = array_filter( explode( "\n", $wp_rewrite->mod_rewrite_rules() ) );
153+
154+
$htaccess_update_required = ( $new_rules !== $existing_rules );
155+
}
156+
}
157+
158+
$using_index_permalinks = $wp_rewrite->using_index_permalinks();
149159

160+
if ( $structure_updated ) {
150161
$message = __( 'Permalink structure updated.' );
151162

152163
if ( $iis7_permalinks ) {
@@ -163,7 +174,7 @@
163174
'<code>web.config</code>'
164175
);
165176
}
166-
} elseif ( ! $is_nginx && $permalink_structure && ! $using_index_permalinks && ! $writable && $update_required ) {
177+
} elseif ( ! $is_nginx && $permalink_structure && ! $using_index_permalinks && ! $writable && $htaccess_update_required ) {
167178
$message = sprintf(
168179
/* translators: %s: .htaccess */
169180
__( 'You should update your %s file now.' ),
@@ -400,7 +411,7 @@ class="button button-secondary"
400411
<p><?php _e( '<a href="https://wordpress.org/support/article/nginx/">Documentation on Nginx configuration</a>.' ); ?></p>
401412
<?php
402413
else :
403-
if ( $permalink_structure && ! $using_index_permalinks && ! $writable && $update_required ) :
414+
if ( $permalink_structure && ! $using_index_permalinks && ! $writable && $htaccess_update_required ) :
404415
?>
405416
<p>
406417
<?php

0 commit comments

Comments
 (0)