Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 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/plugin-editor.php

    r42201 r42343  
    1515}
    1616
    17 if ( !current_user_can('edit_plugins') )
    18     wp_die( __('Sorry, you are not allowed to edit plugins for this site.') );
    19 
    20 $title = __("Edit Plugins");
     17if ( ! current_user_can( 'edit_plugins' ) ) {
     18    wp_die( __( 'Sorry, you are not allowed to edit plugins for this site.' ) );
     19}
     20
     21$title       = __( 'Edit Plugins' );
    2122$parent_file = 'plugins.php';
    2223
     
    3536}
    3637
    37 $file = '';
     38$file   = '';
    3839$plugin = '';
    3940if ( isset( $_REQUEST['file'] ) ) {
     
    6768}
    6869
    69 $plugin_files = get_plugin_files($plugin);
     70$plugin_files = get_plugin_files( $plugin );
    7071
    7172if ( empty( $file ) ) {
     
    7374}
    7475
    75 $file = validate_file_to_edit($file, $plugin_files);
     76$file      = validate_file_to_edit( $file, $plugin_files );
    7677$real_file = WP_PLUGIN_DIR . '/' . $file;
    7778
    7879// Handle fallback editing of file when JavaScript is not available.
    79 $edit_error = null;
     80$edit_error     = null;
    8081$posted_content = null;
    8182if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
     
    8788        }
    8889    } else {
    89         wp_redirect( add_query_arg(
    90             array(
    91                 'a' => 1, // This means "success" for some reason.
    92                 'plugin' => $plugin,
    93                 'file' => $file,
    94             ),
    95             admin_url( 'plugin-editor.php' )
    96         ) );
     90        wp_redirect(
     91            add_query_arg(
     92                array(
     93                    'a'      => 1, // This means "success" for some reason.
     94                    'plugin' => $plugin,
     95                    'file'   => $file,
     96                ),
     97                admin_url( 'plugin-editor.php' )
     98            )
     99        );
    97100        exit;
    98101    }
     
    102105    $editable_extensions = wp_get_plugin_file_editable_extensions( $plugin );
    103106
    104     if ( ! is_file($real_file) ) {
    105         wp_die(sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.')));
    106     } else {
    107         // Get the extension of the file
    108         if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) {
    109             $ext = strtolower($matches[1]);
    110             // If extension is not in the acceptable list, skip it
    111             if ( !in_array( $ext, $editable_extensions) )
    112                 wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.')));
    113         }
    114     }
    115 
    116     get_current_screen()->add_help_tab( array(
    117     'id'        => 'overview',
    118     'title'     => __('Overview'),
    119     'content'   =>
    120         '<p>' . __('You can use the editor to make changes to any of your plugins&#8217; individual PHP files. Be aware that if you make changes, plugins updates will overwrite your customizations.') . '</p>' .
    121         '<p>' . __('Choose a plugin to edit from the dropdown menu and click the Select button. Click once on any file name to load it in the editor, and make your changes. Don&#8217;t forget to save your changes (Update File) when you&#8217;re finished.') . '</p>' .
    122         '<p>' . __('The Documentation menu below the editor lists the PHP functions recognized in the plugin file. Clicking Look Up takes you to a web page about that particular function.') . '</p>' .
    123         '<p id="editor-keyboard-trap-help-1">' . __( 'When using a keyboard to navigate:' ) . '</p>' .
    124         '<ul>' .
    125         '<li id="editor-keyboard-trap-help-2">' . __( 'In the editing area, the Tab key enters a tab character.' ) . '</li>' .
    126         '<li id="editor-keyboard-trap-help-3">' . __( 'To move away from this area, press the Esc key followed by the Tab key.' ) . '</li>' .
    127         '<li id="editor-keyboard-trap-help-4">' . __( 'Screen reader users: when in forms mode, you may need to press the Esc key twice.' ) . '</li>' .
    128         '</ul>' .
    129         '<p>' . __('If you want to make changes but don&#8217;t want them to be overwritten when the plugin is updated, you may be ready to think about writing your own plugin. For information on how to edit plugins, write your own from scratch, or just better understand their anatomy, check out the links below.') . '</p>' .
    130         ( is_network_admin() ? '<p>' . __('Any edits to files from this screen will be reflected on all sites in the network.') . '</p>' : '' )
    131     ) );
     107if ( ! is_file( $real_file ) ) {
     108    wp_die( sprintf( '<p>%s</p>', __( 'No such file exists! Double check the name and try again.' ) ) );
     109} else {
     110    // Get the extension of the file
     111    if ( preg_match( '/\.([^.]+)$/', $real_file, $matches ) ) {
     112        $ext = strtolower( $matches[1] );
     113        // If extension is not in the acceptable list, skip it
     114        if ( ! in_array( $ext, $editable_extensions ) ) {
     115            wp_die( sprintf( '<p>%s</p>', __( 'Files of this type are not editable.' ) ) );
     116        }
     117    }
     118}
     119
     120    get_current_screen()->add_help_tab(
     121        array(
     122            'id'      => 'overview',
     123            'title'   => __( 'Overview' ),
     124            'content' =>
     125                     '<p>' . __( 'You can use the editor to make changes to any of your plugins&#8217; individual PHP files. Be aware that if you make changes, plugins updates will overwrite your customizations.' ) . '</p>' .
     126                     '<p>' . __( 'Choose a plugin to edit from the dropdown menu and click the Select button. Click once on any file name to load it in the editor, and make your changes. Don&#8217;t forget to save your changes (Update File) when you&#8217;re finished.' ) . '</p>' .
     127                     '<p>' . __( 'The Documentation menu below the editor lists the PHP functions recognized in the plugin file. Clicking Look Up takes you to a web page about that particular function.' ) . '</p>' .
     128                     '<p id="editor-keyboard-trap-help-1">' . __( 'When using a keyboard to navigate:' ) . '</p>' .
     129                     '<ul>' .
     130                     '<li id="editor-keyboard-trap-help-2">' . __( 'In the editing area, the Tab key enters a tab character.' ) . '</li>' .
     131                     '<li id="editor-keyboard-trap-help-3">' . __( 'To move away from this area, press the Esc key followed by the Tab key.' ) . '</li>' .
     132                     '<li id="editor-keyboard-trap-help-4">' . __( 'Screen reader users: when in forms mode, you may need to press the Esc key twice.' ) . '</li>' .
     133                     '</ul>' .
     134                     '<p>' . __( 'If you want to make changes but don&#8217;t want them to be overwritten when the plugin is updated, you may be ready to think about writing your own plugin. For information on how to edit plugins, write your own from scratch, or just better understand their anatomy, check out the links below.' ) . '</p>' .
     135                     ( is_network_admin() ? '<p>' . __( 'Any edits to files from this screen will be reflected on all sites in the network.' ) . '</p>' : '' ),
     136        )
     137    );
    132138
    133139    get_current_screen()->set_help_sidebar(
    134         '<p><strong>' . __('For more information:') . '</strong></p>' .
    135         '<p>' . __('<a href="https://codex.wordpress.org/Plugins_Editor_Screen">Documentation on Editing Plugins</a>') . '</p>' .
    136         '<p>' . __('<a href="https://codex.wordpress.org/Writing_a_Plugin">Documentation on Writing Plugins</a>') . '</p>' .
    137         '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
     140        '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
     141        '<p>' . __( '<a href="https://codex.wordpress.org/Plugins_Editor_Screen">Documentation on Editing Plugins</a>' ) . '</p>' .
     142        '<p>' . __( '<a href="https://codex.wordpress.org/Writing_a_Plugin">Documentation on Writing Plugins</a>' ) . '</p>' .
     143        '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'
    138144    );
    139145
     
    145151    wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'wp.themePluginEditor.themeOrPlugin = "plugin";' ) );
    146152
    147     require_once(ABSPATH . 'wp-admin/admin-header.php');
    148 
    149     update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
     153    require_once( ABSPATH . 'wp-admin/admin-header.php' );
     154
     155    update_recently_edited( WP_PLUGIN_DIR . '/' . $file );
    150156
    151157    if ( ! empty( $posted_content ) ) {
     
    158164        $functions = wp_doc_link_parse( $content );
    159165
    160         if ( !empty($functions) ) {
    161             $docs_select = '<select name="docs-list" id="docs-list">';
     166        if ( ! empty( $functions ) ) {
     167            $docs_select  = '<select name="docs-list" id="docs-list">';
    162168            $docs_select .= '<option value="">' . __( 'Function Name&hellip;' ) . '</option>';
    163             foreach ( $functions as $function) {
     169            foreach ( $functions as $function ) {
    164170                $docs_select .= '<option value="' . esc_attr( $function ) . '">' . esc_html( $function ) . '()</option>';
    165171            }
     
    210216<div class="alignright">
    211217    <form action="plugin-editor.php" method="get">
    212         <strong><label for="plugin"><?php _e('Select plugin to edit:'); ?> </label></strong>
     218        <strong><label for="plugin"><?php _e( 'Select plugin to edit:' ); ?> </label></strong>
    213219        <select name="plugin" id="plugin">
    214220<?php
    215     foreach ( $plugins as $plugin_key => $a_plugin ) {
    216         $plugin_name = $a_plugin['Name'];
    217         if ( $plugin_key == $plugin )
    218             $selected = " selected='selected'";
    219         else
    220             $selected = '';
    221         $plugin_name = esc_attr($plugin_name);
    222         $plugin_key = esc_attr($plugin_key);
    223         echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>";
    224     }
     221foreach ( $plugins as $plugin_key => $a_plugin ) {
     222    $plugin_name = $a_plugin['Name'];
     223    if ( $plugin_key == $plugin ) {
     224        $selected = " selected='selected'";
     225    } else {
     226        $selected = '';
     227    }
     228    $plugin_name = esc_attr( $plugin_name );
     229    $plugin_key  = esc_attr( $plugin_key );
     230    echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>";
     231}
    225232?>
    226233        </select>
     
    237244    $plugin_editable_files = array();
    238245    foreach ( $plugin_files as $plugin_file ) {
    239         if ( preg_match('/\.([^.]+)$/', $plugin_file, $matches ) && in_array( $matches[1], $editable_extensions ) ) {
     246        if ( preg_match( '/\.([^.]+)$/', $plugin_file, $matches ) && in_array( $matches[1], $editable_extensions ) ) {
    240247            $plugin_editable_files[] = $plugin_file;
    241248        }
     
    258265            <input type="hidden" name="plugin" value="<?php echo esc_attr( $plugin ); ?>" />
    259266        </div>
    260         <?php if ( !empty( $docs_select ) ) : ?>
    261         <div id="documentation" class="hide-if-no-js"><label for="docs-list"><?php _e('Documentation:') ?></label> <?php echo $docs_select ?> <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'); }" /></div>
     267        <?php if ( ! empty( $docs_select ) ) : ?>
     268        <div id="documentation" class="hide-if-no-js"><label for="docs-list"><?php _e( 'Documentation:' ); ?></label> <?php echo $docs_select; ?> <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'); }" /></div>
    262269        <?php endif; ?>
    263 <?php if ( is_writeable($real_file) ) : ?>
     270<?php if ( is_writeable( $real_file ) ) : ?>
    264271    <div class="editor-notices">
    265272        <?php if ( in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) ) { ?>
    266273            <div class="notice notice-warning inline active-plugin-edit-warning">
    267             <p><?php _e('<strong>Warning:</strong> Making changes to active plugins is not recommended.'); ?></p>
     274            <p><?php _e( '<strong>Warning:</strong> Making changes to active plugins is not recommended.' ); ?></p>
    268275        </div>
    269276        <?php } ?>
     
    274281    </p>
    275282<?php else : ?>
    276     <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>
     283    <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>
    277284<?php endif; ?>
    278285<?php wp_print_file_editor_templates(); ?>
     
    284291if ( ! in_array( 'plugin_editor_notice', $dismissed_pointers, true ) ) :
    285292    // Get a back URL
    286     $referer = wp_get_referer();
     293    $referer                    = wp_get_referer();
    287294    $excluded_referer_basenames = array( 'plugin-editor.php', 'wp-login.php' );
    288295
     
    312319endif; // editor warning notice
    313320
    314 include(ABSPATH . "wp-admin/admin-footer.php");
     321include( ABSPATH . 'wp-admin/admin-footer.php' );
Note: See TracChangeset for help on using the changeset viewer.