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/includes/class-wp-screen.php

    r41978 r42343  
    109109         * The taxonomy associated with the screen, if any.
    110110         * The 'edit-tags.php?taxonomy=category' screen has a taxonomy of 'category'.
     111         *
    111112         * @since 3.3.0
    112113         * @var string
     
    130131        private $_help_sidebar = '';
    131132
    132         /**
     133        /**
    133134         * The accessible hidden headings and text associated with the screen, if any.
    134135         *
     
    192193         *
    193194         * @param string|WP_Screen $hook_name Optional. The hook name (also known as the hook suffix) used to determine the screen.
    194          *                                        Defaults to the current $hook_suffix global.
     195         *                                    Defaults to the current $hook_suffix global.
    195196         * @return WP_Screen Screen object.
    196197         */
     
    201202
    202203                $post_type = $taxonomy = null;
    203                 $in_admin = false;
    204                 $action = '';
    205 
    206                 if ( $hook_name )
     204                $in_admin  = false;
     205                $action    = '';
     206
     207                if ( $hook_name ) {
    207208                        $id = $hook_name;
    208                 else
     209                } else {
    209210                        $id = $GLOBALS['hook_suffix'];
     211                }
    210212
    211213                // For those pesky meta boxes.
    212214                if ( $hook_name && post_type_exists( $hook_name ) ) {
    213215                        $post_type = $id;
    214                         $id = 'post'; // changes later. ends up being $base.
     216                        $id        = 'post'; // changes later. ends up being $base.
    215217                } else {
    216                         if ( '.php' == substr( $id, -4 ) )
     218                        if ( '.php' == substr( $id, -4 ) ) {
    217219                                $id = substr( $id, 0, -4 );
     220                        }
    218221
    219222                        if ( 'post-new' == $id || 'link-add' == $id || 'media-new' == $id || 'user-new' == $id ) {
    220                                 $id = substr( $id, 0, -4 );
     223                                $id     = substr( $id, 0, -4 );
    221224                                $action = 'add';
    222225                        }
     
    225228                if ( ! $post_type && $hook_name ) {
    226229                        if ( '-network' == substr( $id, -8 ) ) {
    227                                 $id = substr( $id, 0, -8 );
     230                                $id       = substr( $id, 0, -8 );
    228231                                $in_admin = 'network';
    229232                        } elseif ( '-user' == substr( $id, -5 ) ) {
    230                                 $id = substr( $id, 0, -5 );
     233                                $id       = substr( $id, 0, -5 );
    231234                                $in_admin = 'user';
    232235                        }
     
    236239                                $maybe = substr( $id, 5 );
    237240                                if ( taxonomy_exists( $maybe ) ) {
    238                                         $id = 'edit-tags';
     241                                        $id       = 'edit-tags';
    239242                                        $taxonomy = $maybe;
    240243                                } elseif ( post_type_exists( $maybe ) ) {
    241                                         $id = 'edit';
     244                                        $id        = 'edit';
    242245                                        $post_type = $maybe;
    243246                                }
    244247                        }
    245248
    246                         if ( ! $in_admin )
     249                        if ( ! $in_admin ) {
    247250                                $in_admin = 'site';
     251                        }
    248252                } else {
    249                         if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN )
     253                        if ( defined( 'WP_NETWORK_ADMIN' ) && WP_NETWORK_ADMIN ) {
    250254                                $in_admin = 'network';
    251                         elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN )
     255                        } elseif ( defined( 'WP_USER_ADMIN' ) && WP_USER_ADMIN ) {
    252256                                $in_admin = 'user';
    253                         else
     257                        } else {
    254258                                $in_admin = 'site';
    255                 }
    256 
    257                 if ( 'index' == $id )
     259                        }
     260                }
     261
     262                if ( 'index' == $id ) {
    258263                        $id = 'dashboard';
    259                 elseif ( 'front' == $id )
     264                } elseif ( 'front' == $id ) {
    260265                        $in_admin = false;
     266                }
    261267
    262268                $base = $id;
     
    264270                // If this is the current screen, see if we can be more accurate for post types and taxonomies.
    265271                if ( ! $hook_name ) {
    266                         if ( isset( $_REQUEST['post_type'] ) )
     272                        if ( isset( $_REQUEST['post_type'] ) ) {
    267273                                $post_type = post_type_exists( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : false;
    268                         if ( isset( $_REQUEST['taxonomy'] ) )
     274                        }
     275                        if ( isset( $_REQUEST['taxonomy'] ) ) {
    269276                                $taxonomy = taxonomy_exists( $_REQUEST['taxonomy'] ) ? $_REQUEST['taxonomy'] : false;
     277                        }
    270278
    271279                        switch ( $base ) {
    272                                 case 'post' :
    273                                         if ( isset( $_GET['post'] ) )
     280                                case 'post':
     281                                        if ( isset( $_GET['post'] ) ) {
    274282                                                $post_id = (int) $_GET['post'];
    275                                         elseif ( isset( $_POST['post_ID'] ) )
     283                                        } elseif ( isset( $_POST['post_ID'] ) ) {
    276284                                                $post_id = (int) $_POST['post_ID'];
    277                                         else
     285                                        } else {
    278286                                                $post_id = 0;
     287                                        }
    279288
    280289                                        if ( $post_id ) {
    281290                                                $post = get_post( $post_id );
    282                                                 if ( $post )
     291                                                if ( $post ) {
    283292                                                        $post_type = $post->post_type;
     293                                                }
    284294                                        }
    285295                                        break;
    286                                 case 'edit-tags' :
    287                                 case 'term' :
    288                                         if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) )
     296                                case 'edit-tags':
     297                                case 'term':
     298                                        if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) ) {
    289299                                                $post_type = 'post';
     300                                        }
    290301                                        break;
    291302                                case 'upload':
     
    296307
    297308                switch ( $base ) {
    298                         case 'post' :
    299                                 if ( null === $post_type )
     309                        case 'post':
     310                                if ( null === $post_type ) {
    300311                                        $post_type = 'post';
     312                                }
    301313                                $id = $post_type;
    302314                                break;
    303                         case 'edit' :
    304                                 if ( null === $post_type )
     315                        case 'edit':
     316                                if ( null === $post_type ) {
    305317                                        $post_type = 'post';
     318                                }
    306319                                $id .= '-' . $post_type;
    307320                                break;
    308                         case 'edit-tags' :
    309                         case 'term' :
    310                                 if ( null === $taxonomy )
     321                        case 'edit-tags':
     322                        case 'term':
     323                                if ( null === $taxonomy ) {
    311324                                        $taxonomy = 'post_tag';
     325                                }
    312326                                // The edit-tags ID does not contain the post type. Look for it in the request.
    313327                                if ( null === $post_type ) {
    314328                                        $post_type = 'post';
    315                                         if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) )
     329                                        if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) {
    316330                                                $post_type = $_REQUEST['post_type'];
     331                                        }
    317332                                }
    318333
     
    331346                if ( isset( self::$_registry[ $id ] ) ) {
    332347                        $screen = self::$_registry[ $id ];
    333                         if ( $screen === get_current_screen() )
     348                        if ( $screen === get_current_screen() ) {
    334349                                return $screen;
     350                        }
    335351                } else {
    336                         $screen = new WP_Screen();
    337                         $screen->id     = $id;
     352                        $screen     = new WP_Screen();
     353                        $screen->id = $id;
    338354                }
    339355
     
    364380                global $current_screen, $taxnow, $typenow;
    365381                $current_screen = $this;
    366                 $taxnow = $this->taxonomy;
    367                 $typenow = $this->post_type;
     382                $taxnow         = $this->taxonomy;
     383                $typenow        = $this->post_type;
    368384
    369385                /**
     
    394410         */
    395411        public function in_admin( $admin = null ) {
    396                 if ( empty( $admin ) )
     412                if ( empty( $admin ) ) {
    397413                        return (bool) $this->in_admin;
     414                }
    398415
    399416                return ( $admin == $this->in_admin );
     
    423440         */
    424441        public function set_parentage( $parent_file ) {
    425                 $this->parent_file = $parent_file;
     442                $this->parent_file         = $parent_file;
    426443                list( $this->parent_base ) = explode( '?', $parent_file );
    427                 $this->parent_base = str_replace( '.php', '', $this->parent_base );
     444                $this->parent_base         = str_replace( '.php', '', $this->parent_base );
    428445        }
    429446
     
    483500         */
    484501        public function get_option( $option, $key = false ) {
    485                 if ( ! isset( $this->_options[ $option ] ) )
     502                if ( ! isset( $this->_options[ $option ] ) ) {
    486503                        return null;
     504                }
    487505                if ( $key ) {
    488                         if ( isset( $this->_options[ $option ][ $key ] ) )
     506                        if ( isset( $this->_options[ $option ][ $key ] ) ) {
    489507                                return $this->_options[ $option ][ $key ];
     508                        }
    490509                        return null;
    491510                }
     
    534553         */
    535554        public function get_help_tab( $id ) {
    536                 if ( ! isset( $this->_help_tabs[ $id ] ) )
     555                if ( ! isset( $this->_help_tabs[ $id ] ) ) {
    537556                        return null;
     557                }
    538558                return $this->_help_tabs[ $id ];
    539559        }
     
    564584                        'priority' => 10,
    565585                );
    566                 $args = wp_parse_args( $args, $defaults );
     586                $args     = wp_parse_args( $args, $defaults );
    567587
    568588                $args['id'] = sanitize_html_class( $args['id'] );
    569589
    570590                // Ensure we have an ID and title.
    571                 if ( ! $args['id'] || ! $args['title'] )
     591                if ( ! $args['id'] || ! $args['title'] ) {
    572592                        return;
     593                }
    573594
    574595                // Allows for overriding an existing tab with that ID.
     
    636657        }
    637658
    638         /**
     659        /**
    639660         * Get the accessible hidden headings and text used in the screen.
    640661         *
     
    686707                        'heading_list'       => __( 'Items list' ),
    687708                );
    688                 $content = wp_parse_args( $content, $defaults );
     709                $content  = wp_parse_args( $content, $defaults );
    689710
    690711                $this->_screen_reader_content = $content;
     
    735756                 * @param string    $screen_id Screen ID.
    736757                 * @param WP_Screen $this      Current WP_Screen instance.
    737                  *
    738758                 */
    739759                $old_help = apply_filters( 'contextual_help', $old_help, $this->id, $this );
     
    752772                         */
    753773                        $default_help = apply_filters( 'default_contextual_help', '' );
    754                         if ( $default_help )
     774                        if ( $default_help ) {
    755775                                $old_help = '<p>' . $default_help . '</p>';
     776                        }
    756777                }
    757778
    758779                if ( $old_help ) {
    759                         $this->add_help_tab( array(
    760                                 'id'      => 'old-contextual-help',
    761                                 'title'   => __('Overview'),
    762                                 'content' => $old_help,
    763                         ) );
     780                        $this->add_help_tab(
     781                                array(
     782                                        'id'      => 'old-contextual-help',
     783                                        'title'   => __( 'Overview' ),
     784                                        'content' => $old_help,
     785                                )
     786                        );
    764787                }
    765788
     
    767790
    768791                $help_class = 'hidden';
    769                 if ( ! $help_sidebar )
     792                if ( ! $help_sidebar ) {
    770793                        $help_class .= ' no-sidebar';
     794                }
    771795
    772796                // Time to render!
     
    774798                <div id="screen-meta" class="metabox-prefs">
    775799
    776                         <div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e('Contextual Help Tab'); ?>">
     800                        <div id="contextual-help-wrap" class="<?php echo esc_attr( $help_class ); ?>" tabindex="-1" aria-label="<?php esc_attr_e( 'Contextual Help Tab' ); ?>">
    777801                                <div id="contextual-help-back"></div>
    778802                                <div id="contextual-help-columns">
     
    807831                                                <?php
    808832                                                $classes = 'help-tab-content active';
    809                                                 foreach ( $this->get_help_tabs() as $tab ):
     833                                                foreach ( $this->get_help_tabs() as $tab ) :
    810834                                                        $panel_id = "tab-panel-{$tab['id']}";
    811835                                                        ?>
     
    817841
    818842                                                                // If it exists, fire tab callback.
    819                                                                 if ( ! empty( $tab['callback'] ) )
     843                                                                if ( ! empty( $tab['callback'] ) ) {
    820844                                                                        call_user_func_array( $tab['callback'], array( $this, $tab ) );
     845                                                                }
    821846                                                                ?>
    822847                                                        </div>
     
    845870                $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this );
    846871
    847                 if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) )
    848                         $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) );
     872                if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) ) {
     873                        $this->add_option( 'layout_columns', array( 'max' => $columns[ $this->id ] ) );
     874                }
    849875
    850876                if ( $this->get_option( 'layout_columns' ) ) {
    851                         $this->columns = (int) get_user_option("screen_layout_$this->id");
    852 
    853                         if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) )
     877                        $this->columns = (int) get_user_option( "screen_layout_$this->id" );
     878
     879                        if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) ) {
    854880                                $this->columns = $this->get_option( 'layout_columns', 'default' );
    855                 }
    856                 $GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat.
     881                        }
     882                }
     883                $GLOBALS['screen_layout_columns'] = $this->columns; // Set the global for back-compat.
    857884
    858885                // Add screen options
    859                 if ( $this->show_screen_options() )
     886                if ( $this->show_screen_options() ) {
    860887                        $this->render_screen_options();
     888                }
    861889                ?>
    862890                </div>
    863891                <?php
    864                 if ( ! $this->get_help_tabs() && ! $this->show_screen_options() )
     892                if ( ! $this->get_help_tabs() && ! $this->show_screen_options() ) {
    865893                        return;
     894                }
    866895                ?>
    867896                <div id="screen-meta-links">
     
    870899                        <button type="button" id="contextual-help-link" class="button show-settings" aria-controls="contextual-help-wrap" aria-expanded="false"><?php _e( 'Help' ); ?></button>
    871900                        </div>
    872                 <?php endif;
    873                 if ( $this->show_screen_options() ) : ?>
     901                <?php
     902                endif;
     903if ( $this->show_screen_options() ) :
     904                ?>
    874905                        <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle">
    875906                        <button type="button" id="show-settings-link" class="button show-settings" aria-controls="screen-options-wrap" aria-expanded="false"><?php _e( 'Screen Options' ); ?></button>
     
    881912
    882913        /**
    883          *
    884914         * @global array $wp_meta_boxes
    885915         *
     
    889919                global $wp_meta_boxes;
    890920
    891                 if ( is_bool( $this->_show_screen_options ) )
     921                if ( is_bool( $this->_show_screen_options ) ) {
    892922                        return $this->_show_screen_options;
     923                }
    893924
    894925                $columns = get_column_headers( $this );
     
    898929                switch ( $this->base ) {
    899930                        case 'widgets':
    900                                 $nonce = wp_create_nonce( 'widgets-access' );
    901                                 $this->_screen_settings = '<p><a id="access-on" href="widgets.php?widgets-access=on&_wpnonce=' . urlencode( $nonce ) . '">' . __('Enable accessibility mode') . '</a><a id="access-off" href="widgets.php?widgets-access=off&_wpnonce=' . urlencode( $nonce ) . '">' . __('Disable accessibility mode') . "</a></p>\n";
     931                                $nonce                  = wp_create_nonce( 'widgets-access' );
     932                                $this->_screen_settings = '<p><a id="access-on" href="widgets.php?widgets-access=on&_wpnonce=' . urlencode( $nonce ) . '">' . __( 'Enable accessibility mode' ) . '</a><a id="access-off" href="widgets.php?widgets-access=off&_wpnonce=' . urlencode( $nonce ) . '">' . __( 'Disable accessibility mode' ) . "</a></p>\n";
    902933                                break;
    903                         case 'post' :
    904                                 $expand = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">';
    905                                 $expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />';
    906                                 $expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></fieldset>';
     934                        case 'post':
     935                                $expand                 = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">';
     936                                $expand                .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />';
     937                                $expand                .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></fieldset>';
    907938                                $this->_screen_settings = $expand;
    908939                                break;
     
    925956                $this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this );
    926957
    927                 if ( $this->_screen_settings || $this->_options )
     958                if ( $this->_screen_settings || $this->_options ) {
    928959                        $show_screen = true;
     960                }
    929961
    930962                /**
     
    951983         */
    952984        public function render_screen_options( $options = array() ) {
    953                 $options = wp_parse_args( $options, array(
    954                         'wrap' => true,
    955                 ) );
     985                $options = wp_parse_args(
     986                        $options, array(
     987                                'wrap' => true,
     988                        )
     989                );
    956990
    957991                $wrapper_start = $wrapper_end = $form_start = $form_end = '';
     
    960994                if ( $options['wrap'] ) {
    961995                        $wrapper_start = '<div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="' . esc_attr__( 'Screen Options Tab' ) . '">';
    962                         $wrapper_end = '</div>';
     996                        $wrapper_end   = '</div>';
    963997                }
    964998
     
    9661000                if ( 'widgets' !== $this->base ) {
    9671001                        $form_start = "\n<form id='adv-settings' method='post'>\n";
    968                         $form_end = "\n" . wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false, false ) . "\n</form>\n";
     1002                        $form_end   = "\n" . wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false, false ) . "\n</form>\n";
    9691003                }
    9701004
     
    10151049                        meta_box_prefs( $this );
    10161050
    1017                         if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) {
    1018                                 if ( isset( $_GET['welcome'] ) ) {
    1019                                         $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
    1020                                         update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
    1021                                 } else {
    1022                                         $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
    1023                                         if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) {
    1024                                                 $welcome_checked = false;
    1025                                         }
     1051                if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) {
     1052                        if ( isset( $_GET['welcome'] ) ) {
     1053                                $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
     1054                                update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
     1055                        } else {
     1056                                $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
     1057                                if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) {
     1058                                        $welcome_checked = false;
    10261059                                }
    1027                                 echo '<label for="wp_welcome_panel-hide">';
    1028                                 echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
    1029                                 echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
    1030                         }
     1060                        }
     1061                        echo '<label for="wp_welcome_panel-hide">';
     1062                        echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
     1063                        echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
     1064                }
    10311065                ?>
    10321066                </fieldset>
     
    10931127
    10941128                $screen_layout_columns = $this->get_columns();
    1095                 $num = $this->get_option( 'layout_columns', 'max' );
     1129                $num                   = $this->get_option( 'layout_columns', 'max' );
    10961130
    10971131                ?>
    10981132                <fieldset class='columns-prefs'>
    1099                 <legend class="screen-layout"><?php _e( 'Layout' ); ?></legend><?php
    1100                         for ( $i = 1; $i <= $num; ++$i ):
    1101                                 ?>
    1102                                 <label class="columns-prefs-<?php echo $i; ?>">
    1103                                         <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
    1104                                                 <?php checked( $screen_layout_columns, $i ); ?> />
    1105                                         <?php printf( _n( '%s column', '%s columns', $i ), number_format_i18n( $i ) ); ?>
     1133                <legend class="screen-layout"><?php _e( 'Layout' ); ?></legend>
     1134                                                                                                <?php
     1135                                                                                                for ( $i = 1; $i <= $num; ++$i ) :
     1136                                                                                                        ?>
     1137                                                                                                        <label class="columns-prefs-<?php echo $i; ?>">
     1138                                <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>'
     1139                                        <?php checked( $screen_layout_columns, $i ); ?> />
     1140                                <?php printf( _n( '%s column', '%s columns', $i ), number_format_i18n( $i ) ); ?>
    11061141                                </label>
    11071142                                <?php
    1108                         endfor; ?>
     1143                        endfor;
     1144                        ?>
    11091145                </fieldset>
    11101146                <?php
     
    11901226                }
    11911227
    1192                 $view_mode_post_types = get_post_types( array( 'hierarchical' => false, 'show_ui' => true ) );
     1228                $view_mode_post_types = get_post_types(
     1229                        array(
     1230                                'hierarchical' => false,
     1231                                'show_ui'      => true,
     1232                        )
     1233                );
    11931234
    11941235                /**
Note: See TracChangeset for help on using the changeset viewer.