Make WordPress Core

Changeset 32721


Ignore:
Timestamp:
06/10/2015 02:00:55 PM (11 years ago)
Author:
helen
Message:

List tables: Consolidate <td> output for posts.

see #25408.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-posts-list-table.php

    r32668 r32721  
    719719                        }
    720720
     721                        if ( 'title' === $column_name ) {
     722                                $classes .= ' page-title'; // Special addition for title column
     723                        }
     724
    721725                        $style = '';
    722726                        if ( in_array( $column_name, $hidden ) ) {
     
    726730                        $attributes = "class='$classes'$style";
    727731
    728                         switch ( $column_name ) {
    729 
    730                         case 'cb':
    731                         ?>
    732                         <th scope="row" class="check-column">
     732                        if ( 'cb' === $column_name ) {
     733                                ?>
     734                                <th scope="row" class="check-column">
     735                                <?php if ( $can_edit_post ) { ?>
     736                                        <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php printf( __( 'Select %s' ), $title ); ?></label>
     737                                        <input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" />
     738                                        <div class="locked-indicator"></div>
     739                                <?php } ?>
     740                                </th>
    733741                                <?php
    734                                 if ( $can_edit_post ) {
    735 
    736                                 ?>
    737                                 <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php printf( __( 'Select %s' ), $title ); ?></label>
    738                                 <input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" />
    739                                 <div class="locked-indicator"></div>
    740                                 <?php
    741                                 }
    742                                 ?>
    743                         </th>
    744                         <?php
    745                         break;
    746 
    747                         case 'title':
    748                                 $classes .= ' page-title'; // Special addition for title column
    749                                 $attributes = "class='$classes'$style";
    750                                 if ( $this->hierarchical_display ) {
    751                                         if ( 0 == $level && (int) $post->post_parent > 0 ) {
    752                                                 // Sent level 0 by accident, by default, or because we don't know the actual level.
    753                                                 $find_main_page = (int) $post->post_parent;
    754                                                 while ( $find_main_page > 0 ) {
    755                                                         $parent = get_post( $find_main_page );
    756 
    757                                                         if ( is_null( $parent ) )
    758                                                                 break;
    759 
    760                                                         $level++;
    761                                                         $find_main_page = (int) $parent->post_parent;
    762 
    763                                                         if ( !isset( $parent_name ) ) {
    764                                                                 /** This filter is documented in wp-includes/post-template.php */
    765                                                                 $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
     742                        } else {
     743                                echo "<td $attributes>";
     744
     745                                switch ( $column_name ) {
     746
     747                                case 'title':
     748                                        if ( $this->hierarchical_display ) {
     749                                                if ( 0 == $level && (int) $post->post_parent > 0 ) {
     750                                                        // Sent level 0 by accident, by default, or because we don't know the actual level.
     751                                                        $find_main_page = (int) $post->post_parent;
     752                                                        while ( $find_main_page > 0 ) {
     753                                                                $parent = get_post( $find_main_page );
     754
     755                                                                if ( is_null( $parent ) )
     756                                                                        break;
     757
     758                                                                $level++;
     759                                                                $find_main_page = (int) $parent->post_parent;
     760
     761                                                                if ( !isset( $parent_name ) ) {
     762                                                                        /** This filter is documented in wp-includes/post-template.php */
     763                                                                        $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
     764                                                                }
    766765                                                        }
    767766                                                }
    768767                                        }
    769                                 }
    770 
    771                                 $pad = str_repeat( '&#8212; ', $level );
    772                                 echo "<td $attributes><strong>";
    773 
    774                                 if ( $format = get_post_format( $post->ID ) ) {
    775                                         $label = get_post_format_string( $format );
    776 
    777                                         echo '<a href="' . esc_url( add_query_arg( array( 'post_format' => $format, 'post_type' => $post->post_type ), 'edit.php' ) ) . '" class="post-state-format post-format-icon post-format-' . $format . '" title="' . $label . '">' . $label . ":</a> ";
    778                                 }
    779 
    780                                 if ( $can_edit_post && $post->post_status != 'trash' ) {
    781                                         echo '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ) . '">' . $pad . $title . '</a>';
    782                                 } else {
    783                                         echo $pad . $title;
    784                                 }
    785                                 _post_states( $post );
    786 
    787                                 if ( isset( $parent_name ) )
    788                                         echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
    789 
    790                                 echo "</strong>\n";
    791 
    792                                 if ( $can_edit_post && $post->post_status != 'trash' ) {
    793                                         if ( $lock_holder ) {
    794                                                 $locked_avatar = get_avatar( $lock_holder->ID, 18 );
    795                                                 $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
     768
     769                                        $pad = str_repeat( '&#8212; ', $level );
     770                                        echo "<strong>";
     771
     772                                        if ( $format = get_post_format( $post->ID ) ) {
     773                                                $label = get_post_format_string( $format );
     774
     775                                                echo '<a href="' . esc_url( add_query_arg( array( 'post_format' => $format, 'post_type' => $post->post_type ), 'edit.php' ) ) . '" class="post-state-format post-format-icon post-format-' . $format . '" title="' . $label . '">' . $label . ":</a> ";
     776                                        }
     777
     778                                        if ( $can_edit_post && $post->post_status != 'trash' ) {
     779                                                echo '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ) . '">' . $pad . $title . '</a>';
    796780                                        } else {
    797                                                 $locked_avatar = $locked_text = '';
     781                                                echo $pad . $title;
    798782                                        }
    799 
    800                                         echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
    801                                 }
    802 
    803                                 if ( ! $this->hierarchical_display && 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) )
    804                                                 the_excerpt();
    805 
    806                                 echo $this->handle_row_actions( $post, $column_name, $primary );
    807 
    808                                 get_inline_data( $post );
    809                                 echo '</td>';
    810                         break;
    811 
    812                         case 'date':
    813                                 if ( '0000-00-00 00:00:00' == $post->post_date ) {
    814                                         $t_time = $h_time = __( 'Unpublished' );
    815                                         $time_diff = 0;
    816                                 } else {
    817                                         $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
    818                                         $m_time = $post->post_date;
    819                                         $time = get_post_time( 'G', true, $post );
    820 
    821                                         $time_diff = time() - $time;
    822 
    823                                         if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS )
    824                                                 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
     783                                        _post_states( $post );
     784
     785                                        if ( isset( $parent_name ) )
     786                                                echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
     787
     788                                        echo "</strong>\n";
     789
     790                                        if ( $can_edit_post && $post->post_status != 'trash' ) {
     791                                                if ( $lock_holder ) {
     792                                                        $locked_avatar = get_avatar( $lock_holder->ID, 18 );
     793                                                        $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
     794                                                } else {
     795                                                        $locked_avatar = $locked_text = '';
     796                                                }
     797
     798                                                echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
     799                                        }
     800
     801                                        if ( ! $this->hierarchical_display && 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) )
     802                                                        the_excerpt();
     803
     804                                        get_inline_data( $post );
     805                                break;
     806
     807                                case 'date':
     808                                        if ( '0000-00-00 00:00:00' == $post->post_date ) {
     809                                                $t_time = $h_time = __( 'Unpublished' );
     810                                                $time_diff = 0;
     811                                        } else {
     812                                                $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
     813                                                $m_time = $post->post_date;
     814                                                $time = get_post_time( 'G', true, $post );
     815
     816                                                $time_diff = time() - $time;
     817
     818                                                if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS )
     819                                                        $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
     820                                                else
     821                                                        $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
     822                                        }
     823
     824                                        if ( 'excerpt' == $mode ) {
     825
     826                                                /**
     827                                                 * Filter the published time of the post.
     828                                                 *
     829                                                 * If $mode equals 'excerpt', the published time and date are both displayed.
     830                                                 * If $mode equals 'list' (default), the publish date is displayed, with the
     831                                                 * time and date together available as an abbreviation definition.
     832                                                 *
     833                                                 * @since 2.5.1
     834                                                 *
     835                                                 * @param array   $t_time      The published time.
     836                                                 * @param WP_Post $post        Post object.
     837                                                 * @param string  $column_name The column name.
     838                                                 * @param string  $mode        The list display mode ('excerpt' or 'list').
     839                                                 */
     840                                                echo apply_filters( 'post_date_column_time', $t_time, $post, $column_name, $mode );
     841                                        } else {
     842
     843                                                /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
     844                                                echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, $column_name, $mode ) . '</abbr>';
     845                                        }
     846                                        echo '<br />';
     847                                        if ( 'publish' == $post->post_status ) {
     848                                                _e( 'Published' );
     849                                        } elseif ( 'future' == $post->post_status ) {
     850                                                if ( $time_diff > 0 )
     851                                                        echo '<strong class="attention">' . __( 'Missed schedule' ) . '</strong>';
     852                                                else
     853                                                        _e( 'Scheduled' );
     854                                        } else {
     855                                                _e( 'Last Modified' );
     856                                        }
     857                                break;
     858
     859                                case 'comments':
     860                                ?>
     861                                <div class="post-com-count-wrapper">
     862                                <?php
     863                                        $pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0;
     864
     865                                        $this->comments_bubble( $post->ID, $pending_comments );
     866                                ?>
     867                                </div>
     868                                <?php
     869                                break;
     870
     871                                case 'author':
     872                                        printf( '<a href="%s">%s</a>',
     873                                                esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'author' => get_the_author_meta( 'ID' ) ), 'edit.php' )),
     874                                                get_the_author()
     875                                        );
     876                                break;
     877
     878                                default:
     879                                        if ( 'categories' == $column_name )
     880                                                $taxonomy = 'category';
     881                                        elseif ( 'tags' == $column_name )
     882                                                $taxonomy = 'post_tag';
     883                                        elseif ( 0 === strpos( $column_name, 'taxonomy-' ) )
     884                                                $taxonomy = substr( $column_name, 9 );
    825885                                        else
    826                                                 $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
    827                                 }
    828 
    829                                 echo '<td ' . $attributes . '>';
    830                                 if ( 'excerpt' == $mode ) {
     886                                                $taxonomy = false;
     887
     888                                        if ( $taxonomy ) {
     889                                                $taxonomy_object = get_taxonomy( $taxonomy );
     890                                                if ( $terms = get_the_terms( $post->ID, $taxonomy ) ) {
     891                                                        $out = array();
     892                                                        foreach ( $terms as $t ) {
     893                                                                $posts_in_term_qv = array();
     894                                                                if ( 'post' != $post->post_type )
     895                                                                        $posts_in_term_qv['post_type'] = $post->post_type;
     896                                                                if ( $taxonomy_object->query_var ) {
     897                                                                        $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
     898                                                                } else {
     899                                                                        $posts_in_term_qv['taxonomy'] = $taxonomy;
     900                                                                        $posts_in_term_qv['term'] = $t->slug;
     901                                                                }
     902
     903                                                                $out[] = sprintf( '<a href="%s">%s</a>',
     904                                                                        esc_url( add_query_arg( $posts_in_term_qv, 'edit.php' ) ),
     905                                                                        esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
     906                                                                );
     907                                                        }
     908                                                        /* translators: used between list items, there is a space after the comma */
     909                                                        echo join( __( ', ' ), $out );
     910                                                } else {
     911                                                        echo '&#8212;';
     912                                                }
     913                                                break;
     914                                        }
     915
     916                                        if ( is_post_type_hierarchical( $post->post_type ) ) {
     917
     918                                                /**
     919                                                 * Fires in each custom column on the Posts list table.
     920                                                 *
     921                                                 * This hook only fires if the current post type is hierarchical,
     922                                                 * such as pages.
     923                                                 *
     924                                                 * @since 2.5.0
     925                                                 *
     926                                                 * @param string $column_name The name of the column to display.
     927                                                 * @param int    $post_id     The current post ID.
     928                                                 */
     929                                                do_action( 'manage_pages_custom_column', $column_name, $post->ID );
     930                                        } else {
     931
     932                                                /**
     933                                                 * Fires in each custom column in the Posts list table.
     934                                                 *
     935                                                 * This hook only fires if the current post type is non-hierarchical,
     936                                                 * such as posts.
     937                                                 *
     938                                                 * @since 1.5.0
     939                                                 *
     940                                                 * @param string $column_name The name of the column to display.
     941                                                 * @param int    $post_id     The current post ID.
     942                                                 */
     943                                                do_action( 'manage_posts_custom_column', $column_name, $post->ID );
     944                                        }
    831945
    832946                                        /**
    833                                          * Filter the published time of the post.
     947                                         * Fires for each custom column of a specific post type in the Posts list table.
    834948                                         *
    835                                          * If $mode equals 'excerpt', the published time and date are both displayed.
    836                                          * If $mode equals 'list' (default), the publish date is displayed, with the
    837                                          * time and date together available as an abbreviation definition.
     949                                         * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
    838950                                         *
    839                                          * @since 2.5.1
    840                                          *
    841                                          * @param array   $t_time      The published time.
    842                                          * @param WP_Post $post        Post object.
    843                                          * @param string  $column_name The column name.
    844                                          * @param string  $mode        The list display mode ('excerpt' or 'list').
    845                                          */
    846                                         echo apply_filters( 'post_date_column_time', $t_time, $post, $column_name, $mode );
    847                                 } else {
    848 
    849                                         /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
    850                                         echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, $column_name, $mode ) . '</abbr>';
    851                                 }
    852                                 echo '<br />';
    853                                 if ( 'publish' == $post->post_status ) {
    854                                         _e( 'Published' );
    855                                 } elseif ( 'future' == $post->post_status ) {
    856                                         if ( $time_diff > 0 )
    857                                                 echo '<strong class="attention">' . __( 'Missed schedule' ) . '</strong>';
    858                                         else
    859                                                 _e( 'Scheduled' );
    860                                 } else {
    861                                         _e( 'Last Modified' );
    862                                 }
    863                                 echo $this->handle_row_actions( $post, $column_name, $primary );
    864                                 echo '</td>';
    865                         break;
    866 
    867                         case 'comments':
    868                         ?>
    869                         <td <?php echo $attributes ?>><div class="post-com-count-wrapper">
    870                         <?php
    871                                 $pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0;
    872 
    873                                 $this->comments_bubble( $post->ID, $pending_comments );
    874                         ?>
    875                         </div><?php echo $this->handle_row_actions( $post, $column_name, $primary ); ?></td>
    876                         <?php
    877                         break;
    878 
    879                         case 'author':
    880                         ?>
    881                         <td <?php echo $attributes ?>><?php
    882                                 printf( '<a href="%s">%s</a>',
    883                                         esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'author' => get_the_author_meta( 'ID' ) ), 'edit.php' )),
    884                                         get_the_author()
    885                                 );
    886                                 echo $this->handle_row_actions( $post, $column_name, $primary );
    887                         ?></td>
    888                         <?php
    889                         break;
    890 
    891                         default:
    892                                 if ( 'categories' == $column_name )
    893                                         $taxonomy = 'category';
    894                                 elseif ( 'tags' == $column_name )
    895                                         $taxonomy = 'post_tag';
    896                                 elseif ( 0 === strpos( $column_name, 'taxonomy-' ) )
    897                                         $taxonomy = substr( $column_name, 9 );
    898                                 else
    899                                         $taxonomy = false;
    900 
    901                                 if ( $taxonomy ) {
    902                                         $taxonomy_object = get_taxonomy( $taxonomy );
    903                                         echo '<td ' . $attributes . '>';
    904                                         if ( $terms = get_the_terms( $post->ID, $taxonomy ) ) {
    905                                                 $out = array();
    906                                                 foreach ( $terms as $t ) {
    907                                                         $posts_in_term_qv = array();
    908                                                         if ( 'post' != $post->post_type )
    909                                                                 $posts_in_term_qv['post_type'] = $post->post_type;
    910                                                         if ( $taxonomy_object->query_var ) {
    911                                                                 $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
    912                                                         } else {
    913                                                                 $posts_in_term_qv['taxonomy'] = $taxonomy;
    914                                                                 $posts_in_term_qv['term'] = $t->slug;
    915                                                         }
    916 
    917                                                         $out[] = sprintf( '<a href="%s">%s</a>',
    918                                                                 esc_url( add_query_arg( $posts_in_term_qv, 'edit.php' ) ),
    919                                                                 esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
    920                                                         );
    921                                                 }
    922                                                 /* translators: used between list items, there is a space after the comma */
    923                                                 echo join( __( ', ' ), $out );
    924                                         } else {
    925                                                 echo '&#8212;';
    926                                         }
    927                                         echo $this->handle_row_actions( $post, $column_name, $primary );
    928                                         echo '</td>';
    929                                         break;
    930                                 }
    931                         ?>
    932                         <td <?php echo $attributes ?>><?php
    933                                 if ( is_post_type_hierarchical( $post->post_type ) ) {
    934 
    935                                         /**
    936                                          * Fires in each custom column on the Posts list table.
    937                                          *
    938                                          * This hook only fires if the current post type is hierarchical,
    939                                          * such as pages.
    940                                          *
    941                                          * @since 2.5.0
     951                                         * @since 3.1.0
    942952                                         *
    943953                                         * @param string $column_name The name of the column to display.
    944954                                         * @param int    $post_id     The current post ID.
    945955                                         */
    946                                         do_action( 'manage_pages_custom_column', $column_name, $post->ID );
    947                                 } else {
    948 
    949                                         /**
    950                                          * Fires in each custom column in the Posts list table.
    951                                          *
    952                                          * This hook only fires if the current post type is non-hierarchical,
    953                                          * such as posts.
    954                                          *
    955                                          * @since 1.5.0
    956                                          *
    957                                          * @param string $column_name The name of the column to display.
    958                                          * @param int    $post_id     The current post ID.
    959                                          */
    960                                         do_action( 'manage_posts_custom_column', $column_name, $post->ID );
     956                                        do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
     957                                break;
    961958                                }
    962959
    963                                 /**
    964                                  * Fires for each custom column of a specific post type in the Posts list table.
    965                                  *
    966                                  * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
    967                                  *
    968                                  * @since 3.1.0
    969                                  *
    970                                  * @param string $column_name The name of the column to display.
    971                                  * @param int    $post_id     The current post ID.
    972                                  */
    973                                 do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
    974960                                echo $this->handle_row_actions( $post, $column_name, $primary );
    975                         ?></td>
    976                         <?php
    977                         break;
     961                                echo '</td>';
    978962                        }
    979963                }
Note: See TracChangeset for help on using the changeset viewer.