Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/theme-editor.php

    r42247 r42343  
    1515}
    1616
    17 if ( !current_user_can('edit_themes') )
    18         wp_die('<p>'.__('Sorry, you are not allowed to edit templates for this site.').'</p>');
    19 
    20 $title = __("Edit Themes");
     17if ( ! current_user_can( 'edit_themes' ) ) {
     18        wp_die( '<p>' . __( 'Sorry, you are not allowed to edit templates for this site.' ) . '</p>' );
     19}
     20
     21$title       = __( 'Edit Themes' );
    2122$parent_file = 'themes.php';
    2223
    23 get_current_screen()->add_help_tab( array(
    24 'id'            => 'overview',
    25 'title'         => __('Overview'),
    26 'content'       =>
    27         '<p>' . __( 'You can use the Theme Editor to edit the individual CSS and PHP files which make up your theme.' ) . '</p>' .
    28         '<p>' . __( 'Begin by choosing a theme to edit from the dropdown menu and clicking the Select button. A list then appears of the theme&#8217;s template files. Clicking once on any file name causes the file to appear in the large Editor box.' ) . '</p>' .
    29         '<p>' . __( 'For PHP files, you can use the Documentation dropdown to select from functions recognized in that file. Look Up takes you to a web page with reference material about that particular function.' ) . '</p>' .
    30         '<p id="editor-keyboard-trap-help-1">' . __( 'When using a keyboard to navigate:' ) . '</p>' .
    31         '<ul>' .
    32         '<li id="editor-keyboard-trap-help-2">' . __( 'In the editing area, the Tab key enters a tab character.' ) . '</li>' .
    33         '<li id="editor-keyboard-trap-help-3">' . __( 'To move away from this area, press the Esc key followed by the Tab key.' ) . '</li>' .
    34         '<li id="editor-keyboard-trap-help-4">' . __( 'Screen reader users: when in forms mode, you may need to press the Esc key twice.' ) . '</li>' .
    35         '</ul>' .
    36         '<p>' . __( 'After typing in your edits, click Update File.' ) . '</p>' .
    37         '<p>' . __( '<strong>Advice:</strong> think very carefully about your site crashing if you are live-editing the theme currently in use.' ) . '</p>' .
    38         /* translators: %s: link to codex article about child themes */
    39         '<p>' . sprintf( __( 'Upgrading to a newer version of the same theme will override changes made here. To avoid this, consider creating a <a href="%s">child theme</a> instead.' ), __( 'https://codex.wordpress.org/Child_Themes' ) ) . '</p>' .
    40         ( is_network_admin() ? '<p>' . __( 'Any edits to files from this screen will be reflected on all sites in the network.' ) . '</p>' : '' ),
    41 ) );
     24get_current_screen()->add_help_tab(
     25        array(
     26                'id'      => 'overview',
     27                'title'   => __( 'Overview' ),
     28                'content' =>
     29                                 '<p>' . __( 'You can use the Theme Editor to edit the individual CSS and PHP files which make up your theme.' ) . '</p>' .
     30                                 '<p>' . __( 'Begin by choosing a theme to edit from the dropdown menu and clicking the Select button. A list then appears of the theme&#8217;s template files. Clicking once on any file name causes the file to appear in the large Editor box.' ) . '</p>' .
     31                                 '<p>' . __( 'For PHP files, you can use the Documentation dropdown to select from functions recognized in that file. Look Up takes you to a web page with reference material about that particular function.' ) . '</p>' .
     32                                 '<p id="editor-keyboard-trap-help-1">' . __( 'When using a keyboard to navigate:' ) . '</p>' .
     33                                 '<ul>' .
     34                                 '<li id="editor-keyboard-trap-help-2">' . __( 'In the editing area, the Tab key enters a tab character.' ) . '</li>' .
     35                                 '<li id="editor-keyboard-trap-help-3">' . __( 'To move away from this area, press the Esc key followed by the Tab key.' ) . '</li>' .
     36                                 '<li id="editor-keyboard-trap-help-4">' . __( 'Screen reader users: when in forms mode, you may need to press the Esc key twice.' ) . '</li>' .
     37                                 '</ul>' .
     38                                 '<p>' . __( 'After typing in your edits, click Update File.' ) . '</p>' .
     39                                 '<p>' . __( '<strong>Advice:</strong> think very carefully about your site crashing if you are live-editing the theme currently in use.' ) . '</p>' .
     40                                 /* translators: %s: link to codex article about child themes */
     41                                 '<p>' . sprintf( __( 'Upgrading to a newer version of the same theme will override changes made here. To avoid this, consider creating a <a href="%s">child theme</a> instead.' ), __( 'https://codex.wordpress.org/Child_Themes' ) ) . '</p>' .
     42                                 ( is_network_admin() ? '<p>' . __( 'Any edits to files from this screen will be reflected on all sites in the network.' ) . '</p>' : '' ),
     43        )
     44);
    4245
    4346get_current_screen()->set_help_sidebar(
    44         '<p><strong>' . __('For more information:') . '</strong></p>' .
    45         '<p>' . __('<a href="https://codex.wordpress.org/Theme_Development">Documentation on Theme Development</a>') . '</p>' .
    46         '<p>' . __('<a href="https://codex.wordpress.org/Using_Themes">Documentation on Using Themes</a>') . '</p>' .
    47         '<p>' . __('<a href="https://codex.wordpress.org/Editing_Files">Documentation on Editing Files</a>') . '</p>' .
    48         '<p>' . __('<a href="https://codex.wordpress.org/Template_Tags">Documentation on Template Tags</a>') . '</p>' .
    49         '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
     47        '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
     48        '<p>' . __( '<a href="https://codex.wordpress.org/Theme_Development">Documentation on Theme Development</a>' ) . '</p>' .
     49        '<p>' . __( '<a href="https://codex.wordpress.org/Using_Themes">Documentation on Using Themes</a>' ) . '</p>' .
     50        '<p>' . __( '<a href="https://codex.wordpress.org/Editing_Files">Documentation on Editing Files</a>' ) . '</p>' .
     51        '<p>' . __( '<a href="https://codex.wordpress.org/Template_Tags">Documentation on Template Tags</a>' ) . '</p>' .
     52        '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'
    5053);
    5154
    … …  
    7780                case 'php':
    7881                        $allowed_files += $theme->get_files( 'php', -1 );
    79                         $has_templates = ! empty( $allowed_files );
     82                        $has_templates  = ! empty( $allowed_files );
    8083                        break;
    8184                case 'css':
    82                         $style_files = $theme->get_files( 'css', -1 );
     85                        $style_files                = $theme->get_files( 'css', -1 );
    8386                        $allowed_files['style.css'] = $style_files['style.css'];
    84                         $allowed_files += $style_files;
     87                        $allowed_files             += $style_files;
    8588                        break;
    8689                default:
    … …  
    100103if ( empty( $file ) ) {
    101104        $relative_file = 'style.css';
    102         $file = $allowed_files['style.css'];
     105        $file          = $allowed_files['style.css'];
    103106} else {
    104107        $relative_file = wp_unslash( $file );
    105         $file = $theme->get_stylesheet_directory() . '/' . $relative_file;
     108        $file          = $theme->get_stylesheet_directory() . '/' . $relative_file;
    106109}
    107110
    … …  
    109112
    110113// Handle fallback editing of file when JavaScript is not available.
    111 $edit_error = null;
     114$edit_error     = null;
    112115$posted_content = null;
    113116if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
    … …  
    119122                }
    120123        } else {
    121                 wp_redirect( add_query_arg(
    122                         array(
    123                                 'a' => 1, // This means "success" for some reason.
    124                                 'theme' => $stylesheet,
    125                                 'file' => $relative_file,
    126                         ),
    127                         admin_url( 'theme-editor.php' )
    128                 ) );
     124                wp_redirect(
     125                        add_query_arg(
     126                                array(
     127                                        'a'     => 1, // This means "success" for some reason.
     128                                        'theme' => $stylesheet,
     129                                        'file'  => $relative_file,
     130                                ),
     131                                admin_url( 'theme-editor.php' )
     132                        )
     133                );
    129134                exit;
    130135        }
    … …  
    142147        update_recently_edited( $file );
    143148
    144         if ( ! is_file( $file ) )
     149        if ( ! is_file( $file ) ) {
    145150                $error = true;
     151        }
    146152
    147153        $content = '';
    … …  
    149155                $content = $posted_content;
    150156        } elseif ( ! $error && filesize( $file ) > 0 ) {
    151                 $f = fopen($file, 'r');
    152                 $content = fread($f, filesize($file));
     157                $f       = fopen( $file, 'r' );
     158                $content = fread( $f, filesize( $file ) );
    153159
    154160                if ( '.php' == substr( $file, strrpos( $file, '.' ) ) ) {
    155161                        $functions = wp_doc_link_parse( $content );
    156162
    157                         $docs_select = '<select name="docs-list" id="docs-list">';
     163                        $docs_select  = '<select name="docs-list" id="docs-list">';
    158164                        $docs_select .= '<option value="">' . esc_attr__( 'Function Name&hellip;' ) . '</option>';
    159165                        foreach ( $functions as $function ) {
    … …  
    166172        }
    167173
    168 $file_description = get_file_description( $relative_file );
    169 $file_show = array_search( $file, array_filter( $allowed_files ) );
    170 $description = esc_html( $file_description );
    171 if ( $file_description != $file_show ) {
    172         $description .= ' <span>(' . esc_html( $file_show ) . ')</span>';
    173 }
     174        $file_description = get_file_description( $relative_file );
     175        $file_show        = array_search( $file, array_filter( $allowed_files ) );
     176        $description      = esc_html( $file_description );
     177        if ( $file_description != $file_show ) {
     178                $description .= ' <span>(' . esc_html( $file_show ) . ')</span>';
     179        }
    174180?>
    175181<div class="wrap">
    … …  
    203209<div class="fileedit-sub">
    204210<div class="alignleft">
    205 <h2><?php echo $theme->display( 'Name' ); if ( $description ) echo ': ' . $description; ?></h2>
     211<h2>
     212<?php
     213echo $theme->display( 'Name' );
     214if ( $description ) {
     215        echo ': ' . $description;}
     216?>
     217</h2>
    206218</div>
    207219<div class="alignright">
    208220        <form action="theme-editor.php" method="get">
    209                 <strong><label for="theme"><?php _e('Select theme to edit:'); ?> </label></strong>
     221                <strong><label for="theme"><?php _e( 'Select theme to edit:' ); ?> </label></strong>
    210222                <select name="theme" id="theme">
    211223<?php
    212224foreach ( wp_get_themes( array( 'errors' => null ) ) as $a_stylesheet => $a_theme ) {
    213         if ( $a_theme->errors() && 'theme_no_stylesheet' == $a_theme->errors()->get_error_code() )
     225        if ( $a_theme->errors() && 'theme_no_stylesheet' == $a_theme->errors()->get_error_code() ) {
    214226                continue;
     227        }
    215228
    216229        $selected = $a_stylesheet == $stylesheet ? ' selected="selected"' : '';
    217         echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display('Name') . '</option>';
     230        echo "\n\t" . '<option value="' . esc_attr( $a_stylesheet ) . '"' . $selected . '>' . $a_theme->display( 'Name' ) . '</option>';
    218231}
    219232?>
    … …  
    225238</div>
    226239<?php
    227 if ( $theme->errors() )
     240if ( $theme->errors() ) {
    228241        echo '<div class="error"><p><strong>' . __( 'This theme is broken.' ) . '</strong> ' . $theme->errors()->get_error_message() . '</p></div>';
     242}
    229243?>
    230244<div id="templateside">
    … …  
    235249                                <?php
    236250                                /* translators: %s: link to edit parent theme */
    237                                 echo sprintf( __( 'This child theme inherits templates from a parent theme, %s.' ),
    238                                         sprintf( '<a href="%s">%s</a>',
     251                                echo sprintf(
     252                                        __( 'This child theme inherits templates from a parent theme, %s.' ),
     253                                        sprintf(
     254                                                '<a href="%s">%s</a>',
    239255                                                self_admin_url( 'theme-editor.php?theme=' . urlencode( $theme->get_template() ) ),
    240256                                                $theme->parent()->display( 'Name' )
    … …  
    252268</div>
    253269
    254 <?php if ( $error ) :
    255         echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
    256 else : ?>
     270<?php
     271if ( $error ) :
     272        echo '<div class="error"><p>' . __( 'Oops, no such file exists! Double check the name and try again, merci.' ) . '</p></div>';
     273else :
     274?>
    257275        <form name="template" id="template" action="theme-editor.php" method="post">
    258276                <?php wp_nonce_field( 'edit-theme_' . $stylesheet . '_' . $relative_file, 'nonce' ); ?>
    … …  
    266284        <?php if ( ! empty( $functions ) ) : ?>
    267285                <div id="documentation" class="hide-if-no-js">
    268                 <label for="docs-list"><?php _e('Documentation:') ?></label>
     286                <label for="docs-list"><?php _e( 'Documentation:' ); ?></label>
    269287                <?php echo $docs_select; ?>
    270                 <input 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() ) + '&amp;locale=<?php echo urlencode( get_user_locale() ) ?>&amp;version=<?php echo urlencode( get_bloginfo( 'version' ) ) ?>&amp;redirect=true'); }" />
     288                <input 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() ) + '&amp;locale=<?php echo urlencode( get_user_locale() ); ?>&amp;version=<?php echo urlencode( get_bloginfo( 'version' ) ); ?>&amp;redirect=true'); }" />
    271289                </div>
    272290        <?php endif; ?>
    … …  
    277295                                <div class="notice notice-warning inline">
    278296                                        <p>
    279                                                 <?php if ( is_writeable( $file ) ) { ?><strong><?php _e( 'Caution:' ); ?></strong><?php } ?>
     297                                                <?php
     298                                                if ( is_writeable( $file ) ) {
     299?>
     300<strong><?php _e( 'Caution:' ); ?></strong><?php } ?>
    280301                                                <?php _e( 'This is a file in your current parent theme.' ); ?>
    281302                                        </p>
    … …  
    289310                </p>
    290311        <?php else : ?>
    291                 <p><em><?php _e('You need to make this file writable before you can save your changes. See <a href="https://codex.wordpress.org/Changing_File_Permissions">the Codex</a> for more information.'); ?></em></p>
     312                <p><em><?php _e( 'You need to make this file writable before you can save your changes. See <a href="https://codex.wordpress.org/Changing_File_Permissions">the Codex</a> for more information.' ); ?></em></p>
    292313        <?php endif; ?>
    293314        </div>
    … …  
    303324if ( ! in_array( 'theme_editor_notice', $dismissed_pointers, true ) ) :
    304325        // Get a back URL
    305         $referer = wp_get_referer();
     326        $referer                    = wp_get_referer();
    306327        $excluded_referer_basenames = array( 'theme-editor.php', 'wp-login.php' );
    307328
    … …  
    339360endif; // editor warning notice
    340361
    341 include(ABSPATH . 'wp-admin/admin-footer.php' );
     362include( ABSPATH . 'wp-admin/admin-footer.php' );
Note: See TracChangeset for help on using the changeset viewer.