Changeset 32740
- Timestamp:
- 06/12/2015 08:17:59 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-posts-list-table.php
r32738 r32740 47 47 48 48 private $is_trash; 49 50 /** 51 * @since 4.3.0 52 * @var int 53 */ 54 protected $current_level = 0; 49 55 50 56 /** … … 672 678 673 679 /** 674 * @global string $mode 680 * @since 4.3.0 681 * 682 * @param WP_Post $post 683 */ 684 public function column_cb( $post ) { 685 $can_edit_post = current_user_can( 'edit_post', $post->ID ); 686 $title = _draft_or_post_title(); 687 ?> 688 <th scope="row" class="check-column"> 689 <?php if ( $can_edit_post ) { ?> 690 <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php printf( __( 'Select %s' ), $title ); ?></label> 691 <input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" /> 692 <div class="locked-indicator"></div> 693 <?php } ?> 694 </th> 695 <?php 696 } 697 698 /** 699 * @since 4.3.0 700 * 701 * @global string $mode 702 * 703 * @param WP_Post $post 704 */ 705 public function column_title( $post ) { 706 global $mode; 707 708 if ( $this->hierarchical_display ) { 709 if ( 0 === $this->current_level && (int) $post->post_parent > 0 ) { 710 // Sent level 0 by accident, by default, or because we don't know the actual level. 711 $find_main_page = (int) $post->post_parent; 712 while ( $find_main_page > 0 ) { 713 $parent = get_post( $find_main_page ); 714 715 if ( is_null( $parent ) ) { 716 break; 717 } 718 719 $this->current_level++; 720 $find_main_page = (int) $parent->post_parent; 721 722 if ( ! isset( $parent_name ) ) { 723 /** This filter is documented in wp-includes/post-template.php */ 724 $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID ); 725 } 726 } 727 } 728 } 729 730 $pad = str_repeat( '— ', $this->current_level ); 731 echo "<strong>"; 732 733 $format = get_post_format( $post->ID ); 734 if ( $format ) { 735 $label = get_post_format_string( $format ); 736 737 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> "; 738 } 739 740 $can_edit_post = current_user_can( 'edit_post', $post->ID ); 741 $title = _draft_or_post_title(); 742 743 if ( $can_edit_post && $post->post_status != 'trash' ) { 744 $edit_link = get_edit_post_link( $post->ID ); 745 echo '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . $pad . $title . '</a>'; 746 } else { 747 echo $pad . $title; 748 } 749 _post_states( $post ); 750 751 if ( isset( $parent_name ) ) { 752 $post_type_object = get_post_type_object( $post->post_type ); 753 echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name ); 754 } 755 echo "</strong>\n"; 756 757 if ( $can_edit_post && $post->post_status != 'trash' ) { 758 $lock_holder = wp_check_post_lock( $post->ID ); 759 760 if ( $lock_holder ) { 761 $lock_holder = get_userdata( $lock_holder ); 762 $locked_avatar = get_avatar( $lock_holder->ID, 18 ); 763 $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) ); 764 } else { 765 $locked_avatar = $locked_text = ''; 766 } 767 768 echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n"; 769 } 770 771 if ( ! $this->hierarchical_display && 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) ) { 772 the_excerpt(); 773 } 774 775 get_inline_data( $post ); 776 } 777 778 /** 779 * @since 4.3.0 780 * 781 * @global string $mode 782 * 783 * @param WP_Post $post 784 */ 785 public function column_date( $post ) { 786 global $mode; 787 788 if ( '0000-00-00 00:00:00' == $post->post_date ) { 789 $t_time = $h_time = __( 'Unpublished' ); 790 $time_diff = 0; 791 } else { 792 $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) ); 793 $m_time = $post->post_date; 794 $time = get_post_time( 'G', true, $post ); 795 796 $time_diff = time() - $time; 797 798 if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) { 799 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); 800 } else { 801 $h_time = mysql2date( __( 'Y/m/d' ), $m_time ); 802 } 803 } 804 805 if ( 'excerpt' == $mode ) { 806 /** 807 * Filter the published time of the post. 808 * 809 * If $mode equals 'excerpt', the published time and date are both displayed. 810 * If $mode equals 'list' (default), the publish date is displayed, with the 811 * time and date together available as an abbreviation definition. 812 * 813 * @since 2.5.1 814 * 815 * @param array $t_time The published time. 816 * @param WP_Post $post Post object. 817 * @param string $column_name The column name. 818 * @param string $mode The list display mode ('excerpt' or 'list'). 819 */ 820 echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode ); 821 } else { 822 823 /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */ 824 echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . '</abbr>'; 825 } 826 echo '<br />'; 827 if ( 'publish' == $post->post_status ) { 828 _e( 'Published' ); 829 } elseif ( 'future' == $post->post_status ) { 830 if ( $time_diff > 0 ) { 831 echo '<strong class="attention">' . __( 'Missed schedule' ) . '</strong>'; 832 } else { 833 _e( 'Scheduled' ); 834 } 835 } else { 836 _e( 'Last Modified' ); 837 } 838 } 839 840 /** 841 * @since 4.3.0 842 * 843 * @param WP_Post $post 844 */ 845 public function column_comments( $post ) { 846 ?> 847 <div class="post-com-count-wrapper"> 848 <?php 849 $pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0; 850 851 $this->comments_bubble( $post->ID, $pending_comments ); 852 ?> 853 </div> 854 <?php 855 } 856 857 /** 858 * @since 4.3.0 859 * 860 * @param WP_Post $post 861 */ 862 public function column_author( $post ) { 863 printf( '<a href="%s">%s</a>', 864 esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'author' => get_the_author_meta( 'ID' ) ), 'edit.php' )), 865 get_the_author() 866 ); 867 } 868 869 /** 870 * @since 4.3.0 871 * 872 * @param WP_Post $post 873 * @param string $column_name 874 */ 875 public function column_default( $post, $column_name ) { 876 if ( 'categories' == $column_name ) { 877 $taxonomy = 'category'; 878 } elseif ( 'tags' == $column_name ) { 879 $taxonomy = 'post_tag'; 880 } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) { 881 $taxonomy = substr( $column_name, 9 ); 882 } else { 883 $taxonomy = false; 884 } 885 if ( $taxonomy ) { 886 $taxonomy_object = get_taxonomy( $taxonomy ); 887 $terms = get_the_terms( $post->ID, $taxonomy ); 888 if ( is_array( $terms ) ) { 889 $out = array(); 890 foreach ( $terms as $t ) { 891 $posts_in_term_qv = array(); 892 if ( 'post' != $post->post_type ) { 893 $posts_in_term_qv['post_type'] = $post->post_type; 894 } 895 if ( $taxonomy_object->query_var ) { 896 $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug; 897 } else { 898 $posts_in_term_qv['taxonomy'] = $taxonomy; 899 $posts_in_term_qv['term'] = $t->slug; 900 } 901 902 $out[] = sprintf( '<a href="%s">%s</a>', 903 esc_url( add_query_arg( $posts_in_term_qv, 'edit.php' ) ), 904 esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) ) 905 ); 906 } 907 /* translators: used between list items, there is a space after the comma */ 908 echo join( __( ', ' ), $out ); 909 } else { 910 echo '<span aria-hidden="true">—</span><span class="screen-reader-text">' . $taxonomy_object->labels->not_found . '</span>'; 911 } 912 return; 913 } 914 915 if ( is_post_type_hierarchical( $post->post_type ) ) { 916 917 /** 918 * Fires in each custom column on the Posts list table. 919 * 920 * This hook only fires if the current post type is hierarchical, 921 * such as pages. 922 * 923 * @since 2.5.0 924 * 925 * @param string $column_name The name of the column to display. 926 * @param int $post_id The current post ID. 927 */ 928 do_action( 'manage_pages_custom_column', $column_name, $post->ID ); 929 } else { 930 931 /** 932 * Fires in each custom column in the Posts list table. 933 * 934 * This hook only fires if the current post type is non-hierarchical, 935 * such as posts. 936 * 937 * @since 1.5.0 938 * 939 * @param string $column_name The name of the column to display. 940 * @param int $post_id The current post ID. 941 */ 942 do_action( 'manage_posts_custom_column', $column_name, $post->ID ); 943 } 944 945 /** 946 * Fires for each custom column of a specific post type in the Posts list table. 947 * 948 * The dynamic portion of the hook name, `$post->post_type`, refers to the post type. 949 * 950 * @since 3.1.0 951 * 952 * @param string $column_name The name of the column to display. 953 * @param int $post_id The current post ID. 954 */ 955 do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID ); 956 } 957 958 /** 959 * @since 4.3.0 960 * 961 * @param WP_Post $post 962 */ 963 public function single_row_columns( $item ) { 964 list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); 965 966 foreach ( $columns as $column_name => $column_display_name ) { 967 $classes = "$column_name column-$column_name"; 968 if ( $primary === $column_name ) { 969 $classes .= ' has-row-actions column-primary'; 970 } 971 972 if ( 'title' === $column_name ) { 973 $classes .= ' page-title'; // Special addition for title column 974 } 975 976 if ( in_array( $column_name, $hidden ) ) { 977 $classes .= ' hidden'; 978 } 979 980 $attributes = "class='$classes'"; 981 982 if ( 'cb' === $column_name ) { 983 $this->column_cb( $item ); 984 } else { 985 echo "<td $attributes>"; 986 987 if ( method_exists( $this, 'column_' . $column_name ) ) { 988 call_user_func( array( $this, 'column_' . $column_name ), $item ); 989 } else { 990 $this->column_default( $item, $column_name ); 991 } 992 993 echo $this->handle_row_actions( $item, $column_name, $primary ); 994 echo '</td>'; 995 } 996 } 997 } 998 999 /** 675 1000 * @global WP_Post $post 676 1001 * … … 679 1004 */ 680 1005 public function single_row( $post, $level = 0 ) { 681 global $mode;682 683 1006 $global_post = get_post(); 684 1007 685 1008 $post = get_post( $post ); 1009 $this->current_level = $level; 686 1010 687 1011 $GLOBALS['post'] = $post; 688 1012 setup_postdata( $post ); 689 690 $edit_link = get_edit_post_link( $post->ID );691 $title = _draft_or_post_title();692 $post_type_object = get_post_type_object( $post->post_type );693 $can_edit_post = current_user_can( 'edit_post', $post->ID );694 1013 695 1014 $classes = 'iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' ); … … 709 1028 ?> 710 1029 <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>"> 711 <?php 712 713 list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); 714 715 foreach ( $columns as $column_name => $column_display_name ) { 716 $classes = "$column_name column-$column_name"; 717 if ( $primary === $column_name ) { 718 $classes .= ' has-row-actions column-primary'; 719 } 720 721 if ( 'title' === $column_name ) { 722 $classes .= ' page-title'; // Special addition for title column 723 } 724 725 if ( in_array( $column_name, $hidden ) ) { 726 $classes .= ' hidden'; 727 } 728 729 $attributes = "class='$classes'"; 730 731 if ( 'cb' === $column_name ) { 732 ?> 733 <th scope="row" class="check-column"> 734 <?php if ( $can_edit_post ) { ?> 735 <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php printf( __( 'Select %s' ), $title ); ?></label> 736 <input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" /> 737 <div class="locked-indicator"></div> 738 <?php } ?> 739 </th> 740 <?php 741 } else { 742 echo "<td $attributes>"; 743 744 switch ( $column_name ) { 745 746 case 'title': 747 if ( $this->hierarchical_display ) { 748 if ( 0 == $level && (int) $post->post_parent > 0 ) { 749 // Sent level 0 by accident, by default, or because we don't know the actual level. 750 $find_main_page = (int) $post->post_parent; 751 while ( $find_main_page > 0 ) { 752 $parent = get_post( $find_main_page ); 753 754 if ( is_null( $parent ) ) 755 break; 756 757 $level++; 758 $find_main_page = (int) $parent->post_parent; 759 760 if ( !isset( $parent_name ) ) { 761 /** This filter is documented in wp-includes/post-template.php */ 762 $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID ); 763 } 764 } 765 } 766 } 767 768 $pad = str_repeat( '— ', $level ); 769 echo "<strong>"; 770 771 if ( $format = get_post_format( $post->ID ) ) { 772 $label = get_post_format_string( $format ); 773 774 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> "; 775 } 776 777 if ( $can_edit_post && $post->post_status != 'trash' ) { 778 echo '<a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . $pad . $title . '</a>'; 779 } else { 780 echo $pad . $title; 781 } 782 _post_states( $post ); 783 784 if ( isset( $parent_name ) ) 785 echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name ); 786 787 echo "</strong>\n"; 788 789 if ( $can_edit_post && $post->post_status != 'trash' ) { 790 if ( $lock_holder ) { 791 $locked_avatar = get_avatar( $lock_holder->ID, 18 ); 792 $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) ); 793 } else { 794 $locked_avatar = $locked_text = ''; 795 } 796 797 echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n"; 798 } 799 800 if ( ! $this->hierarchical_display && 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) ) 801 the_excerpt(); 802 803 get_inline_data( $post ); 804 break; 805 806 case 'date': 807 if ( '0000-00-00 00:00:00' == $post->post_date ) { 808 $t_time = $h_time = __( 'Unpublished' ); 809 $time_diff = 0; 810 } else { 811 $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) ); 812 $m_time = $post->post_date; 813 $time = get_post_time( 'G', true, $post ); 814 815 $time_diff = time() - $time; 816 817 if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) 818 $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); 819 else 820 $h_time = mysql2date( __( 'Y/m/d' ), $m_time ); 821 } 822 823 if ( 'excerpt' == $mode ) { 824 825 /** 826 * Filter the published time of the post. 827 * 828 * If $mode equals 'excerpt', the published time and date are both displayed. 829 * If $mode equals 'list' (default), the publish date is displayed, with the 830 * time and date together available as an abbreviation definition. 831 * 832 * @since 2.5.1 833 * 834 * @param array $t_time The published time. 835 * @param WP_Post $post Post object. 836 * @param string $column_name The column name. 837 * @param string $mode The list display mode ('excerpt' or 'list'). 838 */ 839 echo apply_filters( 'post_date_column_time', $t_time, $post, $column_name, $mode ); 840 } else { 841 842 /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */ 843 echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, $column_name, $mode ) . '</abbr>'; 844 } 845 echo '<br />'; 846 if ( 'publish' == $post->post_status ) { 847 _e( 'Published' ); 848 } elseif ( 'future' == $post->post_status ) { 849 if ( $time_diff > 0 ) 850 echo '<strong class="attention">' . __( 'Missed schedule' ) . '</strong>'; 851 else 852 _e( 'Scheduled' ); 853 } else { 854 _e( 'Last Modified' ); 855 } 856 break; 857 858 case 'comments': 859 ?> 860 <div class="post-com-count-wrapper"> 861 <?php 862 $pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0; 863 864 $this->comments_bubble( $post->ID, $pending_comments ); 865 ?> 866 </div> 867 <?php 868 break; 869 870 case 'author': 871 printf( '<a href="%s">%s</a>', 872 esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'author' => get_the_author_meta( 'ID' ) ), 'edit.php' )), 873 get_the_author() 874 ); 875 break; 876 877 default: 878 if ( 'categories' == $column_name ) 879 $taxonomy = 'category'; 880 elseif ( 'tags' == $column_name ) 881 $taxonomy = 'post_tag'; 882 elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) 883 $taxonomy = substr( $column_name, 9 ); 884 else 885 $taxonomy = false; 886 887 if ( $taxonomy ) { 888 $taxonomy_object = get_taxonomy( $taxonomy ); 889 $terms = get_the_terms( $post->ID, $taxonomy ); 890 if ( is_array( $terms ) ) { 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 '<span aria-hidden="true">—</span><span class="screen-reader-text">' . $taxonomy_object->labels->not_found . '</span>'; 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 } 945 946 /** 947 * Fires for each custom column of a specific post type in the Posts list table. 948 * 949 * The dynamic portion of the hook name, `$post->post_type`, refers to the post type. 950 * 951 * @since 3.1.0 952 * 953 * @param string $column_name The name of the column to display. 954 * @param int $post_id The current post ID. 955 */ 956 do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID ); 957 break; 958 } 959 960 echo $this->handle_row_actions( $post, $column_name, $primary ); 961 echo '</td>'; 962 } 963 } 964 ?> 1030 <?php $this->single_row_columns( $post ); ?> 965 1031 </tr> 966 1032 <?php
Note: See TracChangeset
for help on using the changeset viewer.