Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 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-themes-list-table.php

    r41219 r42343  
    1919
    2020    protected $search_terms = array();
    21     public $features = array();
     21    public $features        = array();
    2222
    2323    /**
     
    3131     */
    3232    public function __construct( $args = array() ) {
    33         parent::__construct( array(
    34             'ajax' => true,
    35             'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
    36         ) );
    37     }
    38 
    39     /**
    40      *
     33        parent::__construct(
     34            array(
     35                'ajax'   => true,
     36                'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
     37            )
     38        );
     39    }
     40
     41    /**
    4142     * @return bool
    4243     */
     
    5152        $themes = wp_get_themes( array( 'allowed' => true ) );
    5253
    53         if ( ! empty( $_REQUEST['s'] ) )
     54        if ( ! empty( $_REQUEST['s'] ) ) {
    5455            $this->search_terms = array_unique( array_filter( array_map( 'trim', explode( ',', strtolower( wp_unslash( $_REQUEST['s'] ) ) ) ) ) );
    55 
    56         if ( ! empty( $_REQUEST['features'] ) )
     56        }
     57
     58        if ( ! empty( $_REQUEST['features'] ) ) {
    5759            $this->features = $_REQUEST['features'];
     60        }
    5861
    5962        if ( $this->search_terms || $this->features ) {
    6063            foreach ( $themes as $key => $theme ) {
    61                 if ( ! $this->search_theme( $theme ) )
     64                if ( ! $this->search_theme( $theme ) ) {
    6265                    unset( $themes[ $key ] );
     66                }
    6367            }
    6468        }
     
    6872
    6973        $per_page = 36;
    70         $page = $this->get_pagenum();
     74        $page     = $this->get_pagenum();
    7175
    7276        $start = ( $page - 1 ) * $per_page;
     
    7478        $this->items = array_slice( $themes, $start, $per_page, true );
    7579
    76         $this->set_pagination_args( array(
    77             'total_items' => count( $themes ),
    78             'per_page' => $per_page,
    79             'infinite_scroll' => true,
    80         ) );
     80        $this->set_pagination_args(
     81            array(
     82                'total_items'     => count( $themes ),
     83                'per_page'        => $per_page,
     84                'infinite_scroll' => true,
     85            )
     86        );
    8187    }
    8288
     
    116122     */
    117123    public function tablenav( $which = 'top' ) {
    118         if ( $this->get_pagination_arg( 'total_pages' ) <= 1 )
     124        if ( $this->get_pagination_arg( 'total_pages' ) <= 1 ) {
    119125            return;
     126        }
    120127        ?>
    121128        <div class="tablenav themes <?php echo $which; ?>">
     
    130137     */
    131138    public function display() {
    132         wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
     139        wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
    133140?>
    134141        <?php $this->tablenav( 'top' ); ?>
     
    143150
    144151    /**
    145      *
    146152     * @return array
    147153     */
     
    167173        $themes = $this->items;
    168174
    169         foreach ( $themes as $theme ):
    170             ?><div class="available-theme"><?php
     175        foreach ( $themes as $theme ) :
     176            ?>
     177            <div class="available-theme">
     178            <?php
    171179
    172180            $template   = $theme->get_template();
    173181            $stylesheet = $theme->get_stylesheet();
    174             $title      = $theme->display('Name');
    175             $version    = $theme->display('Version');
    176             $author     = $theme->display('Author');
    177 
    178             $activate_link = wp_nonce_url( "themes.php?action=activate&amp;template=" . urlencode( $template ) . "&amp;stylesheet=" . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet );
    179 
    180             $actions = array();
     182            $title      = $theme->display( 'Name' );
     183            $version    = $theme->display( 'Version' );
     184            $author     = $theme->display( 'Author' );
     185
     186            $activate_link = wp_nonce_url( 'themes.php?action=activate&amp;template=' . urlencode( $template ) . '&amp;stylesheet=' . urlencode( $stylesheet ), 'switch-theme_' . $stylesheet );
     187
     188            $actions             = array();
    181189            $actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="'
    182190                . esc_attr( sprintf( __( 'Activate &#8220;%s&#8221;' ), $title ) ) . '">' . __( 'Activate' ) . '</a>';
     
    187195            }
    188196
    189             if ( ! is_multisite() && current_user_can( 'delete_themes' ) )
     197            if ( ! is_multisite() && current_user_can( 'delete_themes' ) ) {
    190198                $actions['delete'] = '<a class="submitdelete deletion" href="' . wp_nonce_url( 'themes.php?action=delete&amp;stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet )
    191199                    . '" onclick="' . "return confirm( '" . esc_js( sprintf( __( "You are about to delete this theme '%s'\n  'Cancel' to stop, 'OK' to delete." ), $title ) )
    192200                    . "' );" . '">' . __( 'Delete' ) . '</a>';
     201            }
    193202
    194203            /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */
    195             $actions       = apply_filters( 'theme_action_links', $actions, $theme, 'all' );
     204            $actions = apply_filters( 'theme_action_links', $actions, $theme, 'all' );
    196205
    197206            /** This filter is documented in wp-admin/includes/class-wp-ms-themes-list-table.php */
     
    217226            <div class="action-links">
    218227                <ul>
    219                     <?php foreach ( $actions as $action ): ?>
     228                    <?php foreach ( $actions as $action ) : ?>
    220229                        <li><?php echo $action; ?></li>
    221230                    <?php endforeach; ?>
    222                     <li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e('Details') ?></a></li>
     231                    <li class="hide-if-no-js"><a href="#" class="theme-detail"><?php _e( 'Details' ); ?></a></li>
    223232                </ul>
    224233                <?php echo $delete_action; ?>
     
    228237
    229238            <div class="themedetaildiv hide-if-js">
    230                 <p><strong><?php _e('Version:'); ?></strong> <?php echo $version; ?></p>
    231                 <p><?php echo $theme->display('Description'); ?></p>
    232                 <?php if ( $theme->parent() ) {
    233                     printf( ' <p class="howto">' . __( 'This <a href="%1$s">child theme</a> requires its parent theme, %2$s.' ) . '</p>',
     239                <p><strong><?php _e( 'Version:' ); ?></strong> <?php echo $version; ?></p>
     240                <p><?php echo $theme->display( 'Description' ); ?></p>
     241                <?php
     242                if ( $theme->parent() ) {
     243                    printf(
     244                        ' <p class="howto">' . __( 'This <a href="%1$s">child theme</a> requires its parent theme, %2$s.' ) . '</p>',
    234245                        __( 'https://codex.wordpress.org/Child_Themes' ),
    235                         $theme->parent()->display( 'Name' ) );
    236                 } ?>
     246                        $theme->parent()->display( 'Name' )
     247                    );
     248                }
     249                ?>
    237250            </div>
    238251
     
    249262        // Search the features
    250263        foreach ( $this->features as $word ) {
    251             if ( ! in_array( $word, $theme->get('Tags') ) )
     264            if ( ! in_array( $word, $theme->get( 'Tags' ) ) ) {
    252265                return false;
     266            }
    253267        }
    254268
    255269        // Match all phrases
    256270        foreach ( $this->search_terms as $word ) {
    257             if ( in_array( $word, $theme->get('Tags') ) )
     271            if ( in_array( $word, $theme->get( 'Tags' ) ) ) {
    258272                continue;
     273            }
    259274
    260275            foreach ( array( 'Name', 'Description', 'Author', 'AuthorURI' ) as $header ) {
     
    265280            }
    266281
    267             if ( false !== stripos( $theme->get_stylesheet(), $word ) )
     282            if ( false !== stripos( $theme->get_stylesheet(), $word ) ) {
    268283                continue;
    269 
    270             if ( false !== stripos( $theme->get_template(), $word ) )
     284            }
     285
     286            if ( false !== stripos( $theme->get_template(), $word ) ) {
    271287                continue;
     288            }
    272289
    273290            return false;
     
    288305
    289306        $args = array(
    290             'search' => $search_string,
    291             'features' => $this->features,
    292             'paged' => $this->get_pagenum(),
     307            'search'      => $search_string,
     308            'features'    => $this->features,
     309            'paged'       => $this->get_pagenum(),
    293310            'total_pages' => ! empty( $this->_pagination_args['total_pages'] ) ? $this->_pagination_args['total_pages'] : 1,
    294311        );
    295312
    296         if ( is_array( $extra_args ) )
     313        if ( is_array( $extra_args ) ) {
    297314            $args = array_merge( $args, $extra_args );
     315        }
    298316
    299317        printf( "<script type='text/javascript'>var theme_list_args = %s;</script>\n", wp_json_encode( $args ) );
Note: See TracChangeset for help on using the changeset viewer.