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

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