wp/wp-admin/includes/class-wp-posts-list-table.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    14 	 *
    14 	 *
    15 	 * @since 3.1.0
    15 	 * @since 3.1.0
    16 	 * @var bool
    16 	 * @var bool
    17 	 * @access protected
    17 	 * @access protected
    18 	 */
    18 	 */
    19 	var $hierarchical_display;
    19 	protected $hierarchical_display;
    20 
    20 
    21 	/**
    21 	/**
    22 	 * Holds the number of pending comments for each post
    22 	 * Holds the number of pending comments for each post
    23 	 *
    23 	 *
    24 	 * @since 3.1.0
    24 	 * @since 3.1.0
    25 	 * @var int
    25 	 * @var int
    26 	 * @access protected
    26 	 * @access protected
    27 	 */
    27 	 */
    28 	var $comment_pending_count;
    28 	protected $comment_pending_count;
    29 
    29 
    30 	/**
    30 	/**
    31 	 * Holds the number of posts for this user
    31 	 * Holds the number of posts for this user
    32 	 *
    32 	 *
    33 	 * @since 3.1.0
    33 	 * @since 3.1.0
    34 	 * @var int
    34 	 * @var int
    35 	 * @access private
    35 	 * @access private
    36 	 */
    36 	 */
    37 	var $user_posts_count;
    37 	private $user_posts_count;
    38 
    38 
    39 	/**
    39 	/**
    40 	 * Holds the number of posts which are sticky.
    40 	 * Holds the number of posts which are sticky.
    41 	 *
    41 	 *
    42 	 * @since 3.1.0
    42 	 * @since 3.1.0
    43 	 * @var int
    43 	 * @var int
    44 	 * @access private
    44 	 * @access private
    45 	 */
    45 	 */
    46 	var $sticky_posts_count = 0;
    46 	private $sticky_posts_count = 0;
    47 
    47 
    48 	function __construct( $args = array() ) {
    48 	private $is_trash;
       
    49 
       
    50 	/**
       
    51 	 * Constructor.
       
    52 	 *
       
    53 	 * @since 3.1.0
       
    54 	 * @access public
       
    55 	 *
       
    56 	 * @see WP_List_Table::__construct() for more information on default arguments.
       
    57 	 *
       
    58 	 * @param array $args An associative array of arguments.
       
    59 	 */
       
    60 	public function __construct( $args = array() ) {
    49 		global $post_type_object, $wpdb;
    61 		global $post_type_object, $wpdb;
    50 
    62 
    51 		parent::__construct( array(
    63 		parent::__construct( array(
    52 			'plural' => 'posts',
    64 			'plural' => 'posts',
    53 			'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
    65 			'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
    72 			$sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
    84 			$sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
    73 			$this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ('trash', 'auto-draft') AND ID IN ($sticky_posts)", $post_type ) );
    85 			$this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ('trash', 'auto-draft') AND ID IN ($sticky_posts)", $post_type ) );
    74 		}
    86 		}
    75 	}
    87 	}
    76 
    88 
    77 	function ajax_user_can() {
    89 	/**
       
    90 	 * Sets whether the table layout should be hierarchical or not.
       
    91 	 *
       
    92 	 * @since 4.2.0
       
    93 	 *
       
    94 	 * @param bool $display Whether the table layout should be hierarchical.
       
    95 	 */
       
    96 	public function set_hierarchical_display( $display ) {
       
    97 		$this->hierarchical_display = $display;
       
    98 	}
       
    99 
       
   100 	public function ajax_user_can() {
    78 		return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts );
   101 		return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts );
    79 	}
   102 	}
    80 
   103 
    81 	function prepare_items() {
   104 	public function prepare_items() {
    82 		global $avail_post_stati, $wp_query, $per_page, $mode;
   105 		global $avail_post_stati, $wp_query, $per_page, $mode;
    83 
   106 
    84 		$avail_post_stati = wp_edit_posts_query();
   107 		$avail_post_stati = wp_edit_posts_query();
    85 
   108 
    86 		$this->hierarchical_display = ( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' == $wp_query->query['orderby'] );
   109 		$this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' == $wp_query->query['orderby'] );
    87 
   110 
    88 		$total_items = $this->hierarchical_display ? $wp_query->post_count : $wp_query->found_posts;
   111 		$total_items = $this->hierarchical_display ? $wp_query->post_count : $wp_query->found_posts;
    89 
   112 
    90 		$post_type = $this->screen->post_type;
   113 		$post_type = $this->screen->post_type;
    91 		$per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
   114 		$per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
       
   115 
       
   116 		/** This filter is documented in wp-admin/includes/post.php */
    92  		$per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
   117  		$per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
    93 
   118 
    94 		if ( $this->hierarchical_display )
   119 		if ( $this->hierarchical_display )
    95 			$total_pages = ceil( $total_items / $per_page );
   120 			$total_pages = ceil( $total_items / $per_page );
    96 		else
   121 		else
    97 			$total_pages = $wp_query->max_num_pages;
   122 			$total_pages = $wp_query->max_num_pages;
    98 
   123 
    99 		$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
   124 		if ( ! empty( $_REQUEST['mode'] ) ) {
       
   125 			$mode = $_REQUEST['mode'] == 'excerpt' ? 'excerpt' : 'list';
       
   126 			set_user_setting ( 'posts_list_mode', $mode );
       
   127 		} else {
       
   128 			$mode = get_user_setting ( 'posts_list_mode', 'list' );
       
   129 		}
   100 
   130 
   101 		$this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] == 'trash';
   131 		$this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] == 'trash';
   102 
   132 
   103 		$this->set_pagination_args( array(
   133 		$this->set_pagination_args( array(
   104 			'total_items' => $total_items,
   134 			'total_items' => $total_items,
   105 			'total_pages' => $total_pages,
   135 			'total_pages' => $total_pages,
   106 			'per_page' => $per_page
   136 			'per_page' => $per_page
   107 		) );
   137 		) );
   108 	}
   138 	}
   109 
   139 
   110 	function has_items() {
   140 	public function has_items() {
   111 		return have_posts();
   141 		return have_posts();
   112 	}
   142 	}
   113 
   143 
   114 	function no_items() {
   144 	public function no_items() {
   115 		if ( isset( $_REQUEST['post_status'] ) && 'trash' == $_REQUEST['post_status'] )
   145 		if ( isset( $_REQUEST['post_status'] ) && 'trash' == $_REQUEST['post_status'] )
   116 			echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash;
   146 			echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash;
   117 		else
   147 		else
   118 			echo get_post_type_object( $this->screen->post_type )->labels->not_found;
   148 			echo get_post_type_object( $this->screen->post_type )->labels->not_found;
   119 	}
   149 	}
   120 
   150 
   121 	function get_views() {
   151 	/**
       
   152 	 * Determine if the current view is the "All" view.
       
   153 	 *
       
   154 	 * @since 4.2.0
       
   155 	 *
       
   156 	 * @return bool Whether the current ivew is the "All" view.
       
   157 	 */
       
   158 	protected function is_base_request() {
       
   159 		if ( empty( $_GET ) ) {
       
   160 			return true;
       
   161 		} elseif ( 1 === count( $_GET ) && ! empty( $_GET['post_type'] ) ) {
       
   162 			return $this->screen->post_type === $_GET['post_type'];
       
   163 		}
       
   164 	}
       
   165 
       
   166 	protected function get_views() {
   122 		global $locked_post_status, $avail_post_stati;
   167 		global $locked_post_status, $avail_post_stati;
   123 
   168 
   124 		$post_type = $this->screen->post_type;
   169 		$post_type = $this->screen->post_type;
   125 
   170 
   126 		if ( !empty($locked_post_status) )
   171 		if ( !empty($locked_post_status) )
   136 		if ( $this->user_posts_count ) {
   181 		if ( $this->user_posts_count ) {
   137 			if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) )
   182 			if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) )
   138 				$class = ' class="current"';
   183 				$class = ' class="current"';
   139 			$status_links['mine'] = "<a href='edit.php?post_type=$post_type&author=$current_user_id'$class>" . sprintf( _nx( 'Mine <span class="count">(%s)</span>', 'Mine <span class="count">(%s)</span>', $this->user_posts_count, 'posts' ), number_format_i18n( $this->user_posts_count ) ) . '</a>';
   184 			$status_links['mine'] = "<a href='edit.php?post_type=$post_type&author=$current_user_id'$class>" . sprintf( _nx( 'Mine <span class="count">(%s)</span>', 'Mine <span class="count">(%s)</span>', $this->user_posts_count, 'posts' ), number_format_i18n( $this->user_posts_count ) ) . '</a>';
   140 			$allposts = '&all_posts=1';
   185 			$allposts = '&all_posts=1';
       
   186 			$class = '';
   141 		}
   187 		}
   142 
   188 
   143 		$total_posts = array_sum( (array) $num_posts );
   189 		$total_posts = array_sum( (array) $num_posts );
   144 
   190 
   145 		// Subtract post types that are not included in the admin all list.
   191 		// Subtract post types that are not included in the admin all list.
   146 		foreach ( get_post_stati( array('show_in_admin_all_list' => false) ) as $state )
   192 		foreach ( get_post_stati( array('show_in_admin_all_list' => false) ) as $state )
   147 			$total_posts -= $num_posts->$state;
   193 			$total_posts -= $num_posts->$state;
   148 
   194 
   149 		$class = empty( $class ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['show_sticky'] ) ? ' class="current"' : '';
   195 		if ( empty( $class ) && $this->is_base_request() && ! $this->user_posts_count ) {
   150 		$status_links['all'] = "<a href='edit.php?post_type=$post_type{$allposts}'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>';
   196 			$class =  ' class="current"';
       
   197 		}
       
   198 
       
   199 		$all_inner_html = sprintf(
       
   200 			_nx(
       
   201 				'All <span class="count">(%s)</span>',
       
   202 				'All <span class="count">(%s)</span>',
       
   203 				$total_posts,
       
   204 				'posts'
       
   205 			),
       
   206 			number_format_i18n( $total_posts )
       
   207 		);
       
   208 
       
   209 		$status_links['all'] = "<a href='edit.php?post_type=$post_type{$allposts}'$class>" . $all_inner_html . '</a>';
   151 
   210 
   152 		foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
   211 		foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
   153 			$class = '';
   212 			$class = '';
   154 
   213 
   155 			$status_name = $status->name;
   214 			$status_name = $status->name;
   177 		}
   236 		}
   178 
   237 
   179 		return $status_links;
   238 		return $status_links;
   180 	}
   239 	}
   181 
   240 
   182 	function get_bulk_actions() {
   241 	protected function get_bulk_actions() {
   183 		$actions = array();
   242 		$actions = array();
   184 
   243 		$post_type_obj = get_post_type_object( $this->screen->post_type );
   185 		if ( $this->is_trash )
   244 
       
   245 		if ( $this->is_trash ) {
   186 			$actions['untrash'] = __( 'Restore' );
   246 			$actions['untrash'] = __( 'Restore' );
   187 		else
   247 		} else {
   188 			$actions['edit'] = __( 'Edit' );
   248 			$actions['edit'] = __( 'Edit' );
   189 
   249 		}
   190 		if ( $this->is_trash || !EMPTY_TRASH_DAYS )
   250 
   191 			$actions['delete'] = __( 'Delete Permanently' );
   251 		if ( current_user_can( $post_type_obj->cap->delete_posts ) ) {
   192 		else
   252 			if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) {
   193 			$actions['trash'] = __( 'Move to Trash' );
   253 				$actions['delete'] = __( 'Delete Permanently' );
       
   254 			} else {
       
   255 				$actions['trash'] = __( 'Move to Trash' );
       
   256 			}
       
   257 		}
   194 
   258 
   195 		return $actions;
   259 		return $actions;
   196 	}
   260 	}
   197 
   261 
   198 	function extra_tablenav( $which ) {
   262 	/**
       
   263 	 * @global int $cat
       
   264 	 * @param string $which
       
   265 	 */
       
   266 	protected function extra_tablenav( $which ) {
   199 		global $cat;
   267 		global $cat;
   200 ?>
   268 ?>
   201 		<div class="alignleft actions">
   269 		<div class="alignleft actions">
   202 <?php
   270 <?php
   203 		if ( 'top' == $which && !is_singular() ) {
   271 		if ( 'top' == $which && !is_singular() ) {
   204 
   272 
   205 			$this->months_dropdown( $this->screen->post_type );
   273 			$this->months_dropdown( $this->screen->post_type );
   206 
   274 
   207 			if ( is_object_in_taxonomy( $this->screen->post_type, 'category' ) ) {
   275 			if ( is_object_in_taxonomy( $this->screen->post_type, 'category' ) ) {
   208 				$dropdown_options = array(
   276 				$dropdown_options = array(
   209 					'show_option_all' => __( 'View all categories' ),
   277 					'show_option_all' => __( 'All categories' ),
   210 					'hide_empty' => 0,
   278 					'hide_empty' => 0,
   211 					'hierarchical' => 1,
   279 					'hierarchical' => 1,
   212 					'show_count' => 0,
   280 					'show_count' => 0,
   213 					'orderby' => 'name',
   281 					'orderby' => 'name',
   214 					'selected' => $cat
   282 					'selected' => $cat
   215 				);
   283 				);
       
   284 
       
   285 				echo '<label class="screen-reader-text" for="cat">' . __( 'Filter by category' ) . '</label>';
   216 				wp_dropdown_categories( $dropdown_options );
   286 				wp_dropdown_categories( $dropdown_options );
   217 			}
   287 			}
       
   288 
       
   289 			/**
       
   290 			 * Fires before the Filter button on the Posts and Pages list tables.
       
   291 			 *
       
   292 			 * The Filter button allows sorting by date and/or category on the
       
   293 			 * Posts list table, and sorting by date on the Pages list table.
       
   294 			 *
       
   295 			 * @since 2.1.0
       
   296 			 */
   218 			do_action( 'restrict_manage_posts' );
   297 			do_action( 'restrict_manage_posts' );
   219 			submit_button( __( 'Filter' ), 'button', false, false, array( 'id' => 'post-query-submit' ) );
   298 
       
   299 			submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
   220 		}
   300 		}
   221 
   301 
   222 		if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) ) {
   302 		if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) ) {
   223 			submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
   303 			submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
   224 		}
   304 		}
   225 ?>
   305 ?>
   226 		</div>
   306 		</div>
   227 <?php
   307 <?php
   228 	}
   308 	}
   229 
   309 
   230 	function current_action() {
   310 	public function current_action() {
   231 		if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
   311 		if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
   232 			return 'delete_all';
   312 			return 'delete_all';
   233 
   313 
   234 		return parent::current_action();
   314 		return parent::current_action();
   235 	}
   315 	}
   236 
   316 
   237 	function pagination( $which ) {
   317 	/**
       
   318 	 * @global string $mode
       
   319 	 * @param string $which
       
   320 	 */
       
   321 	protected function pagination( $which ) {
   238 		global $mode;
   322 		global $mode;
   239 
   323 
   240 		parent::pagination( $which );
   324 		parent::pagination( $which );
   241 
   325 
   242 		if ( 'top' == $which && ! is_post_type_hierarchical( $this->screen->post_type ) )
   326 		if ( 'top' == $which && ! is_post_type_hierarchical( $this->screen->post_type ) )
   243 			$this->view_switcher( $mode );
   327 			$this->view_switcher( $mode );
   244 	}
   328 	}
   245 
   329 
   246 	function get_table_classes() {
   330 	protected function get_table_classes() {
   247 		return array( 'widefat', 'fixed', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
   331 		return array( 'widefat', 'fixed', 'striped', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
   248 	}
   332 	}
   249 
   333 
   250 	function get_columns() {
   334 	public function get_columns() {
   251 		$post_type = $this->screen->post_type;
   335 		$post_type = $this->screen->post_type;
   252 
   336 
   253 		$posts_columns = array();
   337 		$posts_columns = array();
   254 
   338 
   255 		$posts_columns['cb'] = '<input type="checkbox" />';
   339 		$posts_columns['cb'] = '<input type="checkbox" />';
   256 
   340 
   257 		/* translators: manage posts column name */
   341 		/* translators: manage posts column name */
   258 		$posts_columns['title'] = _x( 'Title', 'column name' );
   342 		$posts_columns['title'] = _x( 'Title', 'column name' );
   259 
   343 
   260 		if ( post_type_supports( $post_type, 'author' ) )
   344 		if ( post_type_supports( $post_type, 'author' ) ) {
   261 			$posts_columns['author'] = __( 'Author' );
   345 			$posts_columns['author'] = __( 'Author' );
   262 
   346 		}
   263 		$taxonomies = array();
       
   264 
   347 
   265 		$taxonomies = get_object_taxonomies( $post_type, 'objects' );
   348 		$taxonomies = get_object_taxonomies( $post_type, 'objects' );
   266 		$taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
   349 		$taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
   267 
   350 
       
   351 		/**
       
   352 		 * Filter the taxonomy columns in the Posts list table.
       
   353 		 *
       
   354 		 * The dynamic portion of the hook name, `$post_type`, refers to the post
       
   355 		 * type slug.
       
   356 		 *
       
   357 		 * @since 3.5.0
       
   358 		 *
       
   359 		 * @param array  $taxonomies Array of taxonomies to show columns for.
       
   360 		 * @param string $post_type  The post type.
       
   361 		 */
   268 		$taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
   362 		$taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
   269 		$taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
   363 		$taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
   270 
   364 
   271 		foreach ( $taxonomies as $taxonomy ) {
   365 		foreach ( $taxonomies as $taxonomy ) {
   272 			if ( 'category' == $taxonomy )
   366 			if ( 'category' == $taxonomy )
   279 			$posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
   373 			$posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
   280 		}
   374 		}
   281 
   375 
   282 		$post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
   376 		$post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
   283 		if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) )
   377 		if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) )
   284 			$posts_columns['comments'] = '<span class="vers"><div title="' . esc_attr__( 'Comments' ) . '" class="comment-grey-bubble"></div></span>';
   378 			$posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>';
   285 
   379 
   286 		$posts_columns['date'] = __( 'Date' );
   380 		$posts_columns['date'] = __( 'Date' );
   287 
   381 
   288 		if ( 'page' == $post_type )
   382 		if ( 'page' == $post_type ) {
       
   383 
       
   384 			/**
       
   385 			 * Filter the columns displayed in the Pages list table.
       
   386 			 *
       
   387 			 * @since 2.5.0
       
   388 			 *
       
   389 			 * @param array $post_columns An array of column names.
       
   390 			 */
   289 			$posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
   391 			$posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
   290 		else
   392 		} else {
       
   393 
       
   394 			/**
       
   395 			 * Filter the columns displayed in the Posts list table.
       
   396 			 *
       
   397 			 * @since 1.5.0
       
   398 			 *
       
   399 			 * @param array  $posts_columns An array of column names.
       
   400 			 * @param string $post_type     The post type slug.
       
   401 			 */
   291 			$posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
   402 			$posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
       
   403 		}
       
   404 
       
   405 		/**
       
   406 		 * Filter the columns displayed in the Posts list table for a specific post type.
       
   407 		 *
       
   408 		 * The dynamic portion of the hook name, `$post_type`, refers to the post type slug.
       
   409 		 *
       
   410 		 * @since 3.0.0
       
   411 		 *
       
   412 		 * @param array $post_columns An array of column names.
       
   413 		 */
   292 		$posts_columns = apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
   414 		$posts_columns = apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
   293 
   415 
   294 		return $posts_columns;
   416 		return $posts_columns;
   295 	}
   417 	}
   296 
   418 
   297 	function get_sortable_columns() {
   419 	protected function get_sortable_columns() {
   298 		return array(
   420 		return array(
   299 			'title'    => 'title',
   421 			'title'    => 'title',
   300 			'parent'   => 'parent',
   422 			'parent'   => 'parent',
   301 			'comments' => 'comment_count',
   423 			'comments' => 'comment_count',
   302 			'date'     => array( 'date', true )
   424 			'date'     => array( 'date', true )
   303 		);
   425 		);
   304 	}
   426 	}
   305 
   427 
   306 	function display_rows( $posts = array(), $level = 0 ) {
   428 	/**
       
   429 	 * @global WP_Query $wp_query
       
   430 	 * @global int $per_page
       
   431 	 * @param array $posts
       
   432 	 * @param int $level
       
   433 	 */
       
   434 	public function display_rows( $posts = array(), $level = 0 ) {
   307 		global $wp_query, $per_page;
   435 		global $wp_query, $per_page;
   308 
   436 
   309 		if ( empty( $posts ) )
   437 		if ( empty( $posts ) )
   310 			$posts = $wp_query->posts;
   438 			$posts = $wp_query->posts;
   311 
   439 
   316 		} else {
   444 		} else {
   317 			$this->_display_rows( $posts, $level );
   445 			$this->_display_rows( $posts, $level );
   318 		}
   446 		}
   319 	}
   447 	}
   320 
   448 
   321 	function _display_rows( $posts, $level = 0 ) {
   449 	/**
       
   450 	 * @global string $mode
       
   451 	 * @param array $posts
       
   452 	 * @param int $level
       
   453 	 */
       
   454 	private function _display_rows( $posts, $level = 0 ) {
   322 		global $mode;
   455 		global $mode;
   323 
   456 
   324 		// Create array of post IDs.
   457 		// Create array of post IDs.
   325 		$post_ids = array();
   458 		$post_ids = array();
   326 
   459 
   331 
   464 
   332 		foreach ( $posts as $post )
   465 		foreach ( $posts as $post )
   333 			$this->single_row( $post, $level );
   466 			$this->single_row( $post, $level );
   334 	}
   467 	}
   335 
   468 
   336 	function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
   469 	/**
       
   470 	 * @global wpdb $wpdb
       
   471 	 * @param array $pages
       
   472 	 * @param int $pagenum
       
   473 	 * @param int $per_page
       
   474 	 * @return false|null
       
   475 	 */
       
   476 	private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
   337 		global $wpdb;
   477 		global $wpdb;
   338 
   478 
   339 		$level = 0;
   479 		$level = 0;
   340 
   480 
   341 		if ( ! $pages ) {
   481 		if ( ! $pages ) {
   344 			if ( ! $pages )
   484 			if ( ! $pages )
   345 				return false;
   485 				return false;
   346 		}
   486 		}
   347 
   487 
   348 		/*
   488 		/*
   349 		 * arrange pages into two parts: top level pages and children_pages
   489 		 * Arrange pages into two parts: top level pages and children_pages
   350 		 * children_pages is two dimensional array, eg.
   490 		 * children_pages is two dimensional array, eg.
   351 		 * children_pages[10][] contains all sub-pages whose parent is 10.
   491 		 * children_pages[10][] contains all sub-pages whose parent is 10.
   352 		 * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations
   492 		 * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations
   353 		 * If searching, ignore hierarchy and treat everything as top level
   493 		 * If searching, ignore hierarchy and treat everything as top level
   354 		 */
   494 		 */
   357 			$top_level_pages = array();
   497 			$top_level_pages = array();
   358 			$children_pages = array();
   498 			$children_pages = array();
   359 
   499 
   360 			foreach ( $pages as $page ) {
   500 			foreach ( $pages as $page ) {
   361 
   501 
   362 				// catch and repair bad pages
   502 				// Catch and repair bad pages.
   363 				if ( $page->post_parent == $page->ID ) {
   503 				if ( $page->post_parent == $page->ID ) {
   364 					$page->post_parent = 0;
   504 					$page->post_parent = 0;
   365 					$wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
   505 					$wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
   366 					clean_post_cache( $page );
   506 					clean_post_cache( $page );
   367 				}
   507 				}
   376 		}
   516 		}
   377 
   517 
   378 		$count = 0;
   518 		$count = 0;
   379 		$start = ( $pagenum - 1 ) * $per_page;
   519 		$start = ( $pagenum - 1 ) * $per_page;
   380 		$end = $start + $per_page;
   520 		$end = $start + $per_page;
       
   521 		$to_display = array();
   381 
   522 
   382 		foreach ( $pages as $page ) {
   523 		foreach ( $pages as $page ) {
   383 			if ( $count >= $end )
   524 			if ( $count >= $end )
   384 				break;
   525 				break;
   385 
   526 
   386 			if ( $count >= $start ) {
   527 			if ( $count >= $start ) {
   387 				echo "\t";
   528 				$to_display[$page->ID] = $level;
   388 				$this->single_row( $page, $level );
       
   389 			}
   529 			}
   390 
   530 
   391 			$count++;
   531 			$count++;
   392 
   532 
   393 			if ( isset( $children_pages ) )
   533 			if ( isset( $children_pages ) )
   394 				$this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
   534 				$this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
   395 		}
   535 		}
   396 
   536 
   397 		// if it is the last pagenum and there are orphaned pages, display them with paging as well
   537 		// If it is the last pagenum and there are orphaned pages, display them with paging as well.
   398 		if ( isset( $children_pages ) && $count < $end ){
   538 		if ( isset( $children_pages ) && $count < $end ){
   399 			foreach ( $children_pages as $orphans ){
   539 			foreach ( $children_pages as $orphans ){
   400 				foreach ( $orphans as $op ) {
   540 				foreach ( $orphans as $op ) {
   401 					if ( $count >= $end )
   541 					if ( $count >= $end )
   402 						break;
   542 						break;
   403 
   543 
   404 					if ( $count >= $start ) {
   544 					if ( $count >= $start ) {
   405 						echo "\t";
   545 						$to_display[$op->ID] = 0;
   406 						$this->single_row( $op, 0 );
       
   407 					}
   546 					}
   408 
   547 
   409 					$count++;
   548 					$count++;
   410 				}
   549 				}
   411 			}
   550 			}
       
   551 		}
       
   552 
       
   553 		$ids = array_keys( $to_display );
       
   554 		_prime_post_caches( $ids );
       
   555 
       
   556 		if ( ! isset( $GLOBALS['post'] ) ) {
       
   557 			$GLOBALS['post'] = reset( $ids );
       
   558 		}
       
   559 
       
   560 		foreach ( $to_display as $page_id => $level ) {
       
   561 			echo "\t";
       
   562 			$this->single_row( $page_id, $level );
   412 		}
   563 		}
   413 	}
   564 	}
   414 
   565 
   415 	/**
   566 	/**
   416 	 * Given a top level page ID, display the nested hierarchy of sub-pages
   567 	 * Given a top level page ID, display the nested hierarchy of sub-pages
   417 	 * together with paging support
   568 	 * together with paging support
   418 	 *
   569 	 *
   419 	 * @since 3.1.0 (Standalone function exists since 2.6.0)
   570 	 * @since 3.1.0 (Standalone function exists since 2.6.0)
       
   571 	 * @since 4.2.0 Added the `$to_display` parameter.
   420 	 *
   572 	 *
   421 	 * @param array $children_pages
   573 	 * @param array $children_pages
   422 	 * @param int $count
   574 	 * @param int $count
   423 	 * @param int $parent
   575 	 * @param int $parent
   424 	 * @param int $level
   576 	 * @param int $level
   425 	 * @param int $pagenum
   577 	 * @param int $pagenum
   426 	 * @param int $per_page
   578 	 * @param int $per_page
       
   579 	 * @param array $to_display List of pages to be displayed. Passed by reference.
   427 	 */
   580 	 */
   428 	function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page ) {
   581 	private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) {
   429 
   582 
   430 		if ( ! isset( $children_pages[$parent] ) )
   583 		if ( ! isset( $children_pages[$parent] ) )
   431 			return;
   584 			return;
   432 
   585 
   433 		$start = ( $pagenum - 1 ) * $per_page;
   586 		$start = ( $pagenum - 1 ) * $per_page;
   441 			// If the page starts in a subtree, print the parents.
   594 			// If the page starts in a subtree, print the parents.
   442 			if ( $count == $start && $page->post_parent > 0 ) {
   595 			if ( $count == $start && $page->post_parent > 0 ) {
   443 				$my_parents = array();
   596 				$my_parents = array();
   444 				$my_parent = $page->post_parent;
   597 				$my_parent = $page->post_parent;
   445 				while ( $my_parent ) {
   598 				while ( $my_parent ) {
   446 					$my_parent = get_post( $my_parent );
   599 					// Get the ID from the list or the attribute if my_parent is an object
       
   600 					$parent_id = $my_parent;
       
   601 					if ( is_object( $my_parent ) ) {
       
   602 						$parent_id = $my_parent->ID;
       
   603 					}
       
   604 
       
   605 					$my_parent = get_post( $parent_id );
   447 					$my_parents[] = $my_parent;
   606 					$my_parents[] = $my_parent;
   448 					if ( !$my_parent->post_parent )
   607 					if ( !$my_parent->post_parent )
   449 						break;
   608 						break;
   450 					$my_parent = $my_parent->post_parent;
   609 					$my_parent = $my_parent->post_parent;
   451 				}
   610 				}
   452 				$num_parents = count( $my_parents );
   611 				$num_parents = count( $my_parents );
   453 				while ( $my_parent = array_pop( $my_parents ) ) {
   612 				while ( $my_parent = array_pop( $my_parents ) ) {
   454 					echo "\t";
   613 					$to_display[$my_parent->ID] = $level - $num_parents;
   455 					$this->single_row( $my_parent, $level - $num_parents );
       
   456 					$num_parents--;
   614 					$num_parents--;
   457 				}
   615 				}
   458 			}
   616 			}
   459 
   617 
   460 			if ( $count >= $start ) {
   618 			if ( $count >= $start ) {
   461 				echo "\t";
   619 				$to_display[$page->ID] = $level;
   462 				$this->single_row( $page, $level );
       
   463 			}
   620 			}
   464 
   621 
   465 			$count++;
   622 			$count++;
   466 
   623 
   467 			$this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
   624 			$this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
   468 		}
   625 		}
   469 
   626 
   470 		unset( $children_pages[$parent] ); //required in order to keep track of orphans
   627 		unset( $children_pages[$parent] ); //required in order to keep track of orphans
   471 	}
   628 	}
   472 
   629 
   473 	function single_row( $post, $level = 0 ) {
   630 	/**
       
   631 	 * @global string $mode
       
   632 	 * @param WP_Post $post
       
   633 	 * @param int $level
       
   634 	 */
       
   635 	public function single_row( $post, $level = 0 ) {
   474 		global $mode;
   636 		global $mode;
   475 		static $alternate;
       
   476 
   637 
   477 		$global_post = get_post();
   638 		$global_post = get_post();
       
   639 
       
   640 		$post = get_post( $post );
       
   641 
   478 		$GLOBALS['post'] = $post;
   642 		$GLOBALS['post'] = $post;
   479 		setup_postdata( $post );
   643 		setup_postdata( $post );
   480 
   644 
   481 		$edit_link = get_edit_post_link( $post->ID );
   645 		$edit_link = get_edit_post_link( $post->ID );
   482 		$title = _draft_or_post_title();
   646 		$title = _draft_or_post_title();
   483 		$post_type_object = get_post_type_object( $post->post_type );
   647 		$post_type_object = get_post_type_object( $post->post_type );
   484 		$can_edit_post = current_user_can( 'edit_post', $post->ID );
   648 		$can_edit_post = current_user_can( 'edit_post', $post->ID );
   485 
   649 
   486 		$alternate = 'alternate' == $alternate ? '' : 'alternate';
   650 		$classes = 'iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
   487 		$classes = $alternate . ' iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
       
   488 
   651 
   489 		$lock_holder = wp_check_post_lock( $post->ID );
   652 		$lock_holder = wp_check_post_lock( $post->ID );
   490 		if ( $lock_holder ) {
   653 		if ( $lock_holder ) {
   491 			$classes .= ' wp-locked';
   654 			$classes .= ' wp-locked';
   492 			$lock_holder = get_userdata( $lock_holder );
   655 			$lock_holder = get_userdata( $lock_holder );
   493 		}
   656 		}
       
   657 
       
   658 		if ( $post->post_parent ) {
       
   659 		    $count = count( get_post_ancestors( $post->ID ) );
       
   660 		    $classes .= ' level-'. $count;
       
   661 		} else {
       
   662 		    $classes .= ' level-0';
       
   663 		}
   494 	?>
   664 	?>
   495 		<tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>" valign="top">
   665 		<tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>">
   496 	<?php
   666 	<?php
   497 
   667 
   498 		list( $columns, $hidden ) = $this->get_column_info();
   668 		list( $columns, $hidden ) = $this->get_column_info();
   499 
   669 
   500 		foreach ( $columns as $column_name => $column_display_name ) {
   670 		foreach ( $columns as $column_name => $column_display_name ) {
   527 
   697 
   528 			case 'title':
   698 			case 'title':
   529 				$attributes = 'class="post-title page-title column-title"' . $style;
   699 				$attributes = 'class="post-title page-title column-title"' . $style;
   530 				if ( $this->hierarchical_display ) {
   700 				if ( $this->hierarchical_display ) {
   531 					if ( 0 == $level && (int) $post->post_parent > 0 ) {
   701 					if ( 0 == $level && (int) $post->post_parent > 0 ) {
   532 						//sent level 0 by accident, by default, or because we don't know the actual level
   702 						// Sent level 0 by accident, by default, or because we don't know the actual level.
   533 						$find_main_page = (int) $post->post_parent;
   703 						$find_main_page = (int) $post->post_parent;
   534 						while ( $find_main_page > 0 ) {
   704 						while ( $find_main_page > 0 ) {
   535 							$parent = get_post( $find_main_page );
   705 							$parent = get_post( $find_main_page );
   536 
   706 
   537 							if ( is_null( $parent ) )
   707 							if ( is_null( $parent ) )
   583 				if ( ! $this->hierarchical_display && 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) )
   753 				if ( ! $this->hierarchical_display && 'excerpt' == $mode && current_user_can( 'read_post', $post->ID ) )
   584 						the_excerpt();
   754 						the_excerpt();
   585 
   755 
   586 				$actions = array();
   756 				$actions = array();
   587 				if ( $can_edit_post && 'trash' != $post->post_status ) {
   757 				if ( $can_edit_post && 'trash' != $post->post_status ) {
   588 					$actions['edit'] = '<a href="' . get_edit_post_link( $post->ID, true ) . '" title="' . esc_attr( __( 'Edit this item' ) ) . '">' . __( 'Edit' ) . '</a>';
   758 					$actions['edit'] = '<a href="' . get_edit_post_link( $post->ID ) . '" title="' . esc_attr__( 'Edit this item' ) . '">' . __( 'Edit' ) . '</a>';
   589 					$actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr( __( 'Edit this item inline' ) ) . '">' . __( 'Quick&nbsp;Edit' ) . '</a>';
   759 					$actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr__( 'Edit this item inline' ) . '">' . __( 'Quick&nbsp;Edit' ) . '</a>';
   590 				}
   760 				}
   591 				if ( current_user_can( 'delete_post', $post->ID ) ) {
   761 				if ( current_user_can( 'delete_post', $post->ID ) ) {
   592 					if ( 'trash' == $post->post_status )
   762 					if ( 'trash' == $post->post_status )
   593 						$actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this item from the Trash' ) ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";
   763 						$actions['untrash'] = "<a title='" . esc_attr__( 'Restore this item from the Trash' ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore' ) . "</a>";
   594 					elseif ( EMPTY_TRASH_DAYS )
   764 					elseif ( EMPTY_TRASH_DAYS )
   595 						$actions['trash'] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this item to the Trash' ) ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
   765 						$actions['trash'] = "<a class='submitdelete' title='" . esc_attr__( 'Move this item to the Trash' ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash' ) . "</a>";
   596 					if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
   766 					if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS )
   597 						$actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this item permanently' ) ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
   767 						$actions['delete'] = "<a class='submitdelete' title='" . esc_attr__( 'Delete this item permanently' ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently' ) . "</a>";
   598 				}
   768 				}
   599 				if ( $post_type_object->public ) {
   769 				if ( $post_type_object->public ) {
   600 					if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
   770 					if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
   601 						if ( $can_edit_post )
   771 						if ( $can_edit_post ) {
   602 							$actions['view'] = '<a href="' . esc_url( apply_filters( 'preview_post_link', set_url_scheme( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) ) ) . '" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';
   772 							$preview_link = set_url_scheme( get_permalink( $post->ID ) );
       
   773 							/** This filter is documented in wp-admin/includes/meta-boxes.php */
       
   774 							$preview_link = apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ), $post );
       
   775 							$actions['view'] = '<a href="' . esc_url( $preview_link ) . '" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'Preview' ) . '</a>';
       
   776 						}
   603 					} elseif ( 'trash' != $post->post_status ) {
   777 					} elseif ( 'trash' != $post->post_status ) {
   604 						$actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
   778 						$actions['view'] = '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ) . '" rel="permalink">' . __( 'View' ) . '</a>';
   605 					}
   779 					}
   606 				}
   780 				}
   607 
   781 
   608 				$actions = apply_filters( is_post_type_hierarchical( $post->post_type ) ? 'page_row_actions' : 'post_row_actions', $actions, $post );
   782 				if ( is_post_type_hierarchical( $post->post_type ) ) {
       
   783 
       
   784 					/**
       
   785 					 * Filter the array of row action links on the Pages list table.
       
   786 					 *
       
   787 					 * The filter is evaluated only for hierarchical post types.
       
   788 					 *
       
   789 					 * @since 2.8.0
       
   790 					 *
       
   791 					 * @param array   $actions An array of row action links. Defaults are
       
   792 					 *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
       
   793 					 *                         'Delete Permanently', 'Preview', and 'View'.
       
   794 					 * @param WP_Post $post    The post object.
       
   795 					 */
       
   796 					$actions = apply_filters( 'page_row_actions', $actions, $post );
       
   797 				} else {
       
   798 
       
   799 					/**
       
   800 					 * Filter the array of row action links on the Posts list table.
       
   801 					 *
       
   802 					 * The filter is evaluated only for non-hierarchical post types.
       
   803 					 *
       
   804 					 * @since 2.8.0
       
   805 					 *
       
   806 					 * @param array   $actions An array of row action links. Defaults are
       
   807 					 *                         'Edit', 'Quick Edit', 'Restore, 'Trash',
       
   808 					 *                         'Delete Permanently', 'Preview', and 'View'.
       
   809 					 * @param WP_Post $post    The post object.
       
   810 					 */
       
   811 					$actions = apply_filters( 'post_row_actions', $actions, $post );
       
   812 				}
       
   813 
   609 				echo $this->row_actions( $actions );
   814 				echo $this->row_actions( $actions );
   610 
   815 
   611 				get_inline_data( $post );
   816 				get_inline_data( $post );
   612 				echo '</td>';
   817 				echo '</td>';
   613 			break;
   818 			break;
   615 			case 'date':
   820 			case 'date':
   616 				if ( '0000-00-00 00:00:00' == $post->post_date ) {
   821 				if ( '0000-00-00 00:00:00' == $post->post_date ) {
   617 					$t_time = $h_time = __( 'Unpublished' );
   822 					$t_time = $h_time = __( 'Unpublished' );
   618 					$time_diff = 0;
   823 					$time_diff = 0;
   619 				} else {
   824 				} else {
   620 					$t_time = get_the_time( __( 'Y/m/d g:i:s A' ) );
   825 					$t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
   621 					$m_time = $post->post_date;
   826 					$m_time = $post->post_date;
   622 					$time = get_post_time( 'G', true, $post );
   827 					$time = get_post_time( 'G', true, $post );
   623 
   828 
   624 					$time_diff = time() - $time;
   829 					$time_diff = time() - $time;
   625 
   830 
   628 					else
   833 					else
   629 						$h_time = mysql2date( __( 'Y/m/d' ), $m_time );
   834 						$h_time = mysql2date( __( 'Y/m/d' ), $m_time );
   630 				}
   835 				}
   631 
   836 
   632 				echo '<td ' . $attributes . '>';
   837 				echo '<td ' . $attributes . '>';
   633 				if ( 'excerpt' == $mode )
   838 				if ( 'excerpt' == $mode ) {
       
   839 
       
   840 					/**
       
   841 					 * Filter the published time of the post.
       
   842 					 *
       
   843 					 * If $mode equals 'excerpt', the published time and date are both displayed.
       
   844 					 * If $mode equals 'list' (default), the publish date is displayed, with the
       
   845 					 * time and date together available as an abbreviation definition.
       
   846 					 *
       
   847 					 * @since 2.5.1
       
   848 					 *
       
   849 					 * @param array   $t_time      The published time.
       
   850 					 * @param WP_Post $post        Post object.
       
   851 					 * @param string  $column_name The column name.
       
   852 					 * @param string  $mode        The list display mode ('excerpt' or 'list').
       
   853 					 */
   634 					echo apply_filters( 'post_date_column_time', $t_time, $post, $column_name, $mode );
   854 					echo apply_filters( 'post_date_column_time', $t_time, $post, $column_name, $mode );
   635 				else
   855 				} else {
       
   856 
       
   857 					/** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
   636 					echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, $column_name, $mode ) . '</abbr>';
   858 					echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, $column_name, $mode ) . '</abbr>';
       
   859 				}
   637 				echo '<br />';
   860 				echo '<br />';
   638 				if ( 'publish' == $post->post_status ) {
   861 				if ( 'publish' == $post->post_status ) {
   639 					_e( 'Published' );
   862 					_e( 'Published' );
   640 				} elseif ( 'future' == $post->post_status ) {
   863 				} elseif ( 'future' == $post->post_status ) {
   641 					if ( $time_diff > 0 )
   864 					if ( $time_diff > 0 )
   710 					echo '</td>';
   933 					echo '</td>';
   711 					break;
   934 					break;
   712 				}
   935 				}
   713 			?>
   936 			?>
   714 			<td <?php echo $attributes ?>><?php
   937 			<td <?php echo $attributes ?>><?php
   715 				if ( is_post_type_hierarchical( $post->post_type ) )
   938 				if ( is_post_type_hierarchical( $post->post_type ) ) {
       
   939 
       
   940 					/**
       
   941 					 * Fires in each custom column on the Posts list table.
       
   942 					 *
       
   943 					 * This hook only fires if the current post type is hierarchical,
       
   944 					 * such as pages.
       
   945 					 *
       
   946 					 * @since 2.5.0
       
   947 					 *
       
   948 					 * @param string $column_name The name of the column to display.
       
   949 					 * @param int    $post_id     The current post ID.
       
   950 					 */
   716 					do_action( 'manage_pages_custom_column', $column_name, $post->ID );
   951 					do_action( 'manage_pages_custom_column', $column_name, $post->ID );
   717 				else
   952 				} else {
       
   953 
       
   954 					/**
       
   955 					 * Fires in each custom column in the Posts list table.
       
   956 					 *
       
   957 					 * This hook only fires if the current post type is non-hierarchical,
       
   958 					 * such as posts.
       
   959 					 *
       
   960 					 * @since 1.5.0
       
   961 					 *
       
   962 					 * @param string $column_name The name of the column to display.
       
   963 					 * @param int    $post_id     The current post ID.
       
   964 					 */
   718 					do_action( 'manage_posts_custom_column', $column_name, $post->ID );
   965 					do_action( 'manage_posts_custom_column', $column_name, $post->ID );
       
   966 				}
       
   967 
       
   968 				/**
       
   969 				 * Fires for each custom column of a specific post type in the Posts list table.
       
   970 				 *
       
   971 				 * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
       
   972 				 *
       
   973 				 * @since 3.1.0
       
   974 				 *
       
   975 				 * @param string $column_name The name of the column to display.
       
   976 				 * @param int    $post_id     The current post ID.
       
   977 				 */
   719 				do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
   978 				do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
   720 			?></td>
   979 			?></td>
   721 			<?php
   980 			<?php
   722 			break;
   981 			break;
   723 			}
   982 			}
   731 	/**
   990 	/**
   732 	 * Outputs the hidden row displayed when inline editing
   991 	 * Outputs the hidden row displayed when inline editing
   733 	 *
   992 	 *
   734 	 * @since 3.1.0
   993 	 * @since 3.1.0
   735 	 */
   994 	 */
   736 	function inline_edit() {
   995 	public function inline_edit() {
   737 		global $mode;
   996 		global $mode;
   738 
   997 
   739 		$screen = $this->screen;
   998 		$screen = $this->screen;
   740 
   999 
   741 		$post = get_default_post_to_edit( $screen->post_type );
  1000 		$post = get_default_post_to_edit( $screen->post_type );
   743 
  1002 
   744 		$taxonomy_names = get_object_taxonomies( $screen->post_type );
  1003 		$taxonomy_names = get_object_taxonomies( $screen->post_type );
   745 		$hierarchical_taxonomies = array();
  1004 		$hierarchical_taxonomies = array();
   746 		$flat_taxonomies = array();
  1005 		$flat_taxonomies = array();
   747 		foreach ( $taxonomy_names as $taxonomy_name ) {
  1006 		foreach ( $taxonomy_names as $taxonomy_name ) {
       
  1007 
   748 			$taxonomy = get_taxonomy( $taxonomy_name );
  1008 			$taxonomy = get_taxonomy( $taxonomy_name );
   749 
  1009 
   750 			if ( !$taxonomy->show_ui )
  1010 			$show_in_quick_edit = $taxonomy->show_in_quick_edit;
       
  1011 
       
  1012 			/**
       
  1013 			 * Filter whether the current taxonomy should be shown in the Quick Edit panel.
       
  1014 			 *
       
  1015 			 * @since 4.2.0
       
  1016 			 *
       
  1017 			 * @param bool   $show_in_quick_edit Whether to show the current taxonomy in Quick Edit.
       
  1018 			 * @param string $taxonomy_name      Taxonomy name.
       
  1019 			 * @param string $post_type          Post type of current Quick Edit post.
       
  1020 			 */
       
  1021 			if ( ! apply_filters( 'quick_edit_show_taxonomy', $show_in_quick_edit, $taxonomy_name, $screen->post_type ) ) {
   751 				continue;
  1022 				continue;
       
  1023 			}
   752 
  1024 
   753 			if ( $taxonomy->hierarchical )
  1025 			if ( $taxonomy->hierarchical )
   754 				$hierarchical_taxonomies[] = $taxonomy;
  1026 				$hierarchical_taxonomies[] = $taxonomy;
   755 			else
  1027 			else
   756 				$flat_taxonomies[] = $taxonomy;
  1028 				$flat_taxonomies[] = $taxonomy;
   760 		$can_publish = current_user_can( $post_type_object->cap->publish_posts );
  1032 		$can_publish = current_user_can( $post_type_object->cap->publish_posts );
   761 		$core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
  1033 		$core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
   762 
  1034 
   763 	?>
  1035 	?>
   764 
  1036 
   765 	<form method="get" action=""><table style="display: none"><tbody id="inlineedit">
  1037 	<form method="get"><table style="display: none"><tbody id="inlineedit">
   766 		<?php
  1038 		<?php
   767 		$hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page';
  1039 		$hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page';
   768 		$bulk = 0;
  1040 		$bulk = 0;
   769 		while ( $bulk < 2 ) { ?>
  1041 		while ( $bulk < 2 ) { ?>
   770 
  1042 
   830 	?>
  1102 	?>
   831 
  1103 
   832 	<?php if ( !$bulk ) echo $authors_dropdown;
  1104 	<?php if ( !$bulk ) echo $authors_dropdown;
   833 	endif; // post_type_supports author
  1105 	endif; // post_type_supports author
   834 
  1106 
   835 	if ( !$bulk ) :
  1107 	if ( !$bulk && $can_publish ) :
   836 	?>
  1108 	?>
   837 
  1109 
   838 			<div class="inline-edit-group">
  1110 			<div class="inline-edit-group">
   839 				<label class="alignleft">
  1111 				<label class="alignleft">
   840 					<span class="title"><?php _e( 'Password' ); ?></span>
  1112 					<span class="title"><?php _e( 'Password' ); ?></span>
   841 					<span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
  1113 					<span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
   842 				</label>
  1114 				</label>
   843 
  1115 
   844 				<em style="margin:5px 10px 0 0" class="alignleft">
  1116 				<em class="alignleft inline-edit-or">
   845 					<?php
  1117 					<?php
   846 					/* translators: Between password field and private checkbox on post quick edit interface */
  1118 					/* translators: Between password field and private checkbox on post quick edit interface */
   847 					echo __( '&ndash;OR&ndash;' );
  1119 					echo __( '&ndash;OR&ndash;' );
   848 					?>
  1120 					?>
   849 				</em>
  1121 				</em>
   897 			'sort_column'       => 'menu_order, post_title',
  1169 			'sort_column'       => 'menu_order, post_title',
   898 		);
  1170 		);
   899 
  1171 
   900 		if ( $bulk )
  1172 		if ( $bulk )
   901 			$dropdown_args['show_option_no_change'] =  __( '&mdash; No Change &mdash;' );
  1173 			$dropdown_args['show_option_no_change'] =  __( '&mdash; No Change &mdash;' );
       
  1174 
       
  1175 		/**
       
  1176 		 * Filter the arguments used to generate the Quick Edit page-parent drop-down.
       
  1177 		 *
       
  1178 		 * @since 2.7.0
       
  1179 		 *
       
  1180 		 * @see wp_dropdown_pages()
       
  1181 		 *
       
  1182 		 * @param array $dropdown_args An array of arguments.
       
  1183 		 */
   902 		$dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args );
  1184 		$dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args );
       
  1185 
   903 		wp_dropdown_pages( $dropdown_args );
  1186 		wp_dropdown_pages( $dropdown_args );
   904 	?>
  1187 	?>
   905 			</label>
  1188 			</label>
   906 
  1189 
   907 	<?php
  1190 	<?php
   923 				<span class="title"><?php _e( 'Template' ); ?></span>
  1206 				<span class="title"><?php _e( 'Template' ); ?></span>
   924 				<select name="page_template">
  1207 				<select name="page_template">
   925 	<?php	if ( $bulk ) : ?>
  1208 	<?php	if ( $bulk ) : ?>
   926 					<option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
  1209 					<option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
   927 	<?php	endif; // $bulk ?>
  1210 	<?php	endif; // $bulk ?>
   928 					<option value="default"><?php _e( 'Default Template' ); ?></option>
  1211     				<?php
       
  1212 					/** This filter is documented in wp-admin/includes/meta-boxes.php */
       
  1213 					$default_title = apply_filters( 'default_page_template_title',  __( 'Default Template' ), 'quick-edit' );
       
  1214     				?>
       
  1215 					<option value="default"><?php echo esc_html( $default_title ); ?></option>
   929 					<?php page_template_dropdown() ?>
  1216 					<?php page_template_dropdown() ?>
   930 				</select>
  1217 				</select>
   931 			</label>
  1218 			</label>
   932 
  1219 
   933 	<?php
  1220 	<?php
  1038 
  1325 
  1039 			</div>
  1326 			</div>
  1040 
  1327 
  1041 	<?php
  1328 	<?php
  1042 
  1329 
  1043 	if ( $bulk && post_type_supports( $screen->post_type, 'post-formats' ) ) {
  1330 	if ( $bulk && current_theme_supports( 'post-formats' ) && post_type_supports( $screen->post_type, 'post-formats' ) ) {
  1044 		$all_post_formats = get_post_format_strings();
  1331 		$post_formats = get_theme_support( 'post-formats' );
  1045 
  1332 
  1046 		?>
  1333 		?>
  1047 		<label class="alignleft" for="post_format">
  1334 		<label class="alignleft" for="post_format">
  1048 		<span class="title"><?php _ex( 'Format', 'post format' ); ?></span>
  1335 		<span class="title"><?php _ex( 'Format', 'post format' ); ?></span>
  1049 		<select name="post_format">
  1336 		<select name="post_format">
  1050 			<option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
  1337 			<option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
       
  1338 			<option value="0"><?php echo get_post_format_string( 'standard' ); ?></option>
  1051 			<?php
  1339 			<?php
  1052 
  1340 
  1053 			foreach ( $all_post_formats as $slug => $format ) {
  1341 			foreach ( $post_formats[0] as $format ) {
  1054 				?>
  1342 				?>
  1055 				<option value="<?php echo esc_attr( $slug ); ?>"><?php echo esc_html( $format ); ?></option>
  1343 				<option value="<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></option>
  1056 				<?php
  1344 				<?php
  1057 			}
  1345 			}
  1058 
  1346 
  1059 			?>
  1347 			?>
  1060 		</select></label>
  1348 		</select></label>
  1070 		list( $columns ) = $this->get_column_info();
  1358 		list( $columns ) = $this->get_column_info();
  1071 
  1359 
  1072 		foreach ( $columns as $column_name => $column_display_name ) {
  1360 		foreach ( $columns as $column_name => $column_display_name ) {
  1073 			if ( isset( $core_columns[$column_name] ) )
  1361 			if ( isset( $core_columns[$column_name] ) )
  1074 				continue;
  1362 				continue;
  1075 			do_action( $bulk ? 'bulk_edit_custom_box' : 'quick_edit_custom_box', $column_name, $screen->post_type );
  1363 
       
  1364 			if ( $bulk ) {
       
  1365 
       
  1366 				/**
       
  1367 				 * Fires once for each column in Bulk Edit mode.
       
  1368 				 *
       
  1369 				 * @since 2.7.0
       
  1370 				 *
       
  1371 				 * @param string  $column_name Name of the column to edit.
       
  1372 				 * @param WP_Post $post_type   The post type slug.
       
  1373 				 */
       
  1374 				do_action( 'bulk_edit_custom_box', $column_name, $screen->post_type );
       
  1375 			} else {
       
  1376 
       
  1377 				/**
       
  1378 				 * Fires once for each column in Quick Edit mode.
       
  1379 				 *
       
  1380 				 * @since 2.7.0
       
  1381 				 *
       
  1382 				 * @param string  $column_name Name of the column to edit.
       
  1383 				 * @param WP_Post $post_type   The post type slug.
       
  1384 				 */
       
  1385 				do_action( 'quick_edit_custom_box', $column_name, $screen->post_type );
       
  1386 			}
       
  1387 
  1076 		}
  1388 		}
  1077 	?>
  1389 	?>
  1078 		<p class="submit inline-edit-save">
  1390 		<p class="submit inline-edit-save">
  1079 			<a accesskey="c" href="#inline-edit" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></a>
  1391 			<a href="#inline-edit" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></a>
  1080 			<?php if ( ! $bulk ) {
  1392 			<?php if ( ! $bulk ) {
  1081 				wp_nonce_field( 'inlineeditnonce', '_inline_edit', false );
  1393 				wp_nonce_field( 'inlineeditnonce', '_inline_edit', false );
  1082 				?>
  1394 				?>
  1083 				<a accesskey="s" href="#inline-edit" class="button-primary save alignright"><?php _e( 'Update' ); ?></a>
  1395 				<a href="#inline-edit" class="button-primary save alignright"><?php _e( 'Update' ); ?></a>
  1084 				<span class="spinner"></span>
  1396 				<span class="spinner"></span>
  1085 			<?php } else {
  1397 			<?php } else {
  1086 				submit_button( __( 'Update' ), 'button-primary alignright', 'bulk_edit', false, array( 'accesskey' => 's' ) );
  1398 				submit_button( __( 'Update' ), 'button-primary alignright', 'bulk_edit', false );
  1087 			} ?>
  1399 			} ?>
  1088 			<input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" />
  1400 			<input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" />
  1089 			<input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" />
  1401 			<input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" />
  1090 			<?php if ( ! $bulk && ! post_type_supports( $screen->post_type, 'author' ) ) { ?>
  1402 			<?php if ( ! $bulk && ! post_type_supports( $screen->post_type, 'author' ) ) { ?>
  1091 				<input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
  1403 				<input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />