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/includes/class-wp-media-list-table.php

    r41161 r42343  
    4343        $this->modes = array(
    4444            'list' => __( 'List View' ),
    45             'grid' => __( 'Grid View' )
     45            'grid' => __( 'Grid View' ),
    4646        );
    4747
    48         parent::__construct( array(
    49             'plural' => 'media',
    50             'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
    51         ) );
    52     }
    53 
    54     /**
    55      *
     48        parent::__construct(
     49            array(
     50                'plural' => 'media',
     51                'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
     52            )
     53        );
     54    }
     55
     56    /**
    5657     * @return bool
    5758     */
    5859    public function ajax_user_can() {
    59         return current_user_can('upload_files');
    60     }
    61 
    62     /**
    63      *
     60        return current_user_can( 'upload_files' );
     61    }
     62
     63    /**
    6464     * @global WP_Query $wp_query
    6565     * @global array    $post_mime_types
     
    7272        list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $_REQUEST );
    7373
    74         $this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter'];
    75 
    76         $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
    77 
    78         $this->set_pagination_args( array(
    79             'total_items' => $wp_query->found_posts,
    80             'total_pages' => $wp_query->max_num_pages,
    81             'per_page' => $wp_query->query_vars['posts_per_page'],
    82         ) );
     74        $this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter'];
     75
     76        $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
     77
     78        $this->set_pagination_args(
     79            array(
     80                'total_items' => $wp_query->found_posts,
     81                'total_pages' => $wp_query->max_num_pages,
     82                'per_page'    => $wp_query->query_vars['posts_per_page'],
     83            )
     84        );
    8385    }
    8486
     
    113115            );
    114116
    115             $type_links[$mime_type] = sprintf(
     117            $type_links[ $mime_type ] = sprintf(
    116118                '<option value="post_mime_type:%s"%s>%s</option>',
    117119                esc_attr( $mime_type ),
     
    122124        $type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '>' . __( 'Unattached' ) . '</option>';
    123125
    124         if ( $this->is_trash || ( defined( 'MEDIA_TRASH') && MEDIA_TRASH ) ) {
     126        if ( $this->is_trash || ( defined( 'MEDIA_TRASH' ) && MEDIA_TRASH ) ) {
    125127            $type_links['trash'] = sprintf(
    126128                '<option value="trash"%s>%s</option>',
     
    133135
    134136    /**
    135      *
    136137     * @return array
    137138     */
     
    141142            if ( $this->is_trash ) {
    142143                $actions['untrash'] = __( 'Restore' );
    143                 $actions['delete'] = __( 'Delete Permanently' );
     144                $actions['delete']  = __( 'Delete Permanently' );
    144145            } else {
    145146                $actions['trash'] = _x( 'Trash', 'verb' );
     
    149150        }
    150151
    151         if ( $this->detached )
     152        if ( $this->detached ) {
    152153            $actions['attach'] = __( 'Attach' );
     154        }
    153155
    154156        return $actions;
     
    165167        <div class="actions">
    166168<?php
    167         if ( ! is_singular() ) {
    168             if ( ! $this->is_trash ) {
    169                 $this->months_dropdown( 'attachment' );
    170             }
    171 
    172             /** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */
    173             do_action( 'restrict_manage_posts', $this->screen->post_type, $which );
    174 
    175             submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
    176         }
    177 
    178         if ( $this->is_trash && current_user_can( 'edit_others_posts' ) && $this->has_items() ) {
    179             submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
    180         } ?>
     169if ( ! is_singular() ) {
     170    if ( ! $this->is_trash ) {
     171        $this->months_dropdown( 'attachment' );
     172    }
     173
     174    /** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */
     175    do_action( 'restrict_manage_posts', $this->screen->post_type, $which );
     176
     177    submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
     178}
     179
     180if ( $this->is_trash && current_user_can( 'edit_others_posts' ) && $this->has_items() ) {
     181    submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
     182}
     183        ?>
    181184        </div>
    182185<?php
     
    184187
    185188    /**
    186      *
    187189     * @return string
    188190     */
    189191    public function current_action() {
    190         if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) )
     192        if ( isset( $_REQUEST['found_post_id'] ) && isset( $_REQUEST['media'] ) ) {
    191193            return 'attach';
    192 
    193         if ( isset( $_REQUEST['parent_post_id'] ) && isset( $_REQUEST['media'] ) )
     194        }
     195
     196        if ( isset( $_REQUEST['parent_post_id'] ) && isset( $_REQUEST['media'] ) ) {
    194197            return 'detach';
    195 
    196         if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
     198        }
     199
     200        if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) ) {
    197201            return 'delete_all';
     202        }
    198203
    199204        return parent::current_action();
     
    201206
    202207    /**
    203      *
    204208     * @return bool
    205209     */
     
    248252
    249253        // Back compat for pre-4.0 view links.
    250         if ( ! empty( $views ) ) {
    251             echo '<ul class="filter-links">';
    252             foreach ( $views as $class => $view ) {
    253                 echo "<li class='$class'>$view</li>";
    254             }
    255             echo '</ul>';
    256         }
     254if ( ! empty( $views ) ) {
     255    echo '<ul class="filter-links">';
     256    foreach ( $views as $class => $view ) {
     257        echo "<li class='$class'>$view</li>";
     258    }
     259    echo '</ul>';
     260}
    257261?>
    258262    </div>
     
    260264    <div class="search-form">
    261265        <label for="media-search-input" class="screen-reader-text"><?php esc_html_e( 'Search Media' ); ?></label>
    262         <input type="search" placeholder="<?php esc_attr_e( 'Search media items...' ) ?>" id="media-search-input" class="search" name="s" value="<?php _admin_search_query(); ?>"></div>
     266        <input type="search" placeholder="<?php esc_attr_e( 'Search media items...' ); ?>" id="media-search-input" class="search" name="s" value="<?php _admin_search_query(); ?>"></div>
    263267    </div>
    264268    <?php
     
    266270
    267271    /**
    268      *
    269272     * @return array
    270273     */
    271274    public function get_columns() {
    272         $posts_columns = array();
     275        $posts_columns       = array();
    273276        $posts_columns['cb'] = '<input type="checkbox" />';
    274277        /* translators: column name */
    275         $posts_columns['title'] = _x( 'File', 'column name' );
     278        $posts_columns['title']  = _x( 'File', 'column name' );
    276279        $posts_columns['author'] = __( 'Author' );
    277280
     
    302305
    303306        /* translators: column name */
    304         if ( !$this->detached ) {
     307        if ( ! $this->detached ) {
    305308            $posts_columns['parent'] = _x( 'Uploaded to', 'column name' );
    306             if ( post_type_supports( 'attachment', 'comments' ) )
     309            if ( post_type_supports( 'attachment', 'comments' ) ) {
    307310                $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>';
     311            }
    308312        }
    309313        /* translators: column name */
     
    322326
    323327    /**
    324      *
    325328     * @return array
    326329     */
     
    343346     */
    344347    public function column_cb( $post ) {
    345         if ( current_user_can( 'edit_post', $post->ID ) ) { ?>
    346             <label class="screen-reader-text" for="cb-select-<?php echo $post->ID; ?>"><?php
    347                 echo sprintf( __( 'Select %s' ), _draft_or_post_title() );
    348             ?></label>
     348        if ( current_user_can( 'edit_post', $post->ID ) ) {
     349        ?>
     350            <label class="screen-reader-text" for="cb-select-<?php echo $post->ID; ?>">
     351                                                                        <?php
     352                                                                        echo sprintf( __( 'Select %s' ), _draft_or_post_title() );
     353            ?>
     354            </label>
    349355            <input type="checkbox" name="media[]" id="cb-select-<?php echo $post->ID; ?>" value="<?php echo $post->ID; ?>" />
    350         <?php }
     356        <?php
     357        }
    351358    }
    352359
     
    361368        list( $mime ) = explode( '/', $post->post_mime_type );
    362369
    363         $title = _draft_or_post_title();
    364         $thumb = wp_get_attachment_image( $post->ID, array( 60, 60 ), true, array( 'alt' => '' ) );
     370        $title      = _draft_or_post_title();
     371        $thumb      = wp_get_attachment_image( $post->ID, array( 60, 60 ), true, array( 'alt' => '' ) );
    365372        $link_start = $link_end = '';
    366373
     
    380387            <?php
    381388            echo $link_start;
    382             if ( $thumb ) : ?>
     389            if ( $thumb ) :
     390            ?>
    383391                <span class="media-icon <?php echo sanitize_html_class( $mime . '-icon' ); ?>"><?php echo $thumb; ?></span>
    384             <?php endif;
     392            <?php
     393            endif;
    385394            echo $title . $link_end;
    386395            _media_states( $post );
     
    405414     */
    406415    public function column_author( $post ) {
    407         printf( '<a href="%s">%s</a>',
    408             esc_url( add_query_arg( array( 'author' => get_the_author_meta('ID') ), 'upload.php' ) ),
     416        printf(
     417            '<a href="%s">%s</a>',
     418            esc_url( add_query_arg( array( 'author' => get_the_author_meta( 'ID' ) ), 'upload.php' ) ),
    409419            get_the_author()
    410420        );
     
    434444        } else {
    435445            $m_time = $post->post_date;
    436             $time = get_post_time( 'G', true, $post, false );
     446            $time   = get_post_time( 'G', true, $post, false );
    437447            if ( ( abs( $t_diff = time() - $time ) ) < DAY_IN_SECONDS ) {
    438448                if ( $t_diff < 0 ) {
     
    466476
    467477        if ( $parent ) {
    468             $title = _draft_or_post_title( $post->post_parent );
     478            $title       = _draft_or_post_title( $post->post_parent );
    469479            $parent_type = get_post_type_object( $parent->post_type );
    470480
     
    472482?>
    473483                <strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>">
    474                     <?php echo $title ?></a></strong><?php
     484                    <?php echo $title; ?></a></strong>
     485                                <?php
    475486            } elseif ( $parent_type && current_user_can( 'read_post', $post->post_parent ) ) {
    476487?>
    477                 <strong><?php echo $title ?></strong><?php
     488                <strong><?php echo $title; ?></strong>
     489                                    <?php
    478490            } else {
    479491                _e( '(Private post)' );
    480492            }
    481493
    482             if ( $user_can_edit ):
    483                 $detach_url = add_query_arg( array(
    484                     'parent_post_id' => $post->post_parent,
    485                     'media[]' => $post->ID,
    486                     '_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] )
    487                 ), 'upload.php' );
     494            if ( $user_can_edit ) :
     495                $detach_url = add_query_arg(
     496                    array(
     497                        'parent_post_id' => $post->post_parent,
     498                        'media[]'        => $post->ID,
     499                        '_wpnonce'       => wp_create_nonce( 'bulk-' . $this->_args['plural'] ),
     500                    ), 'upload.php'
     501                );
    488502                printf(
    489503                    '<br /><a href="%s" class="hide-if-no-js detach-from-parent" aria-label="%s">%s</a>',
     
    495509            endif;
    496510        } else {
    497             _e( '(Unattached)' ); ?>
    498             <?php if ( $user_can_edit ) {
     511            _e( '(Unattached)' );
     512            ?>
     513            <?php
     514            if ( $user_can_edit ) {
    499515                $title = _draft_or_post_title( $post->post_parent );
    500516                printf(
     
    554570                $out = array();
    555571                foreach ( $terms as $t ) {
    556                     $posts_in_term_qv = array();
     572                    $posts_in_term_qv             = array();
    557573                    $posts_in_term_qv['taxonomy'] = $taxonomy;
    558                     $posts_in_term_qv['term'] = $t->slug;
    559 
    560                     $out[] = sprintf( '<a href="%s">%s</a>',
     574                    $posts_in_term_qv['term']     = $t->slug;
     575
     576                    $out[] = sprintf(
     577                        '<a href="%s">%s</a>',
    561578                        esc_url( add_query_arg( $posts_in_term_qv, 'upload.php' ) ),
    562579                        esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
     
    586603
    587604    /**
    588      *
    589605     * @global WP_Post $post
    590606     */
     
    597613        $this->comment_pending_count = get_pending_comments_num( $post_ids );
    598614
    599         add_filter( 'the_title','esc_html' );
    600 
    601         while ( have_posts() ) : the_post();
     615        add_filter( 'the_title', 'esc_html' );
     616
     617        while ( have_posts() ) :
     618            the_post();
    602619            if (
    603620                ( $this->is_trash && $post->post_status != 'trash' )
     
    655672                    );
    656673                } else {
    657                     $delete_ays = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : '';
     674                    $delete_ays        = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : '';
    658675                    $actions['delete'] = sprintf(
    659676                        '<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>',
     
    683700                );
    684701            }
    685         }
    686         else {
    687             if ( current_user_can( 'edit_post', $post->ID ) && !$this->is_trash ) {
     702        } else {
     703            if ( current_user_can( 'edit_post', $post->ID ) && ! $this->is_trash ) {
    688704                $actions['edit'] = sprintf(
    689705                    '<a href="%s" aria-label="%s">%s</a>',
     
    713729                }
    714730                if ( $this->is_trash || ! EMPTY_TRASH_DAYS || ! MEDIA_TRASH ) {
    715                     $delete_ays = ( !$this->is_trash && !MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : '';
     731                    $delete_ays        = ( ! $this->is_trash && ! MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : '';
    716732                    $actions['delete'] = sprintf(
    717733                        '<a href="%s" class="submitdelete aria-button-if-js"%s aria-label="%s">%s</a>',
Note: See TracChangeset for help on using the changeset viewer.