class-wp-posts-list-table.php 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772
  1. <?php
  2. /**
  3. * List Table API: WP_Posts_List_Table class
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. * @since 3.1.0
  8. */
  9. /**
  10. * Core class used to implement displaying posts in a list table.
  11. *
  12. * @since 3.1.0
  13. * @access private
  14. *
  15. * @see WP_List_Table
  16. */
  17. class WP_Posts_List_Table extends WP_List_Table {
  18. /**
  19. * Whether the items should be displayed hierarchically or linearly.
  20. *
  21. * @since 3.1.0
  22. * @var bool
  23. */
  24. protected $hierarchical_display;
  25. /**
  26. * Holds the number of pending comments for each post.
  27. *
  28. * @since 3.1.0
  29. * @var array
  30. */
  31. protected $comment_pending_count;
  32. /**
  33. * Holds the number of posts for this user.
  34. *
  35. * @since 3.1.0
  36. * @var int
  37. */
  38. private $user_posts_count;
  39. /**
  40. * Holds the number of posts which are sticky.
  41. *
  42. * @since 3.1.0
  43. * @var int
  44. */
  45. private $sticky_posts_count = 0;
  46. private $is_trash;
  47. /**
  48. * Current level for output.
  49. *
  50. * @since 4.3.0
  51. * @var int
  52. */
  53. protected $current_level = 0;
  54. /**
  55. * Constructor.
  56. *
  57. * @since 3.1.0
  58. *
  59. * @see WP_List_Table::__construct() for more information on default arguments.
  60. *
  61. * @global WP_Post_Type $post_type_object
  62. * @global wpdb $wpdb
  63. *
  64. * @param array $args An associative array of arguments.
  65. */
  66. public function __construct( $args = array() ) {
  67. global $post_type_object, $wpdb;
  68. parent::__construct( array(
  69. 'plural' => 'posts',
  70. 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
  71. ) );
  72. $post_type = $this->screen->post_type;
  73. $post_type_object = get_post_type_object( $post_type );
  74. $exclude_states = get_post_stati( array(
  75. 'show_in_admin_all_list' => false,
  76. ) );
  77. $this->user_posts_count = intval( $wpdb->get_var( $wpdb->prepare( "
  78. SELECT COUNT( 1 )
  79. FROM $wpdb->posts
  80. WHERE post_type = %s
  81. AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
  82. AND post_author = %d
  83. ", $post_type, get_current_user_id() ) ) );
  84. if ( $this->user_posts_count && ! current_user_can( $post_type_object->cap->edit_others_posts ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) ) {
  85. $_GET['author'] = get_current_user_id();
  86. }
  87. if ( 'post' === $post_type && $sticky_posts = get_option( 'sticky_posts' ) ) {
  88. $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
  89. $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 ) );
  90. }
  91. }
  92. /**
  93. * Sets whether the table layout should be hierarchical or not.
  94. *
  95. * @since 4.2.0
  96. *
  97. * @param bool $display Whether the table layout should be hierarchical.
  98. */
  99. public function set_hierarchical_display( $display ) {
  100. $this->hierarchical_display = $display;
  101. }
  102. /**
  103. *
  104. * @return bool
  105. */
  106. public function ajax_user_can() {
  107. return current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_posts );
  108. }
  109. /**
  110. *
  111. * @global array $avail_post_stati
  112. * @global WP_Query $wp_query
  113. * @global int $per_page
  114. * @global string $mode
  115. */
  116. public function prepare_items() {
  117. global $avail_post_stati, $wp_query, $per_page, $mode;
  118. // is going to call wp()
  119. $avail_post_stati = wp_edit_posts_query();
  120. $this->set_hierarchical_display( is_post_type_hierarchical( $this->screen->post_type ) && 'menu_order title' === $wp_query->query['orderby'] );
  121. $post_type = $this->screen->post_type;
  122. $per_page = $this->get_items_per_page( 'edit_' . $post_type . '_per_page' );
  123. /** This filter is documented in wp-admin/includes/post.php */
  124. $per_page = apply_filters( 'edit_posts_per_page', $per_page, $post_type );
  125. if ( $this->hierarchical_display ) {
  126. $total_items = $wp_query->post_count;
  127. } elseif ( $wp_query->found_posts || $this->get_pagenum() === 1 ) {
  128. $total_items = $wp_query->found_posts;
  129. } else {
  130. $post_counts = (array) wp_count_posts( $post_type, 'readable' );
  131. if ( isset( $_REQUEST['post_status'] ) && in_array( $_REQUEST['post_status'] , $avail_post_stati ) ) {
  132. $total_items = $post_counts[ $_REQUEST['post_status'] ];
  133. } elseif ( isset( $_REQUEST['show_sticky'] ) && $_REQUEST['show_sticky'] ) {
  134. $total_items = $this->sticky_posts_count;
  135. } elseif ( isset( $_GET['author'] ) && $_GET['author'] == get_current_user_id() ) {
  136. $total_items = $this->user_posts_count;
  137. } else {
  138. $total_items = array_sum( $post_counts );
  139. // Subtract post types that are not included in the admin all list.
  140. foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
  141. $total_items -= $post_counts[ $state ];
  142. }
  143. }
  144. }
  145. if ( ! empty( $_REQUEST['mode'] ) ) {
  146. $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
  147. set_user_setting( 'posts_list_mode', $mode );
  148. } else {
  149. $mode = get_user_setting( 'posts_list_mode', 'list' );
  150. }
  151. $this->is_trash = isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] === 'trash';
  152. $this->set_pagination_args( array(
  153. 'total_items' => $total_items,
  154. 'per_page' => $per_page
  155. ) );
  156. }
  157. /**
  158. *
  159. * @return bool
  160. */
  161. public function has_items() {
  162. return have_posts();
  163. }
  164. /**
  165. */
  166. public function no_items() {
  167. if ( isset( $_REQUEST['post_status'] ) && 'trash' === $_REQUEST['post_status'] )
  168. echo get_post_type_object( $this->screen->post_type )->labels->not_found_in_trash;
  169. else
  170. echo get_post_type_object( $this->screen->post_type )->labels->not_found;
  171. }
  172. /**
  173. * Determine if the current view is the "All" view.
  174. *
  175. * @since 4.2.0
  176. *
  177. * @return bool Whether the current view is the "All" view.
  178. */
  179. protected function is_base_request() {
  180. $vars = $_GET;
  181. unset( $vars['paged'] );
  182. if ( empty( $vars ) ) {
  183. return true;
  184. } elseif ( 1 === count( $vars ) && ! empty( $vars['post_type'] ) ) {
  185. return $this->screen->post_type === $vars['post_type'];
  186. }
  187. return 1 === count( $vars ) && ! empty( $vars['mode'] );
  188. }
  189. /**
  190. * Helper to create links to edit.php with params.
  191. *
  192. * @since 4.4.0
  193. *
  194. * @param array $args URL parameters for the link.
  195. * @param string $label Link text.
  196. * @param string $class Optional. Class attribute. Default empty string.
  197. * @return string The formatted link string.
  198. */
  199. protected function get_edit_link( $args, $label, $class = '' ) {
  200. $url = add_query_arg( $args, 'edit.php' );
  201. $class_html = $aria_current = '';
  202. if ( ! empty( $class ) ) {
  203. $class_html = sprintf(
  204. ' class="%s"',
  205. esc_attr( $class )
  206. );
  207. if ( 'current' === $class ) {
  208. $aria_current = ' aria-current="page"';
  209. }
  210. }
  211. return sprintf(
  212. '<a href="%s"%s%s>%s</a>',
  213. esc_url( $url ),
  214. $class_html,
  215. $aria_current,
  216. $label
  217. );
  218. }
  219. /**
  220. *
  221. * @global array $locked_post_status This seems to be deprecated.
  222. * @global array $avail_post_stati
  223. * @return array
  224. */
  225. protected function get_views() {
  226. global $locked_post_status, $avail_post_stati;
  227. $post_type = $this->screen->post_type;
  228. if ( !empty($locked_post_status) )
  229. return array();
  230. $status_links = array();
  231. $num_posts = wp_count_posts( $post_type, 'readable' );
  232. $total_posts = array_sum( (array) $num_posts );
  233. $class = '';
  234. $current_user_id = get_current_user_id();
  235. $all_args = array( 'post_type' => $post_type );
  236. $mine = '';
  237. // Subtract post types that are not included in the admin all list.
  238. foreach ( get_post_stati( array( 'show_in_admin_all_list' => false ) ) as $state ) {
  239. $total_posts -= $num_posts->$state;
  240. }
  241. if ( $this->user_posts_count && $this->user_posts_count !== $total_posts ) {
  242. if ( isset( $_GET['author'] ) && ( $_GET['author'] == $current_user_id ) ) {
  243. $class = 'current';
  244. }
  245. $mine_args = array(
  246. 'post_type' => $post_type,
  247. 'author' => $current_user_id
  248. );
  249. $mine_inner_html = sprintf(
  250. _nx(
  251. 'Mine <span class="count">(%s)</span>',
  252. 'Mine <span class="count">(%s)</span>',
  253. $this->user_posts_count,
  254. 'posts'
  255. ),
  256. number_format_i18n( $this->user_posts_count )
  257. );
  258. $mine = $this->get_edit_link( $mine_args, $mine_inner_html, $class );
  259. $all_args['all_posts'] = 1;
  260. $class = '';
  261. }
  262. if ( empty( $class ) && ( $this->is_base_request() || isset( $_REQUEST['all_posts'] ) ) ) {
  263. $class = 'current';
  264. }
  265. $all_inner_html = sprintf(
  266. _nx(
  267. 'All <span class="count">(%s)</span>',
  268. 'All <span class="count">(%s)</span>',
  269. $total_posts,
  270. 'posts'
  271. ),
  272. number_format_i18n( $total_posts )
  273. );
  274. $status_links['all'] = $this->get_edit_link( $all_args, $all_inner_html, $class );
  275. if ( $mine ) {
  276. $status_links['mine'] = $mine;
  277. }
  278. foreach ( get_post_stati(array('show_in_admin_status_list' => true), 'objects') as $status ) {
  279. $class = '';
  280. $status_name = $status->name;
  281. if ( ! in_array( $status_name, $avail_post_stati ) || empty( $num_posts->$status_name ) ) {
  282. continue;
  283. }
  284. if ( isset($_REQUEST['post_status']) && $status_name === $_REQUEST['post_status'] ) {
  285. $class = 'current';
  286. }
  287. $status_args = array(
  288. 'post_status' => $status_name,
  289. 'post_type' => $post_type,
  290. );
  291. $status_label = sprintf(
  292. translate_nooped_plural( $status->label_count, $num_posts->$status_name ),
  293. number_format_i18n( $num_posts->$status_name )
  294. );
  295. $status_links[ $status_name ] = $this->get_edit_link( $status_args, $status_label, $class );
  296. }
  297. if ( ! empty( $this->sticky_posts_count ) ) {
  298. $class = ! empty( $_REQUEST['show_sticky'] ) ? 'current' : '';
  299. $sticky_args = array(
  300. 'post_type' => $post_type,
  301. 'show_sticky' => 1
  302. );
  303. $sticky_inner_html = sprintf(
  304. _nx(
  305. 'Sticky <span class="count">(%s)</span>',
  306. 'Sticky <span class="count">(%s)</span>',
  307. $this->sticky_posts_count,
  308. 'posts'
  309. ),
  310. number_format_i18n( $this->sticky_posts_count )
  311. );
  312. $sticky_link = array(
  313. 'sticky' => $this->get_edit_link( $sticky_args, $sticky_inner_html, $class )
  314. );
  315. // Sticky comes after Publish, or if not listed, after All.
  316. $split = 1 + array_search( ( isset( $status_links['publish'] ) ? 'publish' : 'all' ), array_keys( $status_links ) );
  317. $status_links = array_merge( array_slice( $status_links, 0, $split ), $sticky_link, array_slice( $status_links, $split ) );
  318. }
  319. return $status_links;
  320. }
  321. /**
  322. *
  323. * @return array
  324. */
  325. protected function get_bulk_actions() {
  326. $actions = array();
  327. $post_type_obj = get_post_type_object( $this->screen->post_type );
  328. if ( current_user_can( $post_type_obj->cap->edit_posts ) ) {
  329. if ( $this->is_trash ) {
  330. $actions['untrash'] = __( 'Restore' );
  331. } else {
  332. $actions['edit'] = __( 'Edit' );
  333. }
  334. }
  335. if ( current_user_can( $post_type_obj->cap->delete_posts ) ) {
  336. if ( $this->is_trash || ! EMPTY_TRASH_DAYS ) {
  337. $actions['delete'] = __( 'Delete Permanently' );
  338. } else {
  339. $actions['trash'] = __( 'Move to Trash' );
  340. }
  341. }
  342. return $actions;
  343. }
  344. /**
  345. * Displays a categories drop-down for filtering on the Posts list table.
  346. *
  347. * @since 4.6.0
  348. *
  349. * @global int $cat Currently selected category.
  350. *
  351. * @param string $post_type Post type slug.
  352. */
  353. protected function categories_dropdown( $post_type ) {
  354. global $cat;
  355. /**
  356. * Filters whether to remove the 'Categories' drop-down from the post list table.
  357. *
  358. * @since 4.6.0
  359. *
  360. * @param bool $disable Whether to disable the categories drop-down. Default false.
  361. * @param string $post_type Post type slug.
  362. */
  363. if ( false !== apply_filters( 'disable_categories_dropdown', false, $post_type ) ) {
  364. return;
  365. }
  366. if ( is_object_in_taxonomy( $post_type, 'category' ) ) {
  367. $dropdown_options = array(
  368. 'show_option_all' => get_taxonomy( 'category' )->labels->all_items,
  369. 'hide_empty' => 0,
  370. 'hierarchical' => 1,
  371. 'show_count' => 0,
  372. 'orderby' => 'name',
  373. 'selected' => $cat
  374. );
  375. echo '<label class="screen-reader-text" for="cat">' . __( 'Filter by category' ) . '</label>';
  376. wp_dropdown_categories( $dropdown_options );
  377. }
  378. }
  379. /**
  380. * @param string $which
  381. */
  382. protected function extra_tablenav( $which ) {
  383. ?>
  384. <div class="alignleft actions">
  385. <?php
  386. if ( 'top' === $which && !is_singular() ) {
  387. ob_start();
  388. $this->months_dropdown( $this->screen->post_type );
  389. $this->categories_dropdown( $this->screen->post_type );
  390. /**
  391. * Fires before the Filter button on the Posts and Pages list tables.
  392. *
  393. * The Filter button allows sorting by date and/or category on the
  394. * Posts list table, and sorting by date on the Pages list table.
  395. *
  396. * @since 2.1.0
  397. * @since 4.4.0 The `$post_type` parameter was added.
  398. * @since 4.6.0 The `$which` parameter was added.
  399. *
  400. * @param string $post_type The post type slug.
  401. * @param string $which The location of the extra table nav markup:
  402. * 'top' or 'bottom' for WP_Posts_List_Table,
  403. * 'bar' for WP_Media_List_Table.
  404. */
  405. do_action( 'restrict_manage_posts', $this->screen->post_type, $which );
  406. $output = ob_get_clean();
  407. if ( ! empty( $output ) ) {
  408. echo $output;
  409. submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
  410. }
  411. }
  412. if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) && $this->has_items() ) {
  413. submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false );
  414. }
  415. ?>
  416. </div>
  417. <?php
  418. /**
  419. * Fires immediately following the closing "actions" div in the tablenav for the posts
  420. * list table.
  421. *
  422. * @since 4.4.0
  423. *
  424. * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
  425. */
  426. do_action( 'manage_posts_extra_tablenav', $which );
  427. }
  428. /**
  429. *
  430. * @return string
  431. */
  432. public function current_action() {
  433. if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
  434. return 'delete_all';
  435. return parent::current_action();
  436. }
  437. /**
  438. *
  439. * @return array
  440. */
  441. protected function get_table_classes() {
  442. return array( 'widefat', 'fixed', 'striped', is_post_type_hierarchical( $this->screen->post_type ) ? 'pages' : 'posts' );
  443. }
  444. /**
  445. *
  446. * @return array
  447. */
  448. public function get_columns() {
  449. $post_type = $this->screen->post_type;
  450. $posts_columns = array();
  451. $posts_columns['cb'] = '<input type="checkbox" />';
  452. /* translators: manage posts column name */
  453. $posts_columns['title'] = _x( 'Title', 'column name' );
  454. if ( post_type_supports( $post_type, 'author' ) ) {
  455. $posts_columns['author'] = __( 'Author' );
  456. }
  457. $taxonomies = get_object_taxonomies( $post_type, 'objects' );
  458. $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
  459. /**
  460. * Filters the taxonomy columns in the Posts list table.
  461. *
  462. * The dynamic portion of the hook name, `$post_type`, refers to the post
  463. * type slug.
  464. *
  465. * @since 3.5.0
  466. *
  467. * @param array $taxonomies Array of taxonomies to show columns for.
  468. * @param string $post_type The post type.
  469. */
  470. $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
  471. $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
  472. foreach ( $taxonomies as $taxonomy ) {
  473. if ( 'category' === $taxonomy )
  474. $column_key = 'categories';
  475. elseif ( 'post_tag' === $taxonomy )
  476. $column_key = 'tags';
  477. else
  478. $column_key = 'taxonomy-' . $taxonomy;
  479. $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
  480. }
  481. $post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
  482. if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) )
  483. $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>';
  484. $posts_columns['date'] = __( 'Date' );
  485. if ( 'page' === $post_type ) {
  486. /**
  487. * Filters the columns displayed in the Pages list table.
  488. *
  489. * @since 2.5.0
  490. *
  491. * @param array $post_columns An array of column names.
  492. */
  493. $posts_columns = apply_filters( 'manage_pages_columns', $posts_columns );
  494. } else {
  495. /**
  496. * Filters the columns displayed in the Posts list table.
  497. *
  498. * @since 1.5.0
  499. *
  500. * @param array $posts_columns An array of column names.
  501. * @param string $post_type The post type slug.
  502. */
  503. $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
  504. }
  505. /**
  506. * Filters the columns displayed in the Posts list table for a specific post type.
  507. *
  508. * The dynamic portion of the hook name, `$post_type`, refers to the post type slug.
  509. *
  510. * @since 3.0.0
  511. *
  512. * @param array $post_columns An array of column names.
  513. */
  514. return apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
  515. }
  516. /**
  517. *
  518. * @return array
  519. */
  520. protected function get_sortable_columns() {
  521. return array(
  522. 'title' => 'title',
  523. 'parent' => 'parent',
  524. 'comments' => 'comment_count',
  525. 'date' => array( 'date', true )
  526. );
  527. }
  528. /**
  529. * @global WP_Query $wp_query
  530. * @global int $per_page
  531. * @param array $posts
  532. * @param int $level
  533. */
  534. public function display_rows( $posts = array(), $level = 0 ) {
  535. global $wp_query, $per_page;
  536. if ( empty( $posts ) )
  537. $posts = $wp_query->posts;
  538. add_filter( 'the_title', 'esc_html' );
  539. if ( $this->hierarchical_display ) {
  540. $this->_display_rows_hierarchical( $posts, $this->get_pagenum(), $per_page );
  541. } else {
  542. $this->_display_rows( $posts, $level );
  543. }
  544. }
  545. /**
  546. * @param array $posts
  547. * @param int $level
  548. */
  549. private function _display_rows( $posts, $level = 0 ) {
  550. // Create array of post IDs.
  551. $post_ids = array();
  552. foreach ( $posts as $a_post )
  553. $post_ids[] = $a_post->ID;
  554. $this->comment_pending_count = get_pending_comments_num( $post_ids );
  555. foreach ( $posts as $post )
  556. $this->single_row( $post, $level );
  557. }
  558. /**
  559. * @global wpdb $wpdb
  560. * @global WP_Post $post
  561. * @param array $pages
  562. * @param int $pagenum
  563. * @param int $per_page
  564. */
  565. private function _display_rows_hierarchical( $pages, $pagenum = 1, $per_page = 20 ) {
  566. global $wpdb;
  567. $level = 0;
  568. if ( ! $pages ) {
  569. $pages = get_pages( array( 'sort_column' => 'menu_order' ) );
  570. if ( ! $pages )
  571. return;
  572. }
  573. /*
  574. * Arrange pages into two parts: top level pages and children_pages
  575. * children_pages is two dimensional array, eg.
  576. * children_pages[10][] contains all sub-pages whose parent is 10.
  577. * It only takes O( N ) to arrange this and it takes O( 1 ) for subsequent lookup operations
  578. * If searching, ignore hierarchy and treat everything as top level
  579. */
  580. if ( empty( $_REQUEST['s'] ) ) {
  581. $top_level_pages = array();
  582. $children_pages = array();
  583. foreach ( $pages as $page ) {
  584. // Catch and repair bad pages.
  585. if ( $page->post_parent == $page->ID ) {
  586. $page->post_parent = 0;
  587. $wpdb->update( $wpdb->posts, array( 'post_parent' => 0 ), array( 'ID' => $page->ID ) );
  588. clean_post_cache( $page );
  589. }
  590. if ( 0 == $page->post_parent )
  591. $top_level_pages[] = $page;
  592. else
  593. $children_pages[ $page->post_parent ][] = $page;
  594. }
  595. $pages = &$top_level_pages;
  596. }
  597. $count = 0;
  598. $start = ( $pagenum - 1 ) * $per_page;
  599. $end = $start + $per_page;
  600. $to_display = array();
  601. foreach ( $pages as $page ) {
  602. if ( $count >= $end )
  603. break;
  604. if ( $count >= $start ) {
  605. $to_display[$page->ID] = $level;
  606. }
  607. $count++;
  608. if ( isset( $children_pages ) )
  609. $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
  610. }
  611. // If it is the last pagenum and there are orphaned pages, display them with paging as well.
  612. if ( isset( $children_pages ) && $count < $end ){
  613. foreach ( $children_pages as $orphans ){
  614. foreach ( $orphans as $op ) {
  615. if ( $count >= $end )
  616. break;
  617. if ( $count >= $start ) {
  618. $to_display[$op->ID] = 0;
  619. }
  620. $count++;
  621. }
  622. }
  623. }
  624. $ids = array_keys( $to_display );
  625. _prime_post_caches( $ids );
  626. if ( ! isset( $GLOBALS['post'] ) ) {
  627. $GLOBALS['post'] = reset( $ids );
  628. }
  629. foreach ( $to_display as $page_id => $level ) {
  630. echo "\t";
  631. $this->single_row( $page_id, $level );
  632. }
  633. }
  634. /**
  635. * Given a top level page ID, display the nested hierarchy of sub-pages
  636. * together with paging support
  637. *
  638. * @since 3.1.0 (Standalone function exists since 2.6.0)
  639. * @since 4.2.0 Added the `$to_display` parameter.
  640. *
  641. * @param array $children_pages
  642. * @param int $count
  643. * @param int $parent
  644. * @param int $level
  645. * @param int $pagenum
  646. * @param int $per_page
  647. * @param array $to_display List of pages to be displayed. Passed by reference.
  648. */
  649. private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) {
  650. if ( ! isset( $children_pages[$parent] ) )
  651. return;
  652. $start = ( $pagenum - 1 ) * $per_page;
  653. $end = $start + $per_page;
  654. foreach ( $children_pages[$parent] as $page ) {
  655. if ( $count >= $end )
  656. break;
  657. // If the page starts in a subtree, print the parents.
  658. if ( $count == $start && $page->post_parent > 0 ) {
  659. $my_parents = array();
  660. $my_parent = $page->post_parent;
  661. while ( $my_parent ) {
  662. // Get the ID from the list or the attribute if my_parent is an object
  663. $parent_id = $my_parent;
  664. if ( is_object( $my_parent ) ) {
  665. $parent_id = $my_parent->ID;
  666. }
  667. $my_parent = get_post( $parent_id );
  668. $my_parents[] = $my_parent;
  669. if ( !$my_parent->post_parent )
  670. break;
  671. $my_parent = $my_parent->post_parent;
  672. }
  673. $num_parents = count( $my_parents );
  674. while ( $my_parent = array_pop( $my_parents ) ) {
  675. $to_display[$my_parent->ID] = $level - $num_parents;
  676. $num_parents--;
  677. }
  678. }
  679. if ( $count >= $start ) {
  680. $to_display[$page->ID] = $level;
  681. }
  682. $count++;
  683. $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
  684. }
  685. unset( $children_pages[$parent] ); //required in order to keep track of orphans
  686. }
  687. /**
  688. * Handles the checkbox column output.
  689. *
  690. * @since 4.3.0
  691. *
  692. * @param WP_Post $post The current WP_Post object.
  693. */
  694. public function column_cb( $post ) {
  695. if ( current_user_can( 'edit_post', $post->ID ) ): ?>
  696. <label class="screen-reader-text" for="cb-select-<?php the_ID(); ?>"><?php
  697. printf( __( 'Select %s' ), _draft_or_post_title() );
  698. ?></label>
  699. <input id="cb-select-<?php the_ID(); ?>" type="checkbox" name="post[]" value="<?php the_ID(); ?>" />
  700. <div class="locked-indicator">
  701. <span class="locked-indicator-icon" aria-hidden="true"></span>
  702. <span class="screen-reader-text"><?php
  703. printf(
  704. /* translators: %s: post title */
  705. __( '&#8220;%s&#8221; is locked' ),
  706. _draft_or_post_title()
  707. );
  708. ?></span>
  709. </div>
  710. <?php endif;
  711. }
  712. /**
  713. * @since 4.3.0
  714. *
  715. * @param WP_Post $post
  716. * @param string $classes
  717. * @param string $data
  718. * @param string $primary
  719. */
  720. protected function _column_title( $post, $classes, $data, $primary ) {
  721. echo '<td class="' . $classes . ' page-title" ', $data, '>';
  722. echo $this->column_title( $post );
  723. echo $this->handle_row_actions( $post, 'title', $primary );
  724. echo '</td>';
  725. }
  726. /**
  727. * Handles the title column output.
  728. *
  729. * @since 4.3.0
  730. *
  731. * @global string $mode List table view mode.
  732. *
  733. * @param WP_Post $post The current WP_Post object.
  734. */
  735. public function column_title( $post ) {
  736. global $mode;
  737. if ( $this->hierarchical_display ) {
  738. if ( 0 === $this->current_level && (int) $post->post_parent > 0 ) {
  739. // Sent level 0 by accident, by default, or because we don't know the actual level.
  740. $find_main_page = (int) $post->post_parent;
  741. while ( $find_main_page > 0 ) {
  742. $parent = get_post( $find_main_page );
  743. if ( is_null( $parent ) ) {
  744. break;
  745. }
  746. $this->current_level++;
  747. $find_main_page = (int) $parent->post_parent;
  748. if ( ! isset( $parent_name ) ) {
  749. /** This filter is documented in wp-includes/post-template.php */
  750. $parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
  751. }
  752. }
  753. }
  754. }
  755. $can_edit_post = current_user_can( 'edit_post', $post->ID );
  756. if ( $can_edit_post && $post->post_status != 'trash' ) {
  757. $lock_holder = wp_check_post_lock( $post->ID );
  758. if ( $lock_holder ) {
  759. $lock_holder = get_userdata( $lock_holder );
  760. $locked_avatar = get_avatar( $lock_holder->ID, 18 );
  761. $locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
  762. } else {
  763. $locked_avatar = $locked_text = '';
  764. }
  765. echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
  766. }
  767. $pad = str_repeat( '&#8212; ', $this->current_level );
  768. echo "<strong>";
  769. $format = get_post_format( $post->ID );
  770. if ( $format ) {
  771. $label = get_post_format_string( $format );
  772. $format_class = 'post-state-format post-format-icon post-format-' . $format;
  773. $format_args = array(
  774. 'post_format' => $format,
  775. 'post_type' => $post->post_type
  776. );
  777. echo $this->get_edit_link( $format_args, $label . ':', $format_class );
  778. }
  779. $title = _draft_or_post_title();
  780. if ( $can_edit_post && $post->post_status != 'trash' ) {
  781. printf(
  782. '<a class="row-title" href="%s" aria-label="%s">%s%s</a>',
  783. get_edit_post_link( $post->ID ),
  784. /* translators: %s: post title */
  785. esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $title ) ),
  786. $pad,
  787. $title
  788. );
  789. } else {
  790. echo $pad . $title;
  791. }
  792. _post_states( $post );
  793. if ( isset( $parent_name ) ) {
  794. $post_type_object = get_post_type_object( $post->post_type );
  795. echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
  796. }
  797. echo "</strong>\n";
  798. if ( ! is_post_type_hierarchical( $this->screen->post_type ) && 'excerpt' === $mode && current_user_can( 'read_post', $post->ID ) ) {
  799. if ( post_password_required( $post ) ) {
  800. echo '<span class="protected-post-excerpt">' . esc_html( get_the_excerpt() ) . '</span>';
  801. } else {
  802. echo esc_html( get_the_excerpt() );
  803. }
  804. }
  805. get_inline_data( $post );
  806. }
  807. /**
  808. * Handles the post date column output.
  809. *
  810. * @since 4.3.0
  811. *
  812. * @global string $mode List table view mode.
  813. *
  814. * @param WP_Post $post The current WP_Post object.
  815. */
  816. public function column_date( $post ) {
  817. global $mode;
  818. if ( '0000-00-00 00:00:00' === $post->post_date ) {
  819. $t_time = $h_time = __( 'Unpublished' );
  820. $time_diff = 0;
  821. } else {
  822. $t_time = get_the_time( __( 'Y/m/d g:i:s a' ) );
  823. $m_time = $post->post_date;
  824. $time = get_post_time( 'G', true, $post );
  825. $time_diff = time() - $time;
  826. if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
  827. $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) );
  828. } else {
  829. $h_time = mysql2date( __( 'Y/m/d' ), $m_time );
  830. }
  831. }
  832. if ( 'publish' === $post->post_status ) {
  833. $status = __( 'Published' );
  834. } elseif ( 'future' === $post->post_status ) {
  835. if ( $time_diff > 0 ) {
  836. $status = '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>';
  837. } else {
  838. $status = __( 'Scheduled' );
  839. }
  840. } else {
  841. $status = __( 'Last Modified' );
  842. }
  843. /**
  844. * Filters the status text of the post.
  845. *
  846. * @since 4.8.0
  847. *
  848. * @param string $status The status text.
  849. * @param WP_Post $post Post object.
  850. * @param string $column_name The column name.
  851. * @param string $mode The list display mode ('excerpt' or 'list').
  852. */
  853. $status = apply_filters( 'post_date_column_status', $status, $post, 'date', $mode );
  854. if ( $status ) {
  855. echo $status . '<br />';
  856. }
  857. if ( 'excerpt' === $mode ) {
  858. /**
  859. * Filters the published time of the post.
  860. *
  861. * If `$mode` equals 'excerpt', the published time and date are both displayed.
  862. * If `$mode` equals 'list' (default), the publish date is displayed, with the
  863. * time and date together available as an abbreviation definition.
  864. *
  865. * @since 2.5.1
  866. *
  867. * @param string $t_time The published time.
  868. * @param WP_Post $post Post object.
  869. * @param string $column_name The column name.
  870. * @param string $mode The list display mode ('excerpt' or 'list').
  871. */
  872. echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
  873. } else {
  874. /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
  875. echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . '</abbr>';
  876. }
  877. }
  878. /**
  879. * Handles the comments column output.
  880. *
  881. * @since 4.3.0
  882. *
  883. * @param WP_Post $post The current WP_Post object.
  884. */
  885. public function column_comments( $post ) {
  886. ?>
  887. <div class="post-com-count-wrapper">
  888. <?php
  889. $pending_comments = isset( $this->comment_pending_count[$post->ID] ) ? $this->comment_pending_count[$post->ID] : 0;
  890. $this->comments_bubble( $post->ID, $pending_comments );
  891. ?>
  892. </div>
  893. <?php
  894. }
  895. /**
  896. * Handles the post author column output.
  897. *
  898. * @since 4.3.0
  899. *
  900. * @param WP_Post $post The current WP_Post object.
  901. */
  902. public function column_author( $post ) {
  903. $args = array(
  904. 'post_type' => $post->post_type,
  905. 'author' => get_the_author_meta( 'ID' )
  906. );
  907. echo $this->get_edit_link( $args, get_the_author() );
  908. }
  909. /**
  910. * Handles the default column output.
  911. *
  912. * @since 4.3.0
  913. *
  914. * @param WP_Post $post The current WP_Post object.
  915. * @param string $column_name The current column name.
  916. */
  917. public function column_default( $post, $column_name ) {
  918. if ( 'categories' === $column_name ) {
  919. $taxonomy = 'category';
  920. } elseif ( 'tags' === $column_name ) {
  921. $taxonomy = 'post_tag';
  922. } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) ) {
  923. $taxonomy = substr( $column_name, 9 );
  924. } else {
  925. $taxonomy = false;
  926. }
  927. if ( $taxonomy ) {
  928. $taxonomy_object = get_taxonomy( $taxonomy );
  929. $terms = get_the_terms( $post->ID, $taxonomy );
  930. if ( is_array( $terms ) ) {
  931. $out = array();
  932. foreach ( $terms as $t ) {
  933. $posts_in_term_qv = array();
  934. if ( 'post' != $post->post_type ) {
  935. $posts_in_term_qv['post_type'] = $post->post_type;
  936. }
  937. if ( $taxonomy_object->query_var ) {
  938. $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
  939. } else {
  940. $posts_in_term_qv['taxonomy'] = $taxonomy;
  941. $posts_in_term_qv['term'] = $t->slug;
  942. }
  943. $label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) );
  944. $out[] = $this->get_edit_link( $posts_in_term_qv, $label );
  945. }
  946. /* translators: used between list items, there is a space after the comma */
  947. echo join( __( ', ' ), $out );
  948. } else {
  949. echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
  950. }
  951. return;
  952. }
  953. if ( is_post_type_hierarchical( $post->post_type ) ) {
  954. /**
  955. * Fires in each custom column on the Posts list table.
  956. *
  957. * This hook only fires if the current post type is hierarchical,
  958. * such as pages.
  959. *
  960. * @since 2.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. */
  965. do_action( 'manage_pages_custom_column', $column_name, $post->ID );
  966. } else {
  967. /**
  968. * Fires in each custom column in the Posts list table.
  969. *
  970. * This hook only fires if the current post type is non-hierarchical,
  971. * such as posts.
  972. *
  973. * @since 1.5.0
  974. *
  975. * @param string $column_name The name of the column to display.
  976. * @param int $post_id The current post ID.
  977. */
  978. do_action( 'manage_posts_custom_column', $column_name, $post->ID );
  979. }
  980. /**
  981. * Fires for each custom column of a specific post type in the Posts list table.
  982. *
  983. * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
  984. *
  985. * @since 3.1.0
  986. *
  987. * @param string $column_name The name of the column to display.
  988. * @param int $post_id The current post ID.
  989. */
  990. do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
  991. }
  992. /**
  993. * @global WP_Post $post
  994. *
  995. * @param int|WP_Post $post
  996. * @param int $level
  997. */
  998. public function single_row( $post, $level = 0 ) {
  999. $global_post = get_post();
  1000. $post = get_post( $post );
  1001. $this->current_level = $level;
  1002. $GLOBALS['post'] = $post;
  1003. setup_postdata( $post );
  1004. $classes = 'iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
  1005. $lock_holder = wp_check_post_lock( $post->ID );
  1006. if ( $lock_holder ) {
  1007. $classes .= ' wp-locked';
  1008. }
  1009. if ( $post->post_parent ) {
  1010. $count = count( get_post_ancestors( $post->ID ) );
  1011. $classes .= ' level-'. $count;
  1012. } else {
  1013. $classes .= ' level-0';
  1014. }
  1015. ?>
  1016. <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>">
  1017. <?php $this->single_row_columns( $post ); ?>
  1018. </tr>
  1019. <?php
  1020. $GLOBALS['post'] = $global_post;
  1021. }
  1022. /**
  1023. * Gets the name of the default primary column.
  1024. *
  1025. * @since 4.3.0
  1026. *
  1027. * @return string Name of the default primary column, in this case, 'title'.
  1028. */
  1029. protected function get_default_primary_column_name() {
  1030. return 'title';
  1031. }
  1032. /**
  1033. * Generates and displays row action links.
  1034. *
  1035. * @since 4.3.0
  1036. *
  1037. * @param object $post Post being acted upon.
  1038. * @param string $column_name Current column name.
  1039. * @param string $primary Primary column name.
  1040. * @return string Row actions output for posts.
  1041. */
  1042. protected function handle_row_actions( $post, $column_name, $primary ) {
  1043. if ( $primary !== $column_name ) {
  1044. return '';
  1045. }
  1046. $post_type_object = get_post_type_object( $post->post_type );
  1047. $can_edit_post = current_user_can( 'edit_post', $post->ID );
  1048. $actions = array();
  1049. $title = _draft_or_post_title();
  1050. if ( $can_edit_post && 'trash' != $post->post_status ) {
  1051. $actions['edit'] = sprintf(
  1052. '<a href="%s" aria-label="%s">%s</a>',
  1053. get_edit_post_link( $post->ID ),
  1054. /* translators: %s: post title */
  1055. esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ),
  1056. __( 'Edit' )
  1057. );
  1058. $actions['inline hide-if-no-js'] = sprintf(
  1059. '<a href="#" class="editinline" aria-label="%s">%s</a>',
  1060. /* translators: %s: post title */
  1061. esc_attr( sprintf( __( 'Quick edit &#8220;%s&#8221; inline' ), $title ) ),
  1062. __( 'Quick&nbsp;Edit' )
  1063. );
  1064. }
  1065. if ( current_user_can( 'delete_post', $post->ID ) ) {
  1066. if ( 'trash' === $post->post_status ) {
  1067. $actions['untrash'] = sprintf(
  1068. '<a href="%s" aria-label="%s">%s</a>',
  1069. wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ),
  1070. /* translators: %s: post title */
  1071. esc_attr( sprintf( __( 'Restore &#8220;%s&#8221; from the Trash' ), $title ) ),
  1072. __( 'Restore' )
  1073. );
  1074. } elseif ( EMPTY_TRASH_DAYS ) {
  1075. $actions['trash'] = sprintf(
  1076. '<a href="%s" class="submitdelete" aria-label="%s">%s</a>',
  1077. get_delete_post_link( $post->ID ),
  1078. /* translators: %s: post title */
  1079. esc_attr( sprintf( __( 'Move &#8220;%s&#8221; to the Trash' ), $title ) ),
  1080. _x( 'Trash', 'verb' )
  1081. );
  1082. }
  1083. if ( 'trash' === $post->post_status || ! EMPTY_TRASH_DAYS ) {
  1084. $actions['delete'] = sprintf(
  1085. '<a href="%s" class="submitdelete" aria-label="%s">%s</a>',
  1086. get_delete_post_link( $post->ID, '', true ),
  1087. /* translators: %s: post title */
  1088. esc_attr( sprintf( __( 'Delete &#8220;%s&#8221; permanently' ), $title ) ),
  1089. __( 'Delete Permanently' )
  1090. );
  1091. }
  1092. }
  1093. if ( is_post_type_viewable( $post_type_object ) ) {
  1094. if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
  1095. if ( $can_edit_post ) {
  1096. $preview_link = get_preview_post_link( $post );
  1097. $actions['view'] = sprintf(
  1098. '<a href="%s" rel="bookmark" aria-label="%s">%s</a>',
  1099. esc_url( $preview_link ),
  1100. /* translators: %s: post title */
  1101. esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ),
  1102. __( 'Preview' )
  1103. );
  1104. }
  1105. } elseif ( 'trash' != $post->post_status ) {
  1106. $actions['view'] = sprintf(
  1107. '<a href="%s" rel="bookmark" aria-label="%s">%s</a>',
  1108. get_permalink( $post->ID ),
  1109. /* translators: %s: post title */
  1110. esc_attr( sprintf( __( 'View &#8220;%s&#8221;' ), $title ) ),
  1111. __( 'View' )
  1112. );
  1113. }
  1114. }
  1115. if ( is_post_type_hierarchical( $post->post_type ) ) {
  1116. /**
  1117. * Filters the array of row action links on the Pages list table.
  1118. *
  1119. * The filter is evaluated only for hierarchical post types.
  1120. *
  1121. * @since 2.8.0
  1122. *
  1123. * @param array $actions An array of row action links. Defaults are
  1124. * 'Edit', 'Quick Edit', 'Restore', 'Trash',
  1125. * 'Delete Permanently', 'Preview', and 'View'.
  1126. * @param WP_Post $post The post object.
  1127. */
  1128. $actions = apply_filters( 'page_row_actions', $actions, $post );
  1129. } else {
  1130. /**
  1131. * Filters the array of row action links on the Posts list table.
  1132. *
  1133. * The filter is evaluated only for non-hierarchical post types.
  1134. *
  1135. * @since 2.8.0
  1136. *
  1137. * @param array $actions An array of row action links. Defaults are
  1138. * 'Edit', 'Quick Edit', 'Restore', 'Trash',
  1139. * 'Delete Permanently', 'Preview', and 'View'.
  1140. * @param WP_Post $post The post object.
  1141. */
  1142. $actions = apply_filters( 'post_row_actions', $actions, $post );
  1143. }
  1144. return $this->row_actions( $actions );
  1145. }
  1146. /**
  1147. * Outputs the hidden row displayed when inline editing
  1148. *
  1149. * @since 3.1.0
  1150. *
  1151. * @global string $mode List table view mode.
  1152. */
  1153. public function inline_edit() {
  1154. global $mode;
  1155. $screen = $this->screen;
  1156. $post = get_default_post_to_edit( $screen->post_type );
  1157. $post_type_object = get_post_type_object( $screen->post_type );
  1158. $taxonomy_names = get_object_taxonomies( $screen->post_type );
  1159. $hierarchical_taxonomies = array();
  1160. $flat_taxonomies = array();
  1161. foreach ( $taxonomy_names as $taxonomy_name ) {
  1162. $taxonomy = get_taxonomy( $taxonomy_name );
  1163. $show_in_quick_edit = $taxonomy->show_in_quick_edit;
  1164. /**
  1165. * Filters whether the current taxonomy should be shown in the Quick Edit panel.
  1166. *
  1167. * @since 4.2.0
  1168. *
  1169. * @param bool $show_in_quick_edit Whether to show the current taxonomy in Quick Edit.
  1170. * @param string $taxonomy_name Taxonomy name.
  1171. * @param string $post_type Post type of current Quick Edit post.
  1172. */
  1173. if ( ! apply_filters( 'quick_edit_show_taxonomy', $show_in_quick_edit, $taxonomy_name, $screen->post_type ) ) {
  1174. continue;
  1175. }
  1176. if ( $taxonomy->hierarchical )
  1177. $hierarchical_taxonomies[] = $taxonomy;
  1178. else
  1179. $flat_taxonomies[] = $taxonomy;
  1180. }
  1181. $m = ( isset( $mode ) && 'excerpt' === $mode ) ? 'excerpt' : 'list';
  1182. $can_publish = current_user_can( $post_type_object->cap->publish_posts );
  1183. $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
  1184. ?>
  1185. <form method="get"><table style="display: none"><tbody id="inlineedit">
  1186. <?php
  1187. $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page';
  1188. $inline_edit_classes = "inline-edit-row inline-edit-row-$hclass";
  1189. $bulk_edit_classes = "bulk-edit-row bulk-edit-row-$hclass bulk-edit-{$screen->post_type}";
  1190. $quick_edit_classes = "quick-edit-row quick-edit-row-$hclass inline-edit-{$screen->post_type}";
  1191. $bulk = 0;
  1192. while ( $bulk < 2 ) { ?>
  1193. <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="<?php echo $inline_edit_classes . ' ';
  1194. echo $bulk ? $bulk_edit_classes : $quick_edit_classes;
  1195. ?>" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
  1196. <fieldset class="inline-edit-col-left">
  1197. <legend class="inline-edit-legend"><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></legend>
  1198. <div class="inline-edit-col">
  1199. <?php
  1200. if ( post_type_supports( $screen->post_type, 'title' ) ) :
  1201. if ( $bulk ) : ?>
  1202. <div id="bulk-title-div">
  1203. <div id="bulk-titles"></div>
  1204. </div>
  1205. <?php else : // $bulk ?>
  1206. <label>
  1207. <span class="title"><?php _e( 'Title' ); ?></span>
  1208. <span class="input-text-wrap"><input type="text" name="post_title" class="ptitle" value="" /></span>
  1209. </label>
  1210. <label>
  1211. <span class="title"><?php _e( 'Slug' ); ?></span>
  1212. <span class="input-text-wrap"><input type="text" name="post_name" value="" /></span>
  1213. </label>
  1214. <?php endif; // $bulk
  1215. endif; // post_type_supports title ?>
  1216. <?php if ( !$bulk ) : ?>
  1217. <fieldset class="inline-edit-date">
  1218. <legend><span class="title"><?php _e( 'Date' ); ?></span></legend>
  1219. <?php touch_time( 1, 1, 0, 1 ); ?>
  1220. </fieldset>
  1221. <br class="clear" />
  1222. <?php endif; // $bulk
  1223. if ( post_type_supports( $screen->post_type, 'author' ) ) :
  1224. $authors_dropdown = '';
  1225. if ( current_user_can( $post_type_object->cap->edit_others_posts ) ) :
  1226. $users_opt = array(
  1227. 'hide_if_only_one_author' => false,
  1228. 'who' => 'authors',
  1229. 'name' => 'post_author',
  1230. 'class'=> 'authors',
  1231. 'multi' => 1,
  1232. 'echo' => 0,
  1233. 'show' => 'display_name_with_login',
  1234. );
  1235. if ( $bulk )
  1236. $users_opt['show_option_none'] = __( '&mdash; No Change &mdash;' );
  1237. if ( $authors = wp_dropdown_users( $users_opt ) ) :
  1238. $authors_dropdown = '<label class="inline-edit-author">';
  1239. $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
  1240. $authors_dropdown .= $authors;
  1241. $authors_dropdown .= '</label>';
  1242. endif;
  1243. endif; // authors
  1244. ?>
  1245. <?php if ( !$bulk ) echo $authors_dropdown;
  1246. endif; // post_type_supports author
  1247. if ( !$bulk && $can_publish ) :
  1248. ?>
  1249. <div class="inline-edit-group wp-clearfix">
  1250. <label class="alignleft">
  1251. <span class="title"><?php _e( 'Password' ); ?></span>
  1252. <span class="input-text-wrap"><input type="text" name="post_password" class="inline-edit-password-input" value="" /></span>
  1253. </label>
  1254. <em class="alignleft inline-edit-or">
  1255. <?php
  1256. /* translators: Between password field and private checkbox on post quick edit interface */
  1257. _e( '&ndash;OR&ndash;' );
  1258. ?>
  1259. </em>
  1260. <label class="alignleft inline-edit-private">
  1261. <input type="checkbox" name="keep_private" value="private" />
  1262. <span class="checkbox-title"><?php _e( 'Private' ); ?></span>
  1263. </label>
  1264. </div>
  1265. <?php endif; ?>
  1266. </div></fieldset>
  1267. <?php if ( count( $hierarchical_taxonomies ) && !$bulk ) : ?>
  1268. <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col">
  1269. <?php foreach ( $hierarchical_taxonomies as $taxonomy ) : ?>
  1270. <span class="title inline-edit-categories-label"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
  1271. <input type="hidden" name="<?php echo ( $taxonomy->name === 'category' ) ? 'post_category[]' : 'tax_input[' . esc_attr( $taxonomy->name ) . '][]'; ?>" value="0" />
  1272. <ul class="cat-checklist <?php echo esc_attr( $taxonomy->name )?>-checklist">
  1273. <?php wp_terms_checklist( null, array( 'taxonomy' => $taxonomy->name ) ) ?>
  1274. </ul>
  1275. <?php endforeach; //$hierarchical_taxonomies as $taxonomy ?>
  1276. </div></fieldset>
  1277. <?php endif; // count( $hierarchical_taxonomies ) && !$bulk ?>
  1278. <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
  1279. <?php
  1280. if ( post_type_supports( $screen->post_type, 'author' ) && $bulk )
  1281. echo $authors_dropdown;
  1282. if ( post_type_supports( $screen->post_type, 'page-attributes' ) ) :
  1283. if ( $post_type_object->hierarchical ) :
  1284. ?>
  1285. <label>
  1286. <span class="title"><?php _e( 'Parent' ); ?></span>
  1287. <?php
  1288. $dropdown_args = array(
  1289. 'post_type' => $post_type_object->name,
  1290. 'selected' => $post->post_parent,
  1291. 'name' => 'post_parent',
  1292. 'show_option_none' => __( 'Main Page (no parent)' ),
  1293. 'option_none_value' => 0,
  1294. 'sort_column' => 'menu_order, post_title',
  1295. );
  1296. if ( $bulk )
  1297. $dropdown_args['show_option_no_change'] = __( '&mdash; No Change &mdash;' );
  1298. /**
  1299. * Filters the arguments used to generate the Quick Edit page-parent drop-down.
  1300. *
  1301. * @since 2.7.0
  1302. *
  1303. * @see wp_dropdown_pages()
  1304. *
  1305. * @param array $dropdown_args An array of arguments.
  1306. */
  1307. $dropdown_args = apply_filters( 'quick_edit_dropdown_pages_args', $dropdown_args );
  1308. wp_dropdown_pages( $dropdown_args );
  1309. ?>
  1310. </label>
  1311. <?php
  1312. endif; // hierarchical
  1313. if ( !$bulk ) : ?>
  1314. <label>
  1315. <span class="title"><?php _e( 'Order' ); ?></span>
  1316. <span class="input-text-wrap"><input type="text" name="menu_order" class="inline-edit-menu-order-input" value="<?php echo $post->menu_order ?>" /></span>
  1317. </label>
  1318. <?php
  1319. endif; // !$bulk
  1320. endif; // page-attributes
  1321. ?>
  1322. <?php if ( 0 < count( get_page_templates( null, $screen->post_type ) ) ) : ?>
  1323. <label>
  1324. <span class="title"><?php _e( 'Template' ); ?></span>
  1325. <select name="page_template">
  1326. <?php if ( $bulk ) : ?>
  1327. <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
  1328. <?php endif; // $bulk ?>
  1329. <?php
  1330. /** This filter is documented in wp-admin/includes/meta-boxes.php */
  1331. $default_title = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'quick-edit' );
  1332. ?>
  1333. <option value="default"><?php echo esc_html( $default_title ); ?></option>
  1334. <?php page_template_dropdown( '', $screen->post_type ) ?>
  1335. </select>
  1336. </label>
  1337. <?php endif; ?>
  1338. <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?>
  1339. <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
  1340. <?php if ( current_user_can( $taxonomy->cap->assign_terms ) ) :
  1341. $taxonomy_name = esc_attr( $taxonomy->name );
  1342. ?>
  1343. <label class="inline-edit-tags">
  1344. <span class="title"><?php echo esc_html( $taxonomy->labels->name ) ?></span>
  1345. <textarea data-wp-taxonomy="<?php echo $taxonomy_name; ?>" cols="22" rows="1" name="tax_input[<?php echo $taxonomy_name; ?>]" class="tax_input_<?php echo $taxonomy_name; ?>"></textarea>
  1346. </label>
  1347. <?php endif; ?>
  1348. <?php endforeach; //$flat_taxonomies as $taxonomy ?>
  1349. <?php endif; // count( $flat_taxonomies ) && !$bulk ?>
  1350. <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) :
  1351. if ( $bulk ) : ?>
  1352. <div class="inline-edit-group wp-clearfix">
  1353. <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
  1354. <label class="alignleft">
  1355. <span class="title"><?php _e( 'Comments' ); ?></span>
  1356. <select name="comment_status">
  1357. <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
  1358. <option value="open"><?php _e( 'Allow' ); ?></option>
  1359. <option value="closed"><?php _e( 'Do not allow' ); ?></option>
  1360. </select>
  1361. </label>
  1362. <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
  1363. <label class="alignright">
  1364. <span class="title"><?php _e( 'Pings' ); ?></span>
  1365. <select name="ping_status">
  1366. <option value=""><?php _e( '&mdash; No Change &mdash;' ); ?></option>
  1367. <option value="open"><?php _e( 'Allow' ); ?></option>
  1368. <option value="closed"><?php _e( 'Do not allow' ); ?></option>
  1369. </select>
  1370. </label>
  1371. <?php endif; ?>
  1372. </div>
  1373. <?php else : // $bulk ?>
  1374. <div class="inline-edit-group wp-clearfix">
  1375. <?php if ( post_type_supports( $screen->post_type, 'comments' ) ) : ?>
  1376. <label class="alignleft">
  1377. <input type="checkbox" name="comment_status" value="open" />
  1378. <span class="checkbox-title"><?php _e( 'Allow Comments' ); ?></span>
  1379. </label>
  1380. <?php endif; if ( post_type_supports( $screen->post_type, 'trackbacks' ) ) : ?>
  1381. <label class="alignleft">
  1382. <input type="checkbox" name="ping_status" value="open" />
  1383. <span class="checkbox-title"><?php _e( 'Allow Pings' ); ?></span>
  1384. </label>
  1385. <?php endif; ?>
  1386. </div>
  1387. <?php endif; // $bulk
  1388. endif; // post_type_supports comments or pings ?>
  1389. <div class="inline-edit-group wp-clearfix">
  1390. <label class="inline-edit-status alignleft">
  1391. <span class="title"><?php _e( 'Status' ); ?></span>
  1392. <select name="_status">
  1393. <?php if ( $bulk ) : ?>
  1394. <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
  1395. <?php endif; // $bulk ?>
  1396. <?php if ( $can_publish ) : // Contributors only get "Unpublished" and "Pending Review" ?>
  1397. <option value="publish"><?php _e( 'Published' ); ?></option>
  1398. <option value="future"><?php _e( 'Scheduled' ); ?></option>
  1399. <?php if ( $bulk ) : ?>
  1400. <option value="private"><?php _e( 'Private' ) ?></option>
  1401. <?php endif; // $bulk ?>
  1402. <?php endif; ?>
  1403. <option value="pending"><?php _e( 'Pending Review' ); ?></option>
  1404. <option value="draft"><?php _e( 'Draft' ); ?></option>
  1405. </select>
  1406. </label>
  1407. <?php if ( 'post' === $screen->post_type && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?>
  1408. <?php if ( $bulk ) : ?>
  1409. <label class="alignright">
  1410. <span class="title"><?php _e( 'Sticky' ); ?></span>
  1411. <select name="sticky">
  1412. <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
  1413. <option value="sticky"><?php _e( 'Sticky' ); ?></option>
  1414. <option value="unsticky"><?php _e( 'Not Sticky' ); ?></option>
  1415. </select>
  1416. </label>
  1417. <?php else : // $bulk ?>
  1418. <label class="alignleft">
  1419. <input type="checkbox" name="sticky" value="sticky" />
  1420. <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span>
  1421. </label>
  1422. <?php endif; // $bulk ?>
  1423. <?php endif; // 'post' && $can_publish && current_user_can( 'edit_others_cap' ) ?>
  1424. </div>
  1425. <?php
  1426. if ( $bulk && current_theme_supports( 'post-formats' ) && post_type_supports( $screen->post_type, 'post-formats' ) ) {
  1427. $post_formats = get_theme_support( 'post-formats' );
  1428. ?>
  1429. <label class="alignleft">
  1430. <span class="title"><?php _ex( 'Format', 'post format' ); ?></span>
  1431. <select name="post_format">
  1432. <option value="-1"><?php _e( '&mdash; No Change &mdash;' ); ?></option>
  1433. <option value="0"><?php echo get_post_format_string( 'standard' ); ?></option>
  1434. <?php
  1435. if ( is_array( $post_formats[0] ) ) {
  1436. foreach ( $post_formats[0] as $format ) {
  1437. ?>
  1438. <option value="<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></option>
  1439. <?php
  1440. }
  1441. }
  1442. ?>
  1443. </select></label>
  1444. <?php
  1445. }
  1446. ?>
  1447. </div></fieldset>
  1448. <?php
  1449. list( $columns ) = $this->get_column_info();
  1450. foreach ( $columns as $column_name => $column_display_name ) {
  1451. if ( isset( $core_columns[$column_name] ) )
  1452. continue;
  1453. if ( $bulk ) {
  1454. /**
  1455. * Fires once for each column in Bulk Edit mode.
  1456. *
  1457. * @since 2.7.0
  1458. *
  1459. * @param string $column_name Name of the column to edit.
  1460. * @param WP_Post $post_type The post type slug.
  1461. */
  1462. do_action( 'bulk_edit_custom_box', $column_name, $screen->post_type );
  1463. } else {
  1464. /**
  1465. * Fires once for each column in Quick Edit mode.
  1466. *
  1467. * @since 2.7.0
  1468. *
  1469. * @param string $column_name Name of the column to edit.
  1470. * @param string $post_type The post type slug, or current screen name if this is a taxonomy list table.
  1471. * @param string taxonomy The taxonomy name, if any.
  1472. */
  1473. do_action( 'quick_edit_custom_box', $column_name, $screen->post_type, '' );
  1474. }
  1475. }
  1476. ?>
  1477. <div class="submit inline-edit-save">
  1478. <button type="button" class="button cancel alignleft"><?php _e( 'Cancel' ); ?></button>
  1479. <?php if ( ! $bulk ) {
  1480. wp_nonce_field( 'inlineeditnonce', '_inline_edit', false );
  1481. ?>
  1482. <button type="button" class="button button-primary save alignright"><?php _e( 'Update' ); ?></button>
  1483. <span class="spinner"></span>
  1484. <?php } else {
  1485. submit_button( __( 'Update' ), 'primary alignright', 'bulk_edit', false );
  1486. } ?>
  1487. <input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" />
  1488. <input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" />
  1489. <?php if ( ! $bulk && ! post_type_supports( $screen->post_type, 'author' ) ) { ?>
  1490. <input type="hidden" name="post_author" value="<?php echo esc_attr( $post->post_author ); ?>" />
  1491. <?php } ?>
  1492. <br class="clear" />
  1493. <div class="notice notice-error notice-alt inline hidden">
  1494. <p class="error"></p>
  1495. </div>
  1496. </div>
  1497. </td></tr>
  1498. <?php
  1499. $bulk++;
  1500. }
  1501. ?>
  1502. </tbody></table></form>
  1503. <?php
  1504. }
  1505. }