48 ); |
48 ); |
49 |
49 |
50 get_current_screen()->set_help_sidebar( |
50 get_current_screen()->set_help_sidebar( |
51 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
51 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
52 '<p>' . __( '<a href="https://developer.wordpress.org/themes/">Documentation on Theme Development</a>' ) . '</p>' . |
52 '<p>' . __( '<a href="https://developer.wordpress.org/themes/">Documentation on Theme Development</a>' ) . '</p>' . |
53 '<p>' . __( '<a href="https://wordpress.org/support/article/appearance-editor-screen/">Documentation on Editing Themes</a>' ) . '</p>' . |
53 '<p>' . __( '<a href="https://wordpress.org/documentation/article/appearance-theme-file-editor-screen/">Documentation on Editing Themes</a>' ) . '</p>' . |
54 '<p>' . __( '<a href="https://wordpress.org/support/article/editing-files/">Documentation on Editing Files</a>' ) . '</p>' . |
54 '<p>' . __( '<a href="https://developer.wordpress.org/advanced-administration/wordpress/edit-files/">Documentation on Editing Files</a>' ) . '</p>' . |
55 '<p>' . __( '<a href="https://developer.wordpress.org/themes/basics/template-tags/">Documentation on Template Tags</a>' ) . '</p>' . |
55 '<p>' . __( '<a href="https://developer.wordpress.org/themes/basics/template-tags/">Documentation on Template Tags</a>' ) . '</p>' . |
56 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
56 '<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>' |
57 ); |
57 ); |
58 |
58 |
59 wp_reset_vars( array( 'action', 'error', 'file', 'theme' ) ); |
59 $action = ! empty( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : ''; |
|
60 $theme = ! empty( $_REQUEST['theme'] ) ? sanitize_text_field( $_REQUEST['theme'] ) : ''; |
|
61 $file = ! empty( $_REQUEST['file'] ) ? sanitize_text_field( $_REQUEST['file'] ) : ''; |
|
62 $error = ! empty( $_REQUEST['error'] ); |
60 |
63 |
61 if ( $theme ) { |
64 if ( $theme ) { |
62 $stylesheet = $theme; |
65 $stylesheet = $theme; |
63 } else { |
66 } else { |
64 $stylesheet = get_stylesheet(); |
67 $stylesheet = get_stylesheet(); |
159 $content = $posted_content; |
162 $content = $posted_content; |
160 } elseif ( ! $error && filesize( $file ) > 0 ) { |
163 } elseif ( ! $error && filesize( $file ) > 0 ) { |
161 $f = fopen( $file, 'r' ); |
164 $f = fopen( $file, 'r' ); |
162 $content = fread( $f, filesize( $file ) ); |
165 $content = fread( $f, filesize( $file ) ); |
163 |
166 |
164 if ( '.php' === substr( $file, strrpos( $file, '.' ) ) ) { |
167 if ( str_ends_with( $file, '.php' ) ) { |
165 $functions = wp_doc_link_parse( $content ); |
168 $functions = wp_doc_link_parse( $content ); |
166 |
169 |
167 $docs_select = '<select name="docs-list" id="docs-list">'; |
170 if ( ! empty( $functions ) ) { |
168 $docs_select .= '<option value="">' . esc_attr__( 'Function Name…' ) . '</option>'; |
171 $docs_select = '<select name="docs-list" id="docs-list">'; |
169 foreach ( $functions as $function ) { |
172 $docs_select .= '<option value="">' . esc_html__( 'Function Name…' ) . '</option>'; |
170 $docs_select .= '<option value="' . esc_attr( urlencode( $function ) ) . '">' . htmlspecialchars( $function ) . '()</option>'; |
173 |
|
174 foreach ( $functions as $function ) { |
|
175 $docs_select .= '<option value="' . esc_attr( $function ) . '">' . esc_html( $function ) . '()</option>'; |
|
176 } |
|
177 |
|
178 $docs_select .= '</select>'; |
171 } |
179 } |
172 $docs_select .= '</select>'; |
|
173 } |
180 } |
174 |
181 |
175 $content = esc_textarea( $content ); |
182 $content = esc_textarea( $content ); |
176 } |
183 } |
177 |
184 |
183 } |
190 } |
184 ?> |
191 ?> |
185 <div class="wrap"> |
192 <div class="wrap"> |
186 <h1><?php echo esc_html( $title ); ?></h1> |
193 <h1><?php echo esc_html( $title ); ?></h1> |
187 |
194 |
188 <?php if ( isset( $_GET['a'] ) ) : ?> |
195 <?php |
189 <div id="message" class="updated notice is-dismissible"> |
196 if ( isset( $_GET['a'] ) ) { |
190 <p><?php _e( 'File edited successfully.' ); ?></p> |
197 wp_admin_notice( |
191 </div> |
198 __( 'File edited successfully.' ), |
192 <?php elseif ( is_wp_error( $edit_error ) ) : ?> |
199 array( |
193 <div id="message" class="notice notice-error"> |
200 'id' => 'message', |
194 <p><?php _e( 'There was an error while trying to update the file. You may need to fix something and try updating again.' ); ?></p> |
201 'dismissible' => true, |
195 <pre><?php echo esc_html( $edit_error->get_error_message() ? $edit_error->get_error_message() : $edit_error->get_error_code() ); ?></pre> |
202 'additional_classes' => array( 'updated' ), |
196 </div> |
203 ) |
197 <?php endif; ?> |
204 ); |
198 |
205 } elseif ( is_wp_error( $edit_error ) ) { |
199 <?php if ( preg_match( '/\.css$/', $file ) && ! wp_is_block_theme() && current_user_can( 'customize' ) ) : ?> |
206 $error_code = esc_html( $edit_error->get_error_message() ? $edit_error->get_error_message() : $edit_error->get_error_code() ); |
200 <div id="message" class="notice-info notice"> |
207 $message = '<p>' . __( 'There was an error while trying to update the file. You may need to fix something and try updating again.' ) . '</p> |
201 <p><strong><?php _e( 'Did you know?' ); ?></strong></p> |
208 <pre>' . $error_code . '</pre>'; |
202 <p> |
209 wp_admin_notice( |
203 <?php |
210 $message, |
204 printf( |
211 array( |
205 /* translators: %s: Link to Custom CSS section in the Customizer. */ |
212 'type' => 'error', |
206 __( 'There is no need to change your CSS here — you can edit and live preview CSS changes in the <a href="%s">built-in CSS editor</a>.' ), |
213 'id' => 'message', |
207 esc_url( add_query_arg( 'autofocus[section]', 'custom_css', admin_url( 'customize.php' ) ) ) |
214 ) |
208 ); |
215 ); |
209 ?> |
216 } |
210 </p> |
217 |
211 </div> |
218 if ( preg_match( '/\.css$/', $file ) && ! wp_is_block_theme() && current_user_can( 'customize' ) ) { |
212 <?php endif; ?> |
219 $message = '<p><strong>' . __( 'Did you know?' ) . '</strong></p><p>' . sprintf( |
|
220 /* translators: %s: Link to Custom CSS section in the Customizer. */ |
|
221 __( 'There is no need to change your CSS here — you can edit and live preview CSS changes in the <a href="%s">built-in CSS editor</a>.' ), |
|
222 esc_url( add_query_arg( 'autofocus[section]', 'custom_css', admin_url( 'customize.php' ) ) ) |
|
223 ) . '</p>'; |
|
224 wp_admin_notice( |
|
225 $message, |
|
226 array( |
|
227 'type' => 'info', |
|
228 'id' => 'message', |
|
229 ) |
|
230 ); |
|
231 } |
|
232 ?> |
213 |
233 |
214 <div class="fileedit-sub"> |
234 <div class="fileedit-sub"> |
215 <div class="alignleft"> |
235 <div class="alignleft"> |
216 <h2> |
236 <h2> |
217 <?php |
237 <?php |
218 echo $theme->display( 'Name' ); |
238 echo $theme->display( 'Name' ); |
219 if ( $description ) { |
239 if ( $description ) { |
220 echo ': ' . $description;} |
240 echo ': ' . $description; |
|
241 } |
221 ?> |
242 ?> |
222 </h2> |
243 </h2> |
223 </div> |
244 </div> |
224 <div class="alignright"> |
245 <div class="alignright"> |
225 <form action="theme-editor.php" method="get"> |
246 <form action="theme-editor.php" method="get"> |
242 <br class="clear" /> |
263 <br class="clear" /> |
243 </div> |
264 </div> |
244 |
265 |
245 <?php |
266 <?php |
246 if ( $theme->errors() ) { |
267 if ( $theme->errors() ) { |
247 echo '<div class="error"><p><strong>' . __( 'This theme is broken.' ) . '</strong> ' . $theme->errors()->get_error_message() . '</p></div>'; |
268 wp_admin_notice( |
|
269 '<strong>' . __( 'This theme is broken.' ) . '</strong> ' . $theme->errors()->get_error_message(), |
|
270 array( |
|
271 'additional_classes' => array( 'error' ), |
|
272 ) |
|
273 ); |
248 } |
274 } |
249 ?> |
275 ?> |
250 |
276 |
251 <div id="templateside"> |
277 <div id="templateside"> |
252 <h2 id="theme-files-label"><?php _e( 'Theme Files' ); ?></h2> |
278 <h2 id="theme-files-label"><?php _e( 'Theme Files' ); ?></h2> |
291 |
322 |
292 <?php if ( ! empty( $functions ) ) : ?> |
323 <?php if ( ! empty( $functions ) ) : ?> |
293 <div id="documentation" class="hide-if-no-js"> |
324 <div id="documentation" class="hide-if-no-js"> |
294 <label for="docs-list"><?php _e( 'Documentation:' ); ?></label> |
325 <label for="docs-list"><?php _e( 'Documentation:' ); ?></label> |
295 <?php echo $docs_select; ?> |
326 <?php echo $docs_select; ?> |
296 <input disabled id="docs-lookup" type="button" class="button" value="<?php esc_attr_e( 'Look Up' ); ?>" onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_user_locale() ); ?>&version=<?php echo urlencode( get_bloginfo( 'version' ) ); ?>&redirect=true'); }" /> |
327 <input disabled id="docs-lookup" type="button" class="button" value="<?php esc_attr_e( 'Look Up' ); ?>" onclick="if ( '' !== jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_user_locale() ); ?>&version=<?php echo urlencode( get_bloginfo( 'version' ) ); ?>&redirect=true'); }" /> |
297 </div> |
328 </div> |
298 <?php endif; ?> |
329 <?php endif; ?> |
299 |
330 |
300 <div> |
331 <div> |
301 <div class="editor-notices"> |
332 <div class="editor-notices"> |
302 <?php if ( is_child_theme() && $theme->get_stylesheet() === get_template() ) : ?> |
333 <?php |
303 <div class="notice notice-warning inline"> |
334 if ( is_child_theme() && $theme->get_stylesheet() === get_template() ) : |
304 <p> |
335 $message = ( is_writable( $file ) ) ? '<strong>' . __( 'Caution:' ) . '</strong> ' : ''; |
305 <?php if ( is_writable( $file ) ) : ?> |
336 $message .= __( 'This is a file in your current parent theme.' ); |
306 <strong><?php _e( 'Caution:' ); ?></strong> |
337 wp_admin_notice( |
307 <?php endif; ?> |
338 $message, |
308 <?php _e( 'This is a file in your current parent theme.' ); ?> |
339 array( |
309 </p> |
340 'type' => 'warning', |
310 </div> |
341 'additional_classes' => array( 'inline' ), |
311 <?php endif; ?> |
342 ) |
|
343 ); |
|
344 endif; |
|
345 ?> |
312 </div> |
346 </div> |
313 <?php if ( is_writable( $file ) ) : ?> |
347 <?php |
|
348 if ( is_writable( $file ) ) { |
|
349 ?> |
314 <p class="submit"> |
350 <p class="submit"> |
315 <?php submit_button( __( 'Update File' ), 'primary', 'submit', false ); ?> |
351 <?php submit_button( __( 'Update File' ), 'primary', 'submit', false ); ?> |
316 <span class="spinner"></span> |
352 <span class="spinner"></span> |
317 </p> |
353 </p> |
318 <?php else : ?> |
354 <?php |
|
355 } else { |
|
356 ?> |
319 <p> |
357 <p> |
320 <?php |
358 <?php |
321 printf( |
359 printf( |
322 /* translators: %s: Documentation URL. */ |
360 /* translators: %s: Documentation URL. */ |
323 __( 'You need to make this file writable before you can save your changes. See <a href="%s">Changing File Permissions</a> for more information.' ), |
361 __( 'You need to make this file writable before you can save your changes. See <a href="%s">Changing File Permissions</a> for more information.' ), |
324 __( 'https://wordpress.org/support/article/changing-file-permissions/' ) |
362 __( 'https://developer.wordpress.org/advanced-administration/server/file-permissions/' ) |
325 ); |
363 ); |
326 ?> |
364 ?> |
327 </p> |
365 </p> |
328 <?php endif; ?> |
366 <?php |
|
367 } |
|
368 ?> |
329 </div> |
369 </div> |
330 |
370 |
331 <?php wp_print_file_editor_templates(); ?> |
371 <?php wp_print_file_editor_templates(); ?> |
332 </form> |
372 </form> |
333 <?php |
373 <?php |
335 ?> |
375 ?> |
336 <br class="clear" /> |
376 <br class="clear" /> |
337 </div> |
377 </div> |
338 <?php |
378 <?php |
339 $dismissed_pointers = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); |
379 $dismissed_pointers = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); |
340 if ( ! in_array( 'theme_editor_notice', $dismissed_pointers, true ) ) : |
380 if ( ! in_array( 'theme_editor_notice', $dismissed_pointers, true ) ) { |
341 // Get a back URL. |
381 // Get a back URL. |
342 $referer = wp_get_referer(); |
382 $referer = wp_get_referer(); |
343 |
383 |
344 $excluded_referer_basenames = array( 'theme-editor.php', 'wp-login.php' ); |
384 $excluded_referer_basenames = array( 'theme-editor.php', 'wp-login.php' ); |
345 |
385 |