70 $blog_prefix = ''; |
70 $blog_prefix = ''; |
71 if ( ! got_url_rewrite() ) { |
71 if ( ! got_url_rewrite() ) { |
72 $prefix = '/index.php'; |
72 $prefix = '/index.php'; |
73 } |
73 } |
74 |
74 |
75 /** |
75 /* |
76 * In a subdirectory configuration of multisite, the `/blog` prefix is used by |
76 * In a subdirectory configuration of multisite, the `/blog` prefix is used by |
77 * default on the main site to avoid collisions with other sites created on that |
77 * default on the main site to avoid collisions with other sites created on that |
78 * network. If the `permalink_structure` option has been changed to remove this |
78 * network. If the `permalink_structure` option has been changed to remove this |
79 * base prefix, WordPress core can no longer account for the possible collision. |
79 * base prefix, WordPress core can no longer account for the possible collision. |
80 */ |
80 */ |
81 if ( is_multisite() && ! is_subdomain_install() && is_main_site() && 0 === strpos( $permalink_structure, '/blog/' ) ) { |
81 if ( is_multisite() && ! is_subdomain_install() && is_main_site() && 0 === strpos( $permalink_structure, '/blog/' ) ) { |
82 $blog_prefix = '/blog'; |
82 $blog_prefix = '/blog'; |
83 } |
83 } |
84 |
84 |
85 $category_base = get_option( 'category_base' ); |
85 $category_base = get_option( 'category_base' ); |
86 $tag_base = get_option( 'tag_base' ); |
86 $tag_base = get_option( 'tag_base' ); |
87 $update_required = false; |
87 |
88 |
88 $structure_updated = false; |
89 if ( $iis7_permalinks ) { |
89 $htaccess_update_required = false; |
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(); |
|
109 |
90 |
110 if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) ) { |
91 if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) ) { |
111 check_admin_referer( 'update-permalink' ); |
92 check_admin_referer( 'update-permalink' ); |
112 |
93 |
113 if ( isset( $_POST['permalink_structure'] ) ) { |
94 if ( isset( $_POST['permalink_structure'] ) ) { |
114 if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] ) { |
95 if ( isset( $_POST['selection'] ) && 'custom' !== $_POST['selection'] ) { |
115 $permalink_structure = $_POST['selection']; |
96 $permalink_structure = $_POST['selection']; |
116 } else { |
97 } else { |
117 $permalink_structure = $_POST['permalink_structure']; |
98 $permalink_structure = $_POST['permalink_structure']; |
118 } |
99 } |
119 |
100 |
127 } |
108 } |
128 |
109 |
129 $permalink_structure = sanitize_option( 'permalink_structure', $permalink_structure ); |
110 $permalink_structure = sanitize_option( 'permalink_structure', $permalink_structure ); |
130 |
111 |
131 $wp_rewrite->set_permalink_structure( $permalink_structure ); |
112 $wp_rewrite->set_permalink_structure( $permalink_structure ); |
|
113 |
|
114 $structure_updated = true; |
132 } |
115 } |
133 |
116 |
134 if ( isset( $_POST['category_base'] ) ) { |
117 if ( isset( $_POST['category_base'] ) ) { |
135 $category_base = $_POST['category_base']; |
118 $category_base = $_POST['category_base']; |
|
119 |
136 if ( ! empty( $category_base ) ) { |
120 if ( ! empty( $category_base ) ) { |
137 $category_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $category_base ) ); |
121 $category_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $category_base ) ); |
138 } |
122 } |
|
123 |
139 $wp_rewrite->set_category_base( $category_base ); |
124 $wp_rewrite->set_category_base( $category_base ); |
140 } |
125 } |
141 |
126 |
142 if ( isset( $_POST['tag_base'] ) ) { |
127 if ( isset( $_POST['tag_base'] ) ) { |
143 $tag_base = $_POST['tag_base']; |
128 $tag_base = $_POST['tag_base']; |
|
129 |
144 if ( ! empty( $tag_base ) ) { |
130 if ( ! empty( $tag_base ) ) { |
145 $tag_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $tag_base ) ); |
131 $tag_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $tag_base ) ); |
146 } |
132 } |
|
133 |
147 $wp_rewrite->set_tag_base( $tag_base ); |
134 $wp_rewrite->set_tag_base( $tag_base ); |
148 } |
135 } |
149 |
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(); |
|
159 |
|
160 if ( $structure_updated ) { |
150 $message = __( 'Permalink structure updated.' ); |
161 $message = __( 'Permalink structure updated.' ); |
151 |
162 |
152 if ( $iis7_permalinks ) { |
163 if ( ! is_multisite() && $permalink_structure && ! $using_index_permalinks ) { |
153 if ( $permalink_structure && ! $using_index_permalinks && ! $writable ) { |
164 if ( $iis7_permalinks ) { |
|
165 if ( ! $writable ) { |
|
166 $message = sprintf( |
|
167 /* translators: %s: web.config */ |
|
168 __( 'You should update your %s file now.' ), |
|
169 '<code>web.config</code>' |
|
170 ); |
|
171 } else { |
|
172 $message = sprintf( |
|
173 /* translators: %s: web.config */ |
|
174 __( 'Permalink structure updated. Remove write access on %s file now!' ), |
|
175 '<code>web.config</code>' |
|
176 ); |
|
177 } |
|
178 } elseif ( ! $is_nginx && $htaccess_update_required && ! $writable ) { |
154 $message = sprintf( |
179 $message = sprintf( |
155 /* translators: %s: web.config */ |
180 /* translators: %s: .htaccess */ |
156 __( 'You should update your %s file now.' ), |
181 __( 'You should update your %s file now.' ), |
157 '<code>web.config</code>' |
182 '<code>.htaccess</code>' |
158 ); |
|
159 } elseif ( $permalink_structure && ! $using_index_permalinks && $writable ) { |
|
160 $message = sprintf( |
|
161 /* translators: %s: web.config */ |
|
162 __( 'Permalink structure updated. Remove write access on %s file now!' ), |
|
163 '<code>web.config</code>' |
|
164 ); |
183 ); |
165 } |
184 } |
166 } elseif ( ! $is_nginx && $permalink_structure && ! $using_index_permalinks && ! $writable && $update_required ) { |
|
167 $message = sprintf( |
|
168 /* translators: %s: .htaccess */ |
|
169 __( 'You should update your %s file now.' ), |
|
170 '<code>.htaccess</code>' |
|
171 ); |
|
172 } |
185 } |
173 |
186 |
174 if ( ! get_settings_errors() ) { |
187 if ( ! get_settings_errors() ) { |
175 add_settings_error( 'general', 'settings_updated', $message, 'success' ); |
188 add_settings_error( 'general', 'settings_updated', $message, 'success' ); |
176 } |
189 } |
342 <?php |
355 <?php |
343 if ( $iis7_permalinks ) : |
356 if ( $iis7_permalinks ) : |
344 if ( isset( $_POST['submit'] ) && $permalink_structure && ! $using_index_permalinks && ! $writable ) : |
357 if ( isset( $_POST['submit'] ) && $permalink_structure && ! $using_index_permalinks && ! $writable ) : |
345 if ( file_exists( $home_path . 'web.config' ) ) : |
358 if ( file_exists( $home_path . 'web.config' ) ) : |
346 ?> |
359 ?> |
347 <p> |
360 <p id="iis-description-a"> |
348 <?php |
361 <?php |
349 printf( |
362 printf( |
350 /* translators: 1: web.config, 2: Documentation URL, 3: CTRL + a, 4: Element code. */ |
363 /* translators: 1: web.config, 2: Documentation URL, 3: CTRL + a, 4: Element code. */ |
351 __( 'If your %1$s file was <a href="%2$s">writable</a>, we could do this automatically, but it isn’t so this is the url rewrite rule you should have in your %1$s file. Click in the field and press %3$s to select all. Then insert this rule inside of the %4$s element in %1$s file.' ), |
364 __( 'If your %1$s file was <a href="%2$s">writable</a>, we could do this automatically, but it isn’t so this is the url rewrite rule you should have in your %1$s file. Click in the field and press %3$s to select all. Then insert this rule inside of the %4$s element in %1$s file.' ), |
352 '<code>web.config</code>', |
365 '<code>web.config</code>', |
368 '<code>web.config</code>' |
381 '<code>web.config</code>' |
369 ); |
382 ); |
370 ?> |
383 ?> |
371 </p> |
384 </p> |
372 <?php else : ?> |
385 <?php else : ?> |
373 <p> |
386 <p id="iis-description-b"> |
374 <?php |
387 <?php |
375 printf( |
388 printf( |
376 /* translators: 1: Documentation URL, 2: web.config, 3: CTRL + a */ |
389 /* translators: 1: Documentation URL, 2: web.config, 3: CTRL + a */ |
377 __( 'If the root directory of your site was <a href="%1$s">writable</a>, we could do this automatically, but it isn’t so this is the url rewrite rule you should have in your %2$s file. Create a new file, called %2$s in the root directory of your site. Click in the field and press %3$s to select all. Then insert this code into the %2$s file.' ), |
390 __( 'If the root directory of your site was <a href="%1$s">writable</a>, we could do this automatically, but it isn’t so this is the url rewrite rule you should have in your %2$s file. Create a new file, called %2$s in the root directory of your site. Click in the field and press %3$s to select all. Then insert this code into the %2$s file.' ), |
378 __( 'https://wordpress.org/support/article/changing-file-permissions/' ), |
391 __( 'https://wordpress.org/support/article/changing-file-permissions/' ), |
398 <?php endif; ?> |
411 <?php endif; ?> |
399 <?php elseif ( $is_nginx ) : ?> |
412 <?php elseif ( $is_nginx ) : ?> |
400 <p><?php _e( '<a href="https://wordpress.org/support/article/nginx/">Documentation on Nginx configuration</a>.' ); ?></p> |
413 <p><?php _e( '<a href="https://wordpress.org/support/article/nginx/">Documentation on Nginx configuration</a>.' ); ?></p> |
401 <?php |
414 <?php |
402 else : |
415 else : |
403 if ( $permalink_structure && ! $using_index_permalinks && ! $writable && $update_required ) : |
416 if ( $permalink_structure && ! $using_index_permalinks && ! $writable && $htaccess_update_required ) : |
404 ?> |
417 ?> |
405 <p> |
418 <p id="htaccess-description"> |
406 <?php |
419 <?php |
407 printf( |
420 printf( |
408 /* translators: 1: .htaccess, 2: Documentation URL, 3: CTRL + a */ |
421 /* translators: 1: .htaccess, 2: Documentation URL, 3: CTRL + a */ |
409 __( 'If your %1$s file was <a href="%2$s">writable</a>, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your %1$s file. Click in the field and press %3$s to select all.' ), |
422 __( 'If your %1$s file was <a href="%2$s">writable</a>, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your %1$s file. Click in the field and press %3$s to select all.' ), |
410 '<code>.htaccess</code>', |
423 '<code>.htaccess</code>', |