|
72 | 72 | $prefix = '/index.php'; |
73 | 73 | } |
74 | 74 |
|
75 | | -/* |
| 75 | +/** |
76 | 76 | * In a subdirectory configuration of multisite, the `/blog` prefix is used by |
77 | 77 | * default on the main site to avoid collisions with other sites created on that |
78 | 78 | * network. If the `permalink_structure` option has been changed to remove this |
|
82 | 82 | $blog_prefix = '/blog'; |
83 | 83 | } |
84 | 84 |
|
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' ); |
88 | 87 |
|
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; |
109 | 90 |
|
110 | 91 | if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) ) { |
111 | 92 | check_admin_referer( 'update-permalink' ); |
112 | 93 |
|
113 | 94 | if ( isset( $_POST['permalink_structure'] ) ) { |
114 | | - if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] ) { |
| 95 | + if ( isset( $_POST['selection'] ) && 'custom' !== $_POST['selection'] ) { |
115 | 96 | $permalink_structure = $_POST['selection']; |
116 | 97 | } else { |
117 | 98 | $permalink_structure = $_POST['permalink_structure']; |
|
129 | 110 | $permalink_structure = sanitize_option( 'permalink_structure', $permalink_structure ); |
130 | 111 |
|
131 | 112 | $wp_rewrite->set_permalink_structure( $permalink_structure ); |
| 113 | + |
| 114 | + $structure_updated = true; |
132 | 115 | } |
133 | 116 |
|
134 | 117 | if ( isset( $_POST['category_base'] ) ) { |
135 | 118 | $category_base = $_POST['category_base']; |
| 119 | + |
136 | 120 | if ( ! empty( $category_base ) ) { |
137 | 121 | $category_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $category_base ) ); |
138 | 122 | } |
| 123 | + |
139 | 124 | $wp_rewrite->set_category_base( $category_base ); |
140 | 125 | } |
141 | 126 |
|
142 | 127 | if ( isset( $_POST['tag_base'] ) ) { |
143 | 128 | $tag_base = $_POST['tag_base']; |
| 129 | + |
144 | 130 | if ( ! empty( $tag_base ) ) { |
145 | 131 | $tag_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $tag_base ) ); |
146 | 132 | } |
| 133 | + |
147 | 134 | $wp_rewrite->set_tag_base( $tag_base ); |
148 | 135 | } |
| 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(); |
149 | 159 |
|
| 160 | +if ( $structure_updated ) { |
150 | 161 | $message = __( 'Permalink structure updated.' ); |
151 | 162 |
|
152 | 163 | if ( $iis7_permalinks ) { |
|
163 | 174 | '<code>web.config</code>' |
164 | 175 | ); |
165 | 176 | } |
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 ) { |
167 | 178 | $message = sprintf( |
168 | 179 | /* translators: %s: .htaccess */ |
169 | 180 | __( 'You should update your %s file now.' ), |
@@ -400,7 +411,7 @@ class="button button-secondary" |
400 | 411 | <p><?php _e( '<a href="https://wordpress.org/support/article/nginx/">Documentation on Nginx configuration</a>.' ); ?></p> |
401 | 412 | <?php |
402 | 413 | else : |
403 | | - if ( $permalink_structure && ! $using_index_permalinks && ! $writable && $update_required ) : |
| 414 | + if ( $permalink_structure && ! $using_index_permalinks && ! $writable && $htaccess_update_required ) : |
404 | 415 | ?> |
405 | 416 | <p> |
406 | 417 | <?php |
|
0 commit comments