meta-boxes.php 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636
  1. <?php
  2. /**
  3. * WordPress Administration Meta Boxes API.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. //
  9. // Post-related Meta Boxes.
  10. //
  11. /**
  12. * Displays post submit form fields.
  13. *
  14. * @since 2.7.0
  15. *
  16. * @global string $action
  17. *
  18. * @param WP_Post $post Current post object.
  19. * @param array $args {
  20. * Array of arguments for building the post submit meta box.
  21. *
  22. * @type string $id Meta box 'id' attribute.
  23. * @type string $title Meta box title.
  24. * @type callable $callback Meta box display callback.
  25. * @type array $args Extra meta box arguments.
  26. * }
  27. */
  28. function post_submit_meta_box( $post, $args = array() ) {
  29. global $action;
  30. $post_id = (int) $post->ID;
  31. $post_type = $post->post_type;
  32. $post_type_object = get_post_type_object( $post_type );
  33. $can_publish = current_user_can( $post_type_object->cap->publish_posts );
  34. ?>
  35. <div class="submitbox" id="submitpost">
  36. <div id="minor-publishing">
  37. <?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key. ?>
  38. <div style="display:none;">
  39. <?php submit_button( __( 'Save' ), '', 'save' ); ?>
  40. </div>
  41. <div id="minor-publishing-actions">
  42. <div id="save-action">
  43. <?php
  44. if ( ! in_array( $post->post_status, array( 'publish', 'future', 'pending' ), true ) ) {
  45. $private_style = '';
  46. if ( 'private' === $post->post_status ) {
  47. $private_style = 'style="display:none"';
  48. }
  49. ?>
  50. <input <?php echo $private_style; ?> type="submit" name="save" id="save-post" value="<?php esc_attr_e( 'Save Draft' ); ?>" class="button" />
  51. <span class="spinner"></span>
  52. <?php } elseif ( 'pending' === $post->post_status && $can_publish ) { ?>
  53. <input type="submit" name="save" id="save-post" value="<?php esc_attr_e( 'Save as Pending' ); ?>" class="button" />
  54. <span class="spinner"></span>
  55. <?php } ?>
  56. </div>
  57. <?php
  58. if ( is_post_type_viewable( $post_type_object ) ) :
  59. ?>
  60. <div id="preview-action">
  61. <?php
  62. $preview_link = esc_url( get_preview_post_link( $post ) );
  63. if ( 'publish' === $post->post_status ) {
  64. $preview_button_text = __( 'Preview Changes' );
  65. } else {
  66. $preview_button_text = __( 'Preview' );
  67. }
  68. $preview_button = sprintf(
  69. '%1$s<span class="screen-reader-text"> %2$s</span>',
  70. $preview_button_text,
  71. /* translators: Accessibility text. */
  72. __( '(opens in a new tab)' )
  73. );
  74. ?>
  75. <a class="preview button" href="<?php echo $preview_link; ?>" target="wp-preview-<?php echo $post_id; ?>" id="post-preview"><?php echo $preview_button; ?></a>
  76. <input type="hidden" name="wp-preview" id="wp-preview" value="" />
  77. </div>
  78. <?php
  79. endif;
  80. /**
  81. * Fires after the Save Draft (or Save as Pending) and Preview (or Preview Changes) buttons
  82. * in the Publish meta box.
  83. *
  84. * @since 4.4.0
  85. *
  86. * @param WP_Post $post WP_Post object for the current post.
  87. */
  88. do_action( 'post_submitbox_minor_actions', $post );
  89. ?>
  90. <div class="clear"></div>
  91. </div>
  92. <div id="misc-publishing-actions">
  93. <div class="misc-pub-section misc-pub-post-status">
  94. <?php _e( 'Status:' ); ?>
  95. <span id="post-status-display">
  96. <?php
  97. switch ( $post->post_status ) {
  98. case 'private':
  99. _e( 'Privately Published' );
  100. break;
  101. case 'publish':
  102. _e( 'Published' );
  103. break;
  104. case 'future':
  105. _e( 'Scheduled' );
  106. break;
  107. case 'pending':
  108. _e( 'Pending Review' );
  109. break;
  110. case 'draft':
  111. case 'auto-draft':
  112. _e( 'Draft' );
  113. break;
  114. }
  115. ?>
  116. </span>
  117. <?php
  118. if ( 'publish' === $post->post_status || 'private' === $post->post_status || $can_publish ) {
  119. $private_style = '';
  120. if ( 'private' === $post->post_status ) {
  121. $private_style = 'style="display:none"';
  122. }
  123. ?>
  124. <a href="#post_status" <?php echo $private_style; ?> class="edit-post-status hide-if-no-js" role="button"><span aria-hidden="true"><?php _e( 'Edit' ); ?></span> <span class="screen-reader-text"><?php _e( 'Edit status' ); ?></span></a>
  125. <div id="post-status-select" class="hide-if-js">
  126. <input type="hidden" name="hidden_post_status" id="hidden_post_status" value="<?php echo esc_attr( ( 'auto-draft' === $post->post_status ) ? 'draft' : $post->post_status ); ?>" />
  127. <label for="post_status" class="screen-reader-text"><?php _e( 'Set status' ); ?></label>
  128. <select name="post_status" id="post_status">
  129. <?php if ( 'publish' === $post->post_status ) : ?>
  130. <option<?php selected( $post->post_status, 'publish' ); ?> value='publish'><?php _e( 'Published' ); ?></option>
  131. <?php elseif ( 'private' === $post->post_status ) : ?>
  132. <option<?php selected( $post->post_status, 'private' ); ?> value='publish'><?php _e( 'Privately Published' ); ?></option>
  133. <?php elseif ( 'future' === $post->post_status ) : ?>
  134. <option<?php selected( $post->post_status, 'future' ); ?> value='future'><?php _e( 'Scheduled' ); ?></option>
  135. <?php endif; ?>
  136. <option<?php selected( $post->post_status, 'pending' ); ?> value='pending'><?php _e( 'Pending Review' ); ?></option>
  137. <?php if ( 'auto-draft' === $post->post_status ) : ?>
  138. <option<?php selected( $post->post_status, 'auto-draft' ); ?> value='draft'><?php _e( 'Draft' ); ?></option>
  139. <?php else : ?>
  140. <option<?php selected( $post->post_status, 'draft' ); ?> value='draft'><?php _e( 'Draft' ); ?></option>
  141. <?php endif; ?>
  142. </select>
  143. <a href="#post_status" class="save-post-status hide-if-no-js button"><?php _e( 'OK' ); ?></a>
  144. <a href="#post_status" class="cancel-post-status hide-if-no-js button-cancel"><?php _e( 'Cancel' ); ?></a>
  145. </div>
  146. <?php
  147. }
  148. ?>
  149. </div>
  150. <div class="misc-pub-section misc-pub-visibility" id="visibility">
  151. <?php _e( 'Visibility:' ); ?>
  152. <span id="post-visibility-display">
  153. <?php
  154. if ( 'private' === $post->post_status ) {
  155. $post->post_password = '';
  156. $visibility = 'private';
  157. $visibility_trans = __( 'Private' );
  158. } elseif ( ! empty( $post->post_password ) ) {
  159. $visibility = 'password';
  160. $visibility_trans = __( 'Password protected' );
  161. } elseif ( 'post' === $post_type && is_sticky( $post_id ) ) {
  162. $visibility = 'public';
  163. $visibility_trans = __( 'Public, Sticky' );
  164. } else {
  165. $visibility = 'public';
  166. $visibility_trans = __( 'Public' );
  167. }
  168. echo esc_html( $visibility_trans );
  169. ?>
  170. </span>
  171. <?php if ( $can_publish ) { ?>
  172. <a href="#visibility" class="edit-visibility hide-if-no-js" role="button"><span aria-hidden="true"><?php _e( 'Edit' ); ?></span> <span class="screen-reader-text"><?php _e( 'Edit visibility' ); ?></span></a>
  173. <div id="post-visibility-select" class="hide-if-js">
  174. <input type="hidden" name="hidden_post_password" id="hidden-post-password" value="<?php echo esc_attr( $post->post_password ); ?>" />
  175. <?php if ( 'post' === $post_type ) : ?>
  176. <input type="checkbox" style="display:none" name="hidden_post_sticky" id="hidden-post-sticky" value="sticky" <?php checked( is_sticky( $post_id ) ); ?> />
  177. <?php endif; ?>
  178. <input type="hidden" name="hidden_post_visibility" id="hidden-post-visibility" value="<?php echo esc_attr( $visibility ); ?>" />
  179. <input type="radio" name="visibility" id="visibility-radio-public" value="public" <?php checked( $visibility, 'public' ); ?> /> <label for="visibility-radio-public" class="selectit"><?php _e( 'Public' ); ?></label><br />
  180. <?php if ( 'post' === $post_type && current_user_can( 'edit_others_posts' ) ) : ?>
  181. <span id="sticky-span"><input id="sticky" name="sticky" type="checkbox" value="sticky" <?php checked( is_sticky( $post_id ) ); ?> /> <label for="sticky" class="selectit"><?php _e( 'Stick this post to the front page' ); ?></label><br /></span>
  182. <?php endif; ?>
  183. <input type="radio" name="visibility" id="visibility-radio-password" value="password" <?php checked( $visibility, 'password' ); ?> /> <label for="visibility-radio-password" class="selectit"><?php _e( 'Password protected' ); ?></label><br />
  184. <span id="password-span"><label for="post_password"><?php _e( 'Password:' ); ?></label> <input type="text" name="post_password" id="post_password" value="<?php echo esc_attr( $post->post_password ); ?>" maxlength="255" /><br /></span>
  185. <input type="radio" name="visibility" id="visibility-radio-private" value="private" <?php checked( $visibility, 'private' ); ?> /> <label for="visibility-radio-private" class="selectit"><?php _e( 'Private' ); ?></label><br />
  186. <p>
  187. <a href="#visibility" class="save-post-visibility hide-if-no-js button"><?php _e( 'OK' ); ?></a>
  188. <a href="#visibility" class="cancel-post-visibility hide-if-no-js button-cancel"><?php _e( 'Cancel' ); ?></a>
  189. </p>
  190. </div>
  191. <?php } ?>
  192. </div>
  193. <?php
  194. /* translators: Publish box date string. 1: Date, 2: Time. See https://www.php.net/manual/datetime.format.php */
  195. $date_string = __( '%1$s at %2$s' );
  196. /* translators: Publish box date format, see https://www.php.net/manual/datetime.format.php */
  197. $date_format = _x( 'M j, Y', 'publish box date format' );
  198. /* translators: Publish box time format, see https://www.php.net/manual/datetime.format.php */
  199. $time_format = _x( 'H:i', 'publish box time format' );
  200. if ( 0 !== $post_id ) {
  201. if ( 'future' === $post->post_status ) { // Scheduled for publishing at a future date.
  202. /* translators: Post date information. %s: Date on which the post is currently scheduled to be published. */
  203. $stamp = __( 'Scheduled for: %s' );
  204. } elseif ( 'publish' === $post->post_status || 'private' === $post->post_status ) { // Already published.
  205. /* translators: Post date information. %s: Date on which the post was published. */
  206. $stamp = __( 'Published on: %s' );
  207. } elseif ( '0000-00-00 00:00:00' === $post->post_date_gmt ) { // Draft, 1 or more saves, no date specified.
  208. $stamp = __( 'Publish <b>immediately</b>' );
  209. } elseif ( time() < strtotime( $post->post_date_gmt . ' +0000' ) ) { // Draft, 1 or more saves, future date specified.
  210. /* translators: Post date information. %s: Date on which the post is to be published. */
  211. $stamp = __( 'Schedule for: %s' );
  212. } else { // Draft, 1 or more saves, date specified.
  213. /* translators: Post date information. %s: Date on which the post is to be published. */
  214. $stamp = __( 'Publish on: %s' );
  215. }
  216. $date = sprintf(
  217. $date_string,
  218. date_i18n( $date_format, strtotime( $post->post_date ) ),
  219. date_i18n( $time_format, strtotime( $post->post_date ) )
  220. );
  221. } else { // Draft (no saves, and thus no date specified).
  222. $stamp = __( 'Publish <b>immediately</b>' );
  223. $date = sprintf(
  224. $date_string,
  225. date_i18n( $date_format, strtotime( current_time( 'mysql' ) ) ),
  226. date_i18n( $time_format, strtotime( current_time( 'mysql' ) ) )
  227. );
  228. }
  229. if ( ! empty( $args['args']['revisions_count'] ) ) :
  230. ?>
  231. <div class="misc-pub-section misc-pub-revisions">
  232. <?php
  233. /* translators: Post revisions heading. %s: The number of available revisions. */
  234. printf( __( 'Revisions: %s' ), '<b>' . number_format_i18n( $args['args']['revisions_count'] ) . '</b>' );
  235. ?>
  236. <a class="hide-if-no-js" href="<?php echo esc_url( get_edit_post_link( $args['args']['revision_id'] ) ); ?>"><span aria-hidden="true"><?php _ex( 'Browse', 'revisions' ); ?></span> <span class="screen-reader-text"><?php _e( 'Browse revisions' ); ?></span></a>
  237. </div>
  238. <?php
  239. endif;
  240. if ( $can_publish ) : // Contributors don't get to choose the date of publish.
  241. ?>
  242. <div class="misc-pub-section curtime misc-pub-curtime">
  243. <span id="timestamp">
  244. <?php printf( $stamp, '<b>' . $date . '</b>' ); ?>
  245. </span>
  246. <a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" role="button">
  247. <span aria-hidden="true"><?php _e( 'Edit' ); ?></span>
  248. <span class="screen-reader-text"><?php _e( 'Edit date and time' ); ?></span>
  249. </a>
  250. <fieldset id="timestampdiv" class="hide-if-js">
  251. <legend class="screen-reader-text"><?php _e( 'Date and time' ); ?></legend>
  252. <?php touch_time( ( 'edit' === $action ), 1 ); ?>
  253. </fieldset>
  254. </div>
  255. <?php
  256. endif;
  257. if ( 'draft' === $post->post_status && get_post_meta( $post_id, '_customize_changeset_uuid', true ) ) :
  258. ?>
  259. <div class="notice notice-info notice-alt inline">
  260. <p>
  261. <?php
  262. printf(
  263. /* translators: %s: URL to the Customizer. */
  264. __( 'This draft comes from your <a href="%s">unpublished customization changes</a>. You can edit, but there is no need to publish now. It will be published automatically with those changes.' ),
  265. esc_url(
  266. add_query_arg(
  267. 'changeset_uuid',
  268. rawurlencode( get_post_meta( $post_id, '_customize_changeset_uuid', true ) ),
  269. admin_url( 'customize.php' )
  270. )
  271. )
  272. );
  273. ?>
  274. </p>
  275. </div>
  276. <?php
  277. endif;
  278. /**
  279. * Fires after the post time/date setting in the Publish meta box.
  280. *
  281. * @since 2.9.0
  282. * @since 4.4.0 Added the `$post` parameter.
  283. *
  284. * @param WP_Post $post WP_Post object for the current post.
  285. */
  286. do_action( 'post_submitbox_misc_actions', $post );
  287. ?>
  288. </div>
  289. <div class="clear"></div>
  290. </div>
  291. <div id="major-publishing-actions">
  292. <?php
  293. /**
  294. * Fires at the beginning of the publishing actions section of the Publish meta box.
  295. *
  296. * @since 2.7.0
  297. * @since 4.9.0 Added the `$post` parameter.
  298. *
  299. * @param WP_Post|null $post WP_Post object for the current post on Edit Post screen,
  300. * null on Edit Link screen.
  301. */
  302. do_action( 'post_submitbox_start', $post );
  303. ?>
  304. <div id="delete-action">
  305. <?php
  306. if ( current_user_can( 'delete_post', $post_id ) ) {
  307. if ( ! EMPTY_TRASH_DAYS ) {
  308. $delete_text = __( 'Delete permanently' );
  309. } else {
  310. $delete_text = __( 'Move to Trash' );
  311. }
  312. ?>
  313. <a class="submitdelete deletion" href="<?php echo get_delete_post_link( $post_id ); ?>"><?php echo $delete_text; ?></a>
  314. <?php
  315. }
  316. ?>
  317. </div>
  318. <div id="publishing-action">
  319. <span class="spinner"></span>
  320. <?php
  321. if ( ! in_array( $post->post_status, array( 'publish', 'future', 'private' ), true ) || 0 === $post_id ) {
  322. if ( $can_publish ) :
  323. if ( ! empty( $post->post_date_gmt ) && time() < strtotime( $post->post_date_gmt . ' +0000' ) ) :
  324. ?>
  325. <input name="original_publish" type="hidden" id="original_publish" value="<?php echo esc_attr_x( 'Schedule', 'post action/button label' ); ?>" />
  326. <?php submit_button( _x( 'Schedule', 'post action/button label' ), 'primary large', 'publish', false ); ?>
  327. <?php
  328. else :
  329. ?>
  330. <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e( 'Publish' ); ?>" />
  331. <?php submit_button( __( 'Publish' ), 'primary large', 'publish', false ); ?>
  332. <?php
  333. endif;
  334. else :
  335. ?>
  336. <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e( 'Submit for Review' ); ?>" />
  337. <?php submit_button( __( 'Submit for Review' ), 'primary large', 'publish', false ); ?>
  338. <?php
  339. endif;
  340. } else {
  341. ?>
  342. <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e( 'Update' ); ?>" />
  343. <?php submit_button( __( 'Update' ), 'primary large', 'save', false, array( 'id' => 'publish' ) ); ?>
  344. <?php
  345. }
  346. ?>
  347. </div>
  348. <div class="clear"></div>
  349. </div>
  350. </div>
  351. <?php
  352. }
  353. /**
  354. * Displays attachment submit form fields.
  355. *
  356. * @since 3.5.0
  357. *
  358. * @param WP_Post $post Current post object.
  359. */
  360. function attachment_submit_meta_box( $post ) {
  361. ?>
  362. <div class="submitbox" id="submitpost">
  363. <div id="minor-publishing">
  364. <?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key. ?>
  365. <div style="display:none;">
  366. <?php submit_button( __( 'Save' ), '', 'save' ); ?>
  367. </div>
  368. <div id="misc-publishing-actions">
  369. <div class="misc-pub-section curtime misc-pub-curtime">
  370. <span id="timestamp">
  371. <?php
  372. $uploaded_on = sprintf(
  373. /* translators: Publish box date string. 1: Date, 2: Time. See https://www.php.net/manual/datetime.format.php */
  374. __( '%1$s at %2$s' ),
  375. /* translators: Publish box date format, see https://www.php.net/manual/datetime.format.php */
  376. date_i18n( _x( 'M j, Y', 'publish box date format' ), strtotime( $post->post_date ) ),
  377. /* translators: Publish box time format, see https://www.php.net/manual/datetime.format.php */
  378. date_i18n( _x( 'H:i', 'publish box time format' ), strtotime( $post->post_date ) )
  379. );
  380. /* translators: Attachment information. %s: Date the attachment was uploaded. */
  381. printf( __( 'Uploaded on: %s' ), '<b>' . $uploaded_on . '</b>' );
  382. ?>
  383. </span>
  384. </div><!-- .misc-pub-section -->
  385. <?php
  386. /**
  387. * Fires after the 'Uploaded on' section of the Save meta box
  388. * in the attachment editing screen.
  389. *
  390. * @since 3.5.0
  391. * @since 4.9.0 Added the `$post` parameter.
  392. *
  393. * @param WP_Post $post WP_Post object for the current attachment.
  394. */
  395. do_action( 'attachment_submitbox_misc_actions', $post );
  396. ?>
  397. </div><!-- #misc-publishing-actions -->
  398. <div class="clear"></div>
  399. </div><!-- #minor-publishing -->
  400. <div id="major-publishing-actions">
  401. <div id="delete-action">
  402. <?php
  403. if ( current_user_can( 'delete_post', $post->ID ) ) {
  404. if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) {
  405. echo "<a class='submitdelete deletion' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Move to Trash' ) . '</a>';
  406. } else {
  407. $delete_ays = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : '';
  408. echo "<a class='submitdelete deletion'$delete_ays href='" . get_delete_post_link( $post->ID, null, true ) . "'>" . __( 'Delete permanently' ) . '</a>';
  409. }
  410. }
  411. ?>
  412. </div>
  413. <div id="publishing-action">
  414. <span class="spinner"></span>
  415. <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e( 'Update' ); ?>" />
  416. <input name="save" type="submit" class="button button-primary button-large" id="publish" value="<?php esc_attr_e( 'Update' ); ?>" />
  417. </div>
  418. <div class="clear"></div>
  419. </div><!-- #major-publishing-actions -->
  420. </div>
  421. <?php
  422. }
  423. /**
  424. * Displays post format form elements.
  425. *
  426. * @since 3.1.0
  427. *
  428. * @param WP_Post $post Current post object.
  429. * @param array $box {
  430. * Post formats meta box arguments.
  431. *
  432. * @type string $id Meta box 'id' attribute.
  433. * @type string $title Meta box title.
  434. * @type callable $callback Meta box display callback.
  435. * @type array $args Extra meta box arguments.
  436. * }
  437. */
  438. function post_format_meta_box( $post, $box ) {
  439. if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) ) :
  440. $post_formats = get_theme_support( 'post-formats' );
  441. if ( is_array( $post_formats[0] ) ) :
  442. $post_format = get_post_format( $post->ID );
  443. if ( ! $post_format ) {
  444. $post_format = '0';
  445. }
  446. // Add in the current one if it isn't there yet, in case the active theme doesn't support it.
  447. if ( $post_format && ! in_array( $post_format, $post_formats[0], true ) ) {
  448. $post_formats[0][] = $post_format;
  449. }
  450. ?>
  451. <div id="post-formats-select">
  452. <fieldset>
  453. <legend class="screen-reader-text"><?php _e( 'Post Formats' ); ?></legend>
  454. <input type="radio" name="post_format" class="post-format" id="post-format-0" value="0" <?php checked( $post_format, '0' ); ?> /> <label for="post-format-0" class="post-format-icon post-format-standard"><?php echo get_post_format_string( 'standard' ); ?></label>
  455. <?php foreach ( $post_formats[0] as $format ) : ?>
  456. <br /><input type="radio" name="post_format" class="post-format" id="post-format-<?php echo esc_attr( $format ); ?>" value="<?php echo esc_attr( $format ); ?>" <?php checked( $post_format, $format ); ?> /> <label for="post-format-<?php echo esc_attr( $format ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></label>
  457. <?php endforeach; ?>
  458. </fieldset>
  459. </div>
  460. <?php
  461. endif;
  462. endif;
  463. }
  464. /**
  465. * Displays post tags form fields.
  466. *
  467. * @since 2.6.0
  468. *
  469. * @todo Create taxonomy-agnostic wrapper for this.
  470. *
  471. * @param WP_Post $post Current post object.
  472. * @param array $box {
  473. * Tags meta box arguments.
  474. *
  475. * @type string $id Meta box 'id' attribute.
  476. * @type string $title Meta box title.
  477. * @type callable $callback Meta box display callback.
  478. * @type array $args {
  479. * Extra meta box arguments.
  480. *
  481. * @type string $taxonomy Taxonomy. Default 'post_tag'.
  482. * }
  483. * }
  484. */
  485. function post_tags_meta_box( $post, $box ) {
  486. $defaults = array( 'taxonomy' => 'post_tag' );
  487. if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) {
  488. $args = array();
  489. } else {
  490. $args = $box['args'];
  491. }
  492. $parsed_args = wp_parse_args( $args, $defaults );
  493. $tax_name = esc_attr( $parsed_args['taxonomy'] );
  494. $taxonomy = get_taxonomy( $parsed_args['taxonomy'] );
  495. $user_can_assign_terms = current_user_can( $taxonomy->cap->assign_terms );
  496. $comma = _x( ',', 'tag delimiter' );
  497. $terms_to_edit = get_terms_to_edit( $post->ID, $tax_name );
  498. if ( ! is_string( $terms_to_edit ) ) {
  499. $terms_to_edit = '';
  500. }
  501. ?>
  502. <div class="tagsdiv" id="<?php echo $tax_name; ?>">
  503. <div class="jaxtag">
  504. <div class="nojs-tags hide-if-js">
  505. <label for="tax-input-<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_or_remove_items; ?></label>
  506. <p><textarea name="<?php echo "tax_input[$tax_name]"; ?>" rows="3" cols="20" class="the-tags" id="tax-input-<?php echo $tax_name; ?>" <?php disabled( ! $user_can_assign_terms ); ?> aria-describedby="new-tag-<?php echo $tax_name; ?>-desc"><?php echo str_replace( ',', $comma . ' ', $terms_to_edit ); // textarea_escaped by esc_attr() ?></textarea></p>
  507. </div>
  508. <?php if ( $user_can_assign_terms ) : ?>
  509. <div class="ajaxtag hide-if-no-js">
  510. <label class="screen-reader-text" for="new-tag-<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label>
  511. <input data-wp-taxonomy="<?php echo $tax_name; ?>" type="text" id="new-tag-<?php echo $tax_name; ?>" name="newtag[<?php echo $tax_name; ?>]" class="newtag form-input-tip" size="16" autocomplete="off" aria-describedby="new-tag-<?php echo $tax_name; ?>-desc" value="" />
  512. <input type="button" class="button tagadd" value="<?php esc_attr_e( 'Add' ); ?>" />
  513. </div>
  514. <p class="howto" id="new-tag-<?php echo $tax_name; ?>-desc"><?php echo $taxonomy->labels->separate_items_with_commas; ?></p>
  515. <?php elseif ( empty( $terms_to_edit ) ) : ?>
  516. <p><?php echo $taxonomy->labels->no_terms; ?></p>
  517. <?php endif; ?>
  518. </div>
  519. <ul class="tagchecklist" role="list"></ul>
  520. </div>
  521. <?php if ( $user_can_assign_terms ) : ?>
  522. <p class="hide-if-no-js"><button type="button" class="button-link tagcloud-link" id="link-<?php echo $tax_name; ?>" aria-expanded="false"><?php echo $taxonomy->labels->choose_from_most_used; ?></button></p>
  523. <?php endif; ?>
  524. <?php
  525. }
  526. /**
  527. * Displays post categories form fields.
  528. *
  529. * @since 2.6.0
  530. *
  531. * @todo Create taxonomy-agnostic wrapper for this.
  532. *
  533. * @param WP_Post $post Current post object.
  534. * @param array $box {
  535. * Categories meta box arguments.
  536. *
  537. * @type string $id Meta box 'id' attribute.
  538. * @type string $title Meta box title.
  539. * @type callable $callback Meta box display callback.
  540. * @type array $args {
  541. * Extra meta box arguments.
  542. *
  543. * @type string $taxonomy Taxonomy. Default 'category'.
  544. * }
  545. * }
  546. */
  547. function post_categories_meta_box( $post, $box ) {
  548. $defaults = array( 'taxonomy' => 'category' );
  549. if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) {
  550. $args = array();
  551. } else {
  552. $args = $box['args'];
  553. }
  554. $parsed_args = wp_parse_args( $args, $defaults );
  555. $tax_name = esc_attr( $parsed_args['taxonomy'] );
  556. $taxonomy = get_taxonomy( $parsed_args['taxonomy'] );
  557. ?>
  558. <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
  559. <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
  560. <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
  561. <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php echo esc_html( $taxonomy->labels->most_used ); ?></a></li>
  562. </ul>
  563. <div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;">
  564. <ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
  565. <?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?>
  566. </ul>
  567. </div>
  568. <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
  569. <?php
  570. $name = ( 'category' === $tax_name ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
  571. // Allows for an empty term set to be sent. 0 is an invalid term ID and will be ignored by empty() checks.
  572. echo "<input type='hidden' name='{$name}[]' value='0' />";
  573. ?>
  574. <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
  575. <?php
  576. wp_terms_checklist(
  577. $post->ID,
  578. array(
  579. 'taxonomy' => $tax_name,
  580. 'popular_cats' => $popular_ids,
  581. )
  582. );
  583. ?>
  584. </ul>
  585. </div>
  586. <?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?>
  587. <div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children">
  588. <a id="<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js taxonomy-add-new">
  589. <?php
  590. /* translators: %s: Add New taxonomy label. */
  591. printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
  592. ?>
  593. </a>
  594. <p id="<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
  595. <label class="screen-reader-text" for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label>
  596. <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" aria-required="true" />
  597. <label class="screen-reader-text" for="new<?php echo $tax_name; ?>_parent">
  598. <?php echo $taxonomy->labels->parent_item_colon; ?>
  599. </label>
  600. <?php
  601. $parent_dropdown_args = array(
  602. 'taxonomy' => $tax_name,
  603. 'hide_empty' => 0,
  604. 'name' => 'new' . $tax_name . '_parent',
  605. 'orderby' => 'name',
  606. 'hierarchical' => 1,
  607. 'show_option_none' => '&mdash; ' . $taxonomy->labels->parent_item . ' &mdash;',
  608. );
  609. /**
  610. * Filters the arguments for the taxonomy parent dropdown on the Post Edit page.
  611. *
  612. * @since 4.4.0
  613. *
  614. * @param array $parent_dropdown_args {
  615. * Optional. Array of arguments to generate parent dropdown.
  616. *
  617. * @type string $taxonomy Name of the taxonomy to retrieve.
  618. * @type bool $hide_if_empty True to skip generating markup if no
  619. * categories are found. Default 0.
  620. * @type string $name Value for the 'name' attribute
  621. * of the select element.
  622. * Default "new{$tax_name}_parent".
  623. * @type string $orderby Which column to use for ordering
  624. * terms. Default 'name'.
  625. * @type bool|int $hierarchical Whether to traverse the taxonomy
  626. * hierarchy. Default 1.
  627. * @type string $show_option_none Text to display for the "none" option.
  628. * Default "&mdash; {$parent} &mdash;",
  629. * where `$parent` is 'parent_item'
  630. * taxonomy label.
  631. * }
  632. */
  633. $parent_dropdown_args = apply_filters( 'post_edit_category_parent_dropdown_args', $parent_dropdown_args );
  634. wp_dropdown_categories( $parent_dropdown_args );
  635. ?>
  636. <input type="button" id="<?php echo $tax_name; ?>-add-submit" data-wp-lists="add:<?php echo $tax_name; ?>checklist:<?php echo $tax_name; ?>-add" class="button category-add-submit" value="<?php echo esc_attr( $taxonomy->labels->add_new_item ); ?>" />
  637. <?php wp_nonce_field( 'add-' . $tax_name, '_ajax_nonce-add-' . $tax_name, false ); ?>
  638. <span id="<?php echo $tax_name; ?>-ajax-response"></span>
  639. </p>
  640. </div>
  641. <?php endif; ?>
  642. </div>
  643. <?php
  644. }
  645. /**
  646. * Displays post excerpt form fields.
  647. *
  648. * @since 2.6.0
  649. *
  650. * @param WP_Post $post Current post object.
  651. */
  652. function post_excerpt_meta_box( $post ) {
  653. ?>
  654. <label class="screen-reader-text" for="excerpt"><?php _e( 'Excerpt' ); ?></label><textarea rows="1" cols="40" name="excerpt" id="excerpt"><?php echo $post->post_excerpt; // textarea_escaped ?></textarea>
  655. <p>
  656. <?php
  657. printf(
  658. /* translators: %s: Documentation URL. */
  659. __( 'Excerpts are optional hand-crafted summaries of your content that can be used in your theme. <a href="%s">Learn more about manual excerpts</a>.' ),
  660. __( 'https://wordpress.org/support/article/excerpt/' )
  661. );
  662. ?>
  663. </p>
  664. <?php
  665. }
  666. /**
  667. * Displays trackback links form fields.
  668. *
  669. * @since 2.6.0
  670. *
  671. * @param WP_Post $post Current post object.
  672. */
  673. function post_trackback_meta_box( $post ) {
  674. $form_trackback = '<input type="text" name="trackback_url" id="trackback_url" class="code" value="' .
  675. esc_attr( str_replace( "\n", ' ', $post->to_ping ) ) . '" aria-describedby="trackback-url-desc" />';
  676. if ( '' !== $post->pinged ) {
  677. $pings = '<p>' . __( 'Already pinged:' ) . '</p><ul>';
  678. $already_pinged = explode( "\n", trim( $post->pinged ) );
  679. foreach ( $already_pinged as $pinged_url ) {
  680. $pings .= "\n\t<li>" . esc_html( $pinged_url ) . '</li>';
  681. }
  682. $pings .= '</ul>';
  683. }
  684. ?>
  685. <p>
  686. <label for="trackback_url"><?php _e( 'Send trackbacks to:' ); ?></label>
  687. <?php echo $form_trackback; ?>
  688. </p>
  689. <p id="trackback-url-desc" class="howto"><?php _e( 'Separate multiple URLs with spaces' ); ?></p>
  690. <p>
  691. <?php
  692. printf(
  693. /* translators: %s: Documentation URL. */
  694. __( 'Trackbacks are a way to notify legacy blog systems that you&#8217;ve linked to them. If you link other WordPress sites, they&#8217;ll be notified automatically using <a href="%s">pingbacks</a>, no other action necessary.' ),
  695. __( 'https://wordpress.org/support/article/introduction-to-blogging/#comments' )
  696. );
  697. ?>
  698. </p>
  699. <?php
  700. if ( ! empty( $pings ) ) {
  701. echo $pings;
  702. }
  703. }
  704. /**
  705. * Displays custom fields form fields.
  706. *
  707. * @since 2.6.0
  708. *
  709. * @param WP_Post $post Current post object.
  710. */
  711. function post_custom_meta_box( $post ) {
  712. ?>
  713. <div id="postcustomstuff">
  714. <div id="ajax-response"></div>
  715. <?php
  716. $metadata = has_meta( $post->ID );
  717. foreach ( $metadata as $key => $value ) {
  718. if ( is_protected_meta( $metadata[ $key ]['meta_key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post->ID, $metadata[ $key ]['meta_key'] ) ) {
  719. unset( $metadata[ $key ] );
  720. }
  721. }
  722. list_meta( $metadata );
  723. meta_form( $post );
  724. ?>
  725. </div>
  726. <p>
  727. <?php
  728. printf(
  729. /* translators: %s: Documentation URL. */
  730. __( 'Custom fields can be used to add extra metadata to a post that you can <a href="%s">use in your theme</a>.' ),
  731. __( 'https://wordpress.org/support/article/custom-fields/' )
  732. );
  733. ?>
  734. </p>
  735. <?php
  736. }
  737. /**
  738. * Displays comments status form fields.
  739. *
  740. * @since 2.6.0
  741. *
  742. * @param WP_Post $post Current post object.
  743. */
  744. function post_comment_status_meta_box( $post ) {
  745. ?>
  746. <input name="advanced_view" type="hidden" value="1" />
  747. <p class="meta-options">
  748. <label for="comment_status" class="selectit"><input name="comment_status" type="checkbox" id="comment_status" value="open" <?php checked( $post->comment_status, 'open' ); ?> /> <?php _e( 'Allow comments' ); ?></label><br />
  749. <label for="ping_status" class="selectit"><input name="ping_status" type="checkbox" id="ping_status" value="open" <?php checked( $post->ping_status, 'open' ); ?> />
  750. <?php
  751. printf(
  752. /* translators: %s: Documentation URL. */
  753. __( 'Allow <a href="%s">trackbacks and pingbacks</a> on this page' ),
  754. __( 'https://wordpress.org/support/article/introduction-to-blogging/#managing-comments' )
  755. );
  756. ?>
  757. </label>
  758. <?php
  759. /**
  760. * Fires at the end of the Discussion meta box on the post editing screen.
  761. *
  762. * @since 3.1.0
  763. *
  764. * @param WP_Post $post WP_Post object for the current post.
  765. */
  766. do_action( 'post_comment_status_meta_box-options', $post ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
  767. ?>
  768. </p>
  769. <?php
  770. }
  771. /**
  772. * Displays comments for post table header
  773. *
  774. * @since 3.0.0
  775. *
  776. * @param array $result Table header rows.
  777. * @return array
  778. */
  779. function post_comment_meta_box_thead( $result ) {
  780. unset( $result['cb'], $result['response'] );
  781. return $result;
  782. }
  783. /**
  784. * Displays comments for post.
  785. *
  786. * @since 2.8.0
  787. *
  788. * @param WP_Post $post Current post object.
  789. */
  790. function post_comment_meta_box( $post ) {
  791. wp_nonce_field( 'get-comments', 'add_comment_nonce', false );
  792. ?>
  793. <p class="hide-if-no-js" id="add-new-comment"><button type="button" class="button" onclick="window.commentReply && commentReply.addcomment(<?php echo $post->ID; ?>);"><?php _e( 'Add Comment' ); ?></button></p>
  794. <?php
  795. $total = get_comments(
  796. array(
  797. 'post_id' => $post->ID,
  798. 'number' => 1,
  799. 'count' => true,
  800. )
  801. );
  802. $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table' );
  803. $wp_list_table->display( true );
  804. if ( 1 > $total ) {
  805. echo '<p id="no-comments">' . __( 'No comments yet.' ) . '</p>';
  806. } else {
  807. $hidden = get_hidden_meta_boxes( get_current_screen() );
  808. if ( ! in_array( 'commentsdiv', $hidden, true ) ) {
  809. ?>
  810. <script type="text/javascript">jQuery(function(){commentsBox.get(<?php echo $total; ?>, 10);});</script>
  811. <?php
  812. }
  813. ?>
  814. <p class="hide-if-no-js" id="show-comments"><a href="#commentstatusdiv" onclick="commentsBox.load(<?php echo $total; ?>);return false;"><?php _e( 'Show comments' ); ?></a> <span class="spinner"></span></p>
  815. <?php
  816. }
  817. wp_comment_trashnotice();
  818. }
  819. /**
  820. * Displays slug form fields.
  821. *
  822. * @since 2.6.0
  823. *
  824. * @param WP_Post $post Current post object.
  825. */
  826. function post_slug_meta_box( $post ) {
  827. /** This filter is documented in wp-admin/edit-tag-form.php */
  828. $editable_slug = apply_filters( 'editable_slug', $post->post_name, $post );
  829. ?>
  830. <label class="screen-reader-text" for="post_name"><?php _e( 'Slug' ); ?></label><input name="post_name" type="text" size="13" id="post_name" value="<?php echo esc_attr( $editable_slug ); ?>" />
  831. <?php
  832. }
  833. /**
  834. * Displays form field with list of authors.
  835. *
  836. * @since 2.6.0
  837. *
  838. * @global int $user_ID
  839. *
  840. * @param WP_Post $post Current post object.
  841. */
  842. function post_author_meta_box( $post ) {
  843. global $user_ID;
  844. $post_type_object = get_post_type_object( $post->post_type );
  845. ?>
  846. <label class="screen-reader-text" for="post_author_override"><?php _e( 'Author' ); ?></label>
  847. <?php
  848. wp_dropdown_users(
  849. array(
  850. 'capability' => array( $post_type_object->cap->edit_posts ),
  851. 'name' => 'post_author_override',
  852. 'selected' => empty( $post->ID ) ? $user_ID : $post->post_author,
  853. 'include_selected' => true,
  854. 'show' => 'display_name_with_login',
  855. )
  856. );
  857. }
  858. /**
  859. * Displays list of revisions.
  860. *
  861. * @since 2.6.0
  862. *
  863. * @param WP_Post $post Current post object.
  864. */
  865. function post_revisions_meta_box( $post ) {
  866. wp_list_post_revisions( $post );
  867. }
  868. //
  869. // Page-related Meta Boxes.
  870. //
  871. /**
  872. * Displays page attributes form fields.
  873. *
  874. * @since 2.7.0
  875. *
  876. * @param WP_Post $post Current post object.
  877. */
  878. function page_attributes_meta_box( $post ) {
  879. if ( is_post_type_hierarchical( $post->post_type ) ) :
  880. $dropdown_args = array(
  881. 'post_type' => $post->post_type,
  882. 'exclude_tree' => $post->ID,
  883. 'selected' => $post->post_parent,
  884. 'name' => 'parent_id',
  885. 'show_option_none' => __( '(no parent)' ),
  886. 'sort_column' => 'menu_order, post_title',
  887. 'echo' => 0,
  888. );
  889. /**
  890. * Filters the arguments used to generate a Pages drop-down element.
  891. *
  892. * @since 3.3.0
  893. *
  894. * @see wp_dropdown_pages()
  895. *
  896. * @param array $dropdown_args Array of arguments used to generate the pages drop-down.
  897. * @param WP_Post $post The current post.
  898. */
  899. $dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post );
  900. $pages = wp_dropdown_pages( $dropdown_args );
  901. if ( ! empty( $pages ) ) :
  902. ?>
  903. <p class="post-attributes-label-wrapper parent-id-label-wrapper"><label class="post-attributes-label" for="parent_id"><?php _e( 'Parent' ); ?></label></p>
  904. <?php echo $pages; ?>
  905. <?php
  906. endif; // End empty pages check.
  907. endif; // End hierarchical check.
  908. if ( count( get_page_templates( $post ) ) > 0 && get_option( 'page_for_posts' ) != $post->ID ) :
  909. $template = ! empty( $post->page_template ) ? $post->page_template : false;
  910. ?>
  911. <p class="post-attributes-label-wrapper page-template-label-wrapper"><label class="post-attributes-label" for="page_template"><?php _e( 'Template' ); ?></label>
  912. <?php
  913. /**
  914. * Fires immediately after the label inside the 'Template' section
  915. * of the 'Page Attributes' meta box.
  916. *
  917. * @since 4.4.0
  918. *
  919. * @param string|false $template The template used for the current post.
  920. * @param WP_Post $post The current post.
  921. */
  922. do_action( 'page_attributes_meta_box_template', $template, $post );
  923. ?>
  924. </p>
  925. <select name="page_template" id="page_template">
  926. <?php
  927. /**
  928. * Filters the title of the default page template displayed in the drop-down.
  929. *
  930. * @since 4.1.0
  931. *
  932. * @param string $label The display value for the default page template title.
  933. * @param string $context Where the option label is displayed. Possible values
  934. * include 'meta-box' or 'quick-edit'.
  935. */
  936. $default_title = apply_filters( 'default_page_template_title', __( 'Default template' ), 'meta-box' );
  937. ?>
  938. <option value="default"><?php echo esc_html( $default_title ); ?></option>
  939. <?php page_template_dropdown( $template, $post->post_type ); ?>
  940. </select>
  941. <?php endif; ?>
  942. <?php if ( post_type_supports( $post->post_type, 'page-attributes' ) ) : ?>
  943. <p class="post-attributes-label-wrapper menu-order-label-wrapper"><label class="post-attributes-label" for="menu_order"><?php _e( 'Order' ); ?></label></p>
  944. <input name="menu_order" type="text" size="4" id="menu_order" value="<?php echo esc_attr( $post->menu_order ); ?>" />
  945. <?php
  946. /**
  947. * Fires before the help hint text in the 'Page Attributes' meta box.
  948. *
  949. * @since 4.9.0
  950. *
  951. * @param WP_Post $post The current post.
  952. */
  953. do_action( 'page_attributes_misc_attributes', $post );
  954. ?>
  955. <?php if ( 'page' === $post->post_type && get_current_screen()->get_help_tabs() ) : ?>
  956. <p class="post-attributes-help-text"><?php _e( 'Need help? Use the Help tab above the screen title.' ); ?></p>
  957. <?php
  958. endif;
  959. endif;
  960. }
  961. //
  962. // Link-related Meta Boxes.
  963. //
  964. /**
  965. * Displays link create form fields.
  966. *
  967. * @since 2.7.0
  968. *
  969. * @param object $link Current link object.
  970. */
  971. function link_submit_meta_box( $link ) {
  972. ?>
  973. <div class="submitbox" id="submitlink">
  974. <div id="minor-publishing">
  975. <?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key. ?>
  976. <div style="display:none;">
  977. <?php submit_button( __( 'Save' ), '', 'save', false ); ?>
  978. </div>
  979. <div id="minor-publishing-actions">
  980. <div id="preview-action">
  981. <?php if ( ! empty( $link->link_id ) ) { ?>
  982. <a class="preview button" href="<?php echo $link->link_url; ?>" target="_blank"><?php _e( 'Visit Link' ); ?></a>
  983. <?php } ?>
  984. </div>
  985. <div class="clear"></div>
  986. </div>
  987. <div id="misc-publishing-actions">
  988. <div class="misc-pub-section misc-pub-private">
  989. <label for="link_private" class="selectit"><input id="link_private" name="link_visible" type="checkbox" value="N" <?php checked( $link->link_visible, 'N' ); ?> /> <?php _e( 'Keep this link private' ); ?></label>
  990. </div>
  991. </div>
  992. </div>
  993. <div id="major-publishing-actions">
  994. <?php
  995. /** This action is documented in wp-admin/includes/meta-boxes.php */
  996. do_action( 'post_submitbox_start', null );
  997. ?>
  998. <div id="delete-action">
  999. <?php
  1000. if ( ! empty( $_GET['action'] ) && 'edit' === $_GET['action'] && current_user_can( 'manage_links' ) ) {
  1001. printf(
  1002. '<a class="submitdelete deletion" href="%s" onclick="return confirm( \'%s\' );">%s</a>',
  1003. wp_nonce_url( "link.php?action=delete&amp;link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ),
  1004. /* translators: %s: Link name. */
  1005. esc_js( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ),
  1006. __( 'Delete' )
  1007. );
  1008. }
  1009. ?>
  1010. </div>
  1011. <div id="publishing-action">
  1012. <?php if ( ! empty( $link->link_id ) ) { ?>
  1013. <input name="save" type="submit" class="button button-primary button-large" id="publish" value="<?php esc_attr_e( 'Update Link' ); ?>" />
  1014. <?php } else { ?>
  1015. <input name="save" type="submit" class="button button-primary button-large" id="publish" value="<?php esc_attr_e( 'Add Link' ); ?>" />
  1016. <?php } ?>
  1017. </div>
  1018. <div class="clear"></div>
  1019. </div>
  1020. <?php
  1021. /**
  1022. * Fires at the end of the Publish box in the Link editing screen.
  1023. *
  1024. * @since 2.5.0
  1025. */
  1026. do_action( 'submitlink_box' );
  1027. ?>
  1028. <div class="clear"></div>
  1029. </div>
  1030. <?php
  1031. }
  1032. /**
  1033. * Displays link categories form fields.
  1034. *
  1035. * @since 2.6.0
  1036. *
  1037. * @param object $link Current link object.
  1038. */
  1039. function link_categories_meta_box( $link ) {
  1040. ?>
  1041. <div id="taxonomy-linkcategory" class="categorydiv">
  1042. <ul id="category-tabs" class="category-tabs">
  1043. <li class="tabs"><a href="#categories-all"><?php _e( 'All categories' ); ?></a></li>
  1044. <li class="hide-if-no-js"><a href="#categories-pop"><?php _ex( 'Most Used', 'categories' ); ?></a></li>
  1045. </ul>
  1046. <div id="categories-all" class="tabs-panel">
  1047. <ul id="categorychecklist" data-wp-lists="list:category" class="categorychecklist form-no-clear">
  1048. <?php
  1049. if ( isset( $link->link_id ) ) {
  1050. wp_link_category_checklist( $link->link_id );
  1051. } else {
  1052. wp_link_category_checklist();
  1053. }
  1054. ?>
  1055. </ul>
  1056. </div>
  1057. <div id="categories-pop" class="tabs-panel" style="display: none;">
  1058. <ul id="categorychecklist-pop" class="categorychecklist form-no-clear">
  1059. <?php wp_popular_terms_checklist( 'link_category' ); ?>
  1060. </ul>
  1061. </div>
  1062. <div id="category-adder" class="wp-hidden-children">
  1063. <a id="category-add-toggle" href="#category-add" class="taxonomy-add-new"><?php _e( '+ Add New Category' ); ?></a>
  1064. <p id="link-category-add" class="wp-hidden-child">
  1065. <label class="screen-reader-text" for="newcat"><?php _e( '+ Add New Category' ); ?></label>
  1066. <input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php esc_attr_e( 'New category name' ); ?>" aria-required="true" />
  1067. <input type="button" id="link-category-add-submit" data-wp-lists="add:categorychecklist:link-category-add" class="button" value="<?php esc_attr_e( 'Add' ); ?>" />
  1068. <?php wp_nonce_field( 'add-link-category', '_ajax_nonce', false ); ?>
  1069. <span id="category-ajax-response"></span>
  1070. </p>
  1071. </div>
  1072. </div>
  1073. <?php
  1074. }
  1075. /**
  1076. * Displays form fields for changing link target.
  1077. *
  1078. * @since 2.6.0
  1079. *
  1080. * @param object $link Current link object.
  1081. */
  1082. function link_target_meta_box( $link ) {
  1083. ?>
  1084. <fieldset><legend class="screen-reader-text"><span><?php _e( 'Target' ); ?></span></legend>
  1085. <p><label for="link_target_blank" class="selectit">
  1086. <input id="link_target_blank" type="radio" name="link_target" value="_blank" <?php echo ( isset( $link->link_target ) && ( '_blank' === $link->link_target ) ? 'checked="checked"' : '' ); ?> />
  1087. <?php _e( '<code>_blank</code> &mdash; new window or tab.' ); ?></label></p>
  1088. <p><label for="link_target_top" class="selectit">
  1089. <input id="link_target_top" type="radio" name="link_target" value="_top" <?php echo ( isset( $link->link_target ) && ( '_top' === $link->link_target ) ? 'checked="checked"' : '' ); ?> />
  1090. <?php _e( '<code>_top</code> &mdash; current window or tab, with no frames.' ); ?></label></p>
  1091. <p><label for="link_target_none" class="selectit">
  1092. <input id="link_target_none" type="radio" name="link_target" value="" <?php echo ( isset( $link->link_target ) && ( '' === $link->link_target ) ? 'checked="checked"' : '' ); ?> />
  1093. <?php _e( '<code>_none</code> &mdash; same window or tab.' ); ?></label></p>
  1094. </fieldset>
  1095. <p><?php _e( 'Choose the target frame for your link.' ); ?></p>
  1096. <?php
  1097. }
  1098. /**
  1099. * Displays 'checked' checkboxes attribute for XFN microformat options.
  1100. *
  1101. * @since 1.0.1
  1102. *
  1103. * @global object $link Current link object.
  1104. *
  1105. * @param string $xfn_relationship XFN relationship category. Possible values are:
  1106. * 'friendship', 'physical', 'professional',
  1107. * 'geographical', 'family', 'romantic', 'identity'.
  1108. * @param string $xfn_value Optional. The XFN value to mark as checked
  1109. * if it matches the current link's relationship.
  1110. * Default empty string.
  1111. * @param mixed $deprecated Deprecated. Not used.
  1112. */
  1113. function xfn_check( $xfn_relationship, $xfn_value = '', $deprecated = '' ) {
  1114. global $link;
  1115. if ( ! empty( $deprecated ) ) {
  1116. _deprecated_argument( __FUNCTION__, '2.5.0' ); // Never implemented.
  1117. }
  1118. $link_rel = isset( $link->link_rel ) ? $link->link_rel : ''; // In PHP 5.3: $link_rel = $link->link_rel ?: '';
  1119. $link_rels = preg_split( '/\s+/', $link_rel );
  1120. // Mark the specified value as checked if it matches the current link's relationship.
  1121. if ( '' !== $xfn_value && in_array( $xfn_value, $link_rels, true ) ) {
  1122. echo ' checked="checked"';
  1123. }
  1124. if ( '' === $xfn_value ) {
  1125. // Mark the 'none' value as checked if the current link does not match the specified relationship.
  1126. if ( 'family' === $xfn_relationship
  1127. && ! array_intersect( $link_rels, array( 'child', 'parent', 'sibling', 'spouse', 'kin' ) )
  1128. ) {
  1129. echo ' checked="checked"';
  1130. }
  1131. if ( 'friendship' === $xfn_relationship
  1132. && ! array_intersect( $link_rels, array( 'friend', 'acquaintance', 'contact' ) )
  1133. ) {
  1134. echo ' checked="checked"';
  1135. }
  1136. if ( 'geographical' === $xfn_relationship
  1137. && ! array_intersect( $link_rels, array( 'co-resident', 'neighbor' ) )
  1138. ) {
  1139. echo ' checked="checked"';
  1140. }
  1141. // Mark the 'me' value as checked if it matches the current link's relationship.
  1142. if ( 'identity' === $xfn_relationship
  1143. && in_array( 'me', $link_rels, true )
  1144. ) {
  1145. echo ' checked="checked"';
  1146. }
  1147. }
  1148. }
  1149. /**
  1150. * Displays XFN form fields.
  1151. *
  1152. * @since 2.6.0
  1153. *
  1154. * @param object $link Current link object.
  1155. */
  1156. function link_xfn_meta_box( $link ) {
  1157. ?>
  1158. <table class="links-table">
  1159. <tr>
  1160. <th scope="row"><label for="link_rel"><?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'rel:' ); ?></label></th>
  1161. <td><input type="text" name="link_rel" id="link_rel" value="<?php echo ( isset( $link->link_rel ) ? esc_attr( $link->link_rel ) : '' ); ?>" /></td>
  1162. </tr>
  1163. <tr>
  1164. <th scope="row"><?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'identity' ); ?></th>
  1165. <td><fieldset><legend class="screen-reader-text"><span><?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'identity' ); ?></span></legend>
  1166. <label for="me">
  1167. <input type="checkbox" name="identity" value="me" id="me" <?php xfn_check( 'identity', 'me' ); ?> />
  1168. <?php _e( 'another web address of mine' ); ?></label>
  1169. </fieldset></td>
  1170. </tr>
  1171. <tr>
  1172. <th scope="row"><?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'friendship' ); ?></th>
  1173. <td><fieldset><legend class="screen-reader-text"><span><?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'friendship' ); ?></span></legend>
  1174. <label for="contact">
  1175. <input class="valinp" type="radio" name="friendship" value="contact" id="contact" <?php xfn_check( 'friendship', 'contact' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'contact' ); ?>
  1176. </label>
  1177. <label for="acquaintance">
  1178. <input class="valinp" type="radio" name="friendship" value="acquaintance" id="acquaintance" <?php xfn_check( 'friendship', 'acquaintance' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'acquaintance' ); ?>
  1179. </label>
  1180. <label for="friend">
  1181. <input class="valinp" type="radio" name="friendship" value="friend" id="friend" <?php xfn_check( 'friendship', 'friend' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'friend' ); ?>
  1182. </label>
  1183. <label for="friendship">
  1184. <input name="friendship" type="radio" class="valinp" value="" id="friendship" <?php xfn_check( 'friendship' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'none' ); ?>
  1185. </label>
  1186. </fieldset></td>
  1187. </tr>
  1188. <tr>
  1189. <th scope="row"> <?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'physical' ); ?> </th>
  1190. <td><fieldset><legend class="screen-reader-text"><span><?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'physical' ); ?></span></legend>
  1191. <label for="met">
  1192. <input class="valinp" type="checkbox" name="physical" value="met" id="met" <?php xfn_check( 'physical', 'met' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'met' ); ?>
  1193. </label>
  1194. </fieldset></td>
  1195. </tr>
  1196. <tr>
  1197. <th scope="row"> <?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'professional' ); ?> </th>
  1198. <td><fieldset><legend class="screen-reader-text"><span><?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'professional' ); ?></span></legend>
  1199. <label for="co-worker">
  1200. <input class="valinp" type="checkbox" name="professional" value="co-worker" id="co-worker" <?php xfn_check( 'professional', 'co-worker' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'co-worker' ); ?>
  1201. </label>
  1202. <label for="colleague">
  1203. <input class="valinp" type="checkbox" name="professional" value="colleague" id="colleague" <?php xfn_check( 'professional', 'colleague' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'colleague' ); ?>
  1204. </label>
  1205. </fieldset></td>
  1206. </tr>
  1207. <tr>
  1208. <th scope="row"><?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'geographical' ); ?></th>
  1209. <td><fieldset><legend class="screen-reader-text"><span> <?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'geographical' ); ?> </span></legend>
  1210. <label for="co-resident">
  1211. <input class="valinp" type="radio" name="geographical" value="co-resident" id="co-resident" <?php xfn_check( 'geographical', 'co-resident' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'co-resident' ); ?>
  1212. </label>
  1213. <label for="neighbor">
  1214. <input class="valinp" type="radio" name="geographical" value="neighbor" id="neighbor" <?php xfn_check( 'geographical', 'neighbor' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'neighbor' ); ?>
  1215. </label>
  1216. <label for="geographical">
  1217. <input class="valinp" type="radio" name="geographical" value="" id="geographical" <?php xfn_check( 'geographical' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'none' ); ?>
  1218. </label>
  1219. </fieldset></td>
  1220. </tr>
  1221. <tr>
  1222. <th scope="row"><?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'family' ); ?></th>
  1223. <td><fieldset><legend class="screen-reader-text"><span> <?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'family' ); ?> </span></legend>
  1224. <label for="child">
  1225. <input class="valinp" type="radio" name="family" value="child" id="child" <?php xfn_check( 'family', 'child' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'child' ); ?>
  1226. </label>
  1227. <label for="kin">
  1228. <input class="valinp" type="radio" name="family" value="kin" id="kin" <?php xfn_check( 'family', 'kin' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'kin' ); ?>
  1229. </label>
  1230. <label for="parent">
  1231. <input class="valinp" type="radio" name="family" value="parent" id="parent" <?php xfn_check( 'family', 'parent' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'parent' ); ?>
  1232. </label>
  1233. <label for="sibling">
  1234. <input class="valinp" type="radio" name="family" value="sibling" id="sibling" <?php xfn_check( 'family', 'sibling' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'sibling' ); ?>
  1235. </label>
  1236. <label for="spouse">
  1237. <input class="valinp" type="radio" name="family" value="spouse" id="spouse" <?php xfn_check( 'family', 'spouse' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'spouse' ); ?>
  1238. </label>
  1239. <label for="family">
  1240. <input class="valinp" type="radio" name="family" value="" id="family" <?php xfn_check( 'family' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'none' ); ?>
  1241. </label>
  1242. </fieldset></td>
  1243. </tr>
  1244. <tr>
  1245. <th scope="row"><?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'romantic' ); ?></th>
  1246. <td><fieldset><legend class="screen-reader-text"><span> <?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'romantic' ); ?> </span></legend>
  1247. <label for="muse">
  1248. <input class="valinp" type="checkbox" name="romantic" value="muse" id="muse" <?php xfn_check( 'romantic', 'muse' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'muse' ); ?>
  1249. </label>
  1250. <label for="crush">
  1251. <input class="valinp" type="checkbox" name="romantic" value="crush" id="crush" <?php xfn_check( 'romantic', 'crush' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'crush' ); ?>
  1252. </label>
  1253. <label for="date">
  1254. <input class="valinp" type="checkbox" name="romantic" value="date" id="date" <?php xfn_check( 'romantic', 'date' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'date' ); ?>
  1255. </label>
  1256. <label for="romantic">
  1257. <input class="valinp" type="checkbox" name="romantic" value="sweetheart" id="romantic" <?php xfn_check( 'romantic', 'sweetheart' ); ?> />&nbsp;<?php /* translators: xfn: https://gmpg.org/xfn/ */ _e( 'sweetheart' ); ?>
  1258. </label>
  1259. </fieldset></td>
  1260. </tr>
  1261. </table>
  1262. <p><?php _e( 'If the link is to a person, you can specify your relationship with them using the above form. If you would like to learn more about the idea check out <a href="https://gmpg.org/xfn/">XFN</a>.' ); ?></p>
  1263. <?php
  1264. }
  1265. /**
  1266. * Displays advanced link options form fields.
  1267. *
  1268. * @since 2.6.0
  1269. *
  1270. * @param object $link Current link object.
  1271. */
  1272. function link_advanced_meta_box( $link ) {
  1273. ?>
  1274. <table class="links-table" cellpadding="0">
  1275. <tr>
  1276. <th scope="row"><label for="link_image"><?php _e( 'Image Address' ); ?></label></th>
  1277. <td><input type="text" name="link_image" class="code" id="link_image" maxlength="255" value="<?php echo ( isset( $link->link_image ) ? esc_attr( $link->link_image ) : '' ); ?>" /></td>
  1278. </tr>
  1279. <tr>
  1280. <th scope="row"><label for="rss_uri"><?php _e( 'RSS Address' ); ?></label></th>
  1281. <td><input name="link_rss" class="code" type="text" id="rss_uri" maxlength="255" value="<?php echo ( isset( $link->link_rss ) ? esc_attr( $link->link_rss ) : '' ); ?>" /></td>
  1282. </tr>
  1283. <tr>
  1284. <th scope="row"><label for="link_notes"><?php _e( 'Notes' ); ?></label></th>
  1285. <td><textarea name="link_notes" id="link_notes" rows="10"><?php echo ( isset( $link->link_notes ) ? $link->link_notes : '' ); // textarea_escaped ?></textarea></td>
  1286. </tr>
  1287. <tr>
  1288. <th scope="row"><label for="link_rating"><?php _e( 'Rating' ); ?></label></th>
  1289. <td><select name="link_rating" id="link_rating" size="1">
  1290. <?php
  1291. for ( $rating = 0; $rating <= 10; $rating++ ) {
  1292. echo '<option value="' . $rating . '"';
  1293. if ( isset( $link->link_rating ) && $link->link_rating == $rating ) {
  1294. echo ' selected="selected"';
  1295. }
  1296. echo '>' . $rating . '</option>';
  1297. }
  1298. ?>
  1299. </select>&nbsp;<?php _e( '(Leave at 0 for no rating.)' ); ?>
  1300. </td>
  1301. </tr>
  1302. </table>
  1303. <?php
  1304. }
  1305. /**
  1306. * Displays post thumbnail meta box.
  1307. *
  1308. * @since 2.9.0
  1309. *
  1310. * @param WP_Post $post Current post object.
  1311. */
  1312. function post_thumbnail_meta_box( $post ) {
  1313. $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
  1314. echo _wp_post_thumbnail_html( $thumbnail_id, $post->ID );
  1315. }
  1316. /**
  1317. * Displays fields for ID3 data.
  1318. *
  1319. * @since 3.9.0
  1320. *
  1321. * @param WP_Post $post Current post object.
  1322. */
  1323. function attachment_id3_data_meta_box( $post ) {
  1324. $meta = array();
  1325. if ( ! empty( $post->ID ) ) {
  1326. $meta = wp_get_attachment_metadata( $post->ID );
  1327. }
  1328. foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) :
  1329. $value = '';
  1330. if ( ! empty( $meta[ $key ] ) ) {
  1331. $value = $meta[ $key ];
  1332. }
  1333. ?>
  1334. <p>
  1335. <label for="title"><?php echo $label; ?></label><br />
  1336. <input type="text" name="id3_<?php echo esc_attr( $key ); ?>" id="id3_<?php echo esc_attr( $key ); ?>" class="large-text" value="<?php echo esc_attr( $value ); ?>" />
  1337. </p>
  1338. <?php
  1339. endforeach;
  1340. }
  1341. /**
  1342. * Registers the default post meta boxes, and runs the `do_meta_boxes` actions.
  1343. *
  1344. * @since 5.0.0
  1345. *
  1346. * @param WP_Post $post The post object that these meta boxes are being generated for.
  1347. */
  1348. function register_and_do_post_meta_boxes( $post ) {
  1349. $post_type = $post->post_type;
  1350. $post_type_object = get_post_type_object( $post_type );
  1351. $thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' );
  1352. if ( ! $thumbnail_support && 'attachment' === $post_type && $post->post_mime_type ) {
  1353. if ( wp_attachment_is( 'audio', $post ) ) {
  1354. $thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' );
  1355. } elseif ( wp_attachment_is( 'video', $post ) ) {
  1356. $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
  1357. }
  1358. }
  1359. $publish_callback_args = array( '__back_compat_meta_box' => true );
  1360. if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' !== $post->post_status ) {
  1361. $revisions = wp_get_latest_revision_id_and_total_count( $post->ID );
  1362. // We should aim to show the revisions meta box only when there are revisions.
  1363. if ( ! is_wp_error( $revisions ) && $revisions['count'] > 1 ) {
  1364. $publish_callback_args = array(
  1365. 'revisions_count' => $revisions['count'],
  1366. 'revision_id' => $revisions['latest_id'],
  1367. '__back_compat_meta_box' => true,
  1368. );
  1369. add_meta_box( 'revisionsdiv', __( 'Revisions' ), 'post_revisions_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
  1370. }
  1371. }
  1372. if ( 'attachment' === $post_type ) {
  1373. wp_enqueue_script( 'image-edit' );
  1374. wp_enqueue_style( 'imgareaselect' );
  1375. add_meta_box( 'submitdiv', __( 'Save' ), 'attachment_submit_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
  1376. add_action( 'edit_form_after_title', 'edit_form_image_editor' );
  1377. if ( wp_attachment_is( 'audio', $post ) ) {
  1378. add_meta_box( 'attachment-id3', __( 'Metadata' ), 'attachment_id3_data_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
  1379. }
  1380. } else {
  1381. add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', null, 'side', 'core', $publish_callback_args );
  1382. }
  1383. if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post_type, 'post-formats' ) ) {
  1384. add_meta_box( 'formatdiv', _x( 'Format', 'post format' ), 'post_format_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
  1385. }
  1386. // All taxonomies.
  1387. foreach ( get_object_taxonomies( $post ) as $tax_name ) {
  1388. $taxonomy = get_taxonomy( $tax_name );
  1389. if ( ! $taxonomy->show_ui || false === $taxonomy->meta_box_cb ) {
  1390. continue;
  1391. }
  1392. $label = $taxonomy->labels->name;
  1393. if ( ! is_taxonomy_hierarchical( $tax_name ) ) {
  1394. $tax_meta_box_id = 'tagsdiv-' . $tax_name;
  1395. } else {
  1396. $tax_meta_box_id = $tax_name . 'div';
  1397. }
  1398. add_meta_box(
  1399. $tax_meta_box_id,
  1400. $label,
  1401. $taxonomy->meta_box_cb,
  1402. null,
  1403. 'side',
  1404. 'core',
  1405. array(
  1406. 'taxonomy' => $tax_name,
  1407. '__back_compat_meta_box' => true,
  1408. )
  1409. );
  1410. }
  1411. if ( post_type_supports( $post_type, 'page-attributes' ) || count( get_page_templates( $post ) ) > 0 ) {
  1412. add_meta_box( 'pageparentdiv', $post_type_object->labels->attributes, 'page_attributes_meta_box', null, 'side', 'core', array( '__back_compat_meta_box' => true ) );
  1413. }
  1414. if ( $thumbnail_support && current_user_can( 'upload_files' ) ) {
  1415. add_meta_box( 'postimagediv', esc_html( $post_type_object->labels->featured_image ), 'post_thumbnail_meta_box', null, 'side', 'low', array( '__back_compat_meta_box' => true ) );
  1416. }
  1417. if ( post_type_supports( $post_type, 'excerpt' ) ) {
  1418. add_meta_box( 'postexcerpt', __( 'Excerpt' ), 'post_excerpt_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
  1419. }
  1420. if ( post_type_supports( $post_type, 'trackbacks' ) ) {
  1421. add_meta_box( 'trackbacksdiv', __( 'Send Trackbacks' ), 'post_trackback_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
  1422. }
  1423. if ( post_type_supports( $post_type, 'custom-fields' ) ) {
  1424. add_meta_box(
  1425. 'postcustom',
  1426. __( 'Custom Fields' ),
  1427. 'post_custom_meta_box',
  1428. null,
  1429. 'normal',
  1430. 'core',
  1431. array(
  1432. '__back_compat_meta_box' => ! (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ),
  1433. '__block_editor_compatible_meta_box' => true,
  1434. )
  1435. );
  1436. }
  1437. /**
  1438. * Fires in the middle of built-in meta box registration.
  1439. *
  1440. * @since 2.1.0
  1441. * @deprecated 3.7.0 Use {@see 'add_meta_boxes'} instead.
  1442. *
  1443. * @param WP_Post $post Post object.
  1444. */
  1445. do_action_deprecated( 'dbx_post_advanced', array( $post ), '3.7.0', 'add_meta_boxes' );
  1446. // Allow the Discussion meta box to show up if the post type supports comments,
  1447. // or if comments or pings are open.
  1448. if ( comments_open( $post ) || pings_open( $post ) || post_type_supports( $post_type, 'comments' ) ) {
  1449. add_meta_box( 'commentstatusdiv', __( 'Discussion' ), 'post_comment_status_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
  1450. }
  1451. $stati = get_post_stati( array( 'public' => true ) );
  1452. if ( empty( $stati ) ) {
  1453. $stati = array( 'publish' );
  1454. }
  1455. $stati[] = 'private';
  1456. if ( in_array( get_post_status( $post ), $stati, true ) ) {
  1457. // If the post type support comments, or the post has comments,
  1458. // allow the Comments meta box.
  1459. if ( comments_open( $post ) || pings_open( $post ) || $post->comment_count > 0 || post_type_supports( $post_type, 'comments' ) ) {
  1460. add_meta_box( 'commentsdiv', __( 'Comments' ), 'post_comment_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
  1461. }
  1462. }
  1463. if ( ! ( 'pending' === get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) ) ) {
  1464. add_meta_box( 'slugdiv', __( 'Slug' ), 'post_slug_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
  1465. }
  1466. if ( post_type_supports( $post_type, 'author' ) && current_user_can( $post_type_object->cap->edit_others_posts ) ) {
  1467. add_meta_box( 'authordiv', __( 'Author' ), 'post_author_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => true ) );
  1468. }
  1469. /**
  1470. * Fires after all built-in meta boxes have been added.
  1471. *
  1472. * @since 3.0.0
  1473. *
  1474. * @param string $post_type Post type.
  1475. * @param WP_Post $post Post object.
  1476. */
  1477. do_action( 'add_meta_boxes', $post_type, $post );
  1478. /**
  1479. * Fires after all built-in meta boxes have been added, contextually for the given post type.
  1480. *
  1481. * The dynamic portion of the hook name, `$post_type`, refers to the post type of the post.
  1482. *
  1483. * Possible hook names include:
  1484. *
  1485. * - `add_meta_boxes_post`
  1486. * - `add_meta_boxes_page`
  1487. * - `add_meta_boxes_attachment`
  1488. *
  1489. * @since 3.0.0
  1490. *
  1491. * @param WP_Post $post Post object.
  1492. */
  1493. do_action( "add_meta_boxes_{$post_type}", $post );
  1494. /**
  1495. * Fires after meta boxes have been added.
  1496. *
  1497. * Fires once for each of the default meta box contexts: normal, advanced, and side.
  1498. *
  1499. * @since 3.0.0
  1500. *
  1501. * @param string $post_type Post type of the post on Edit Post screen, 'link' on Edit Link screen,
  1502. * 'dashboard' on Dashboard screen.
  1503. * @param string $context Meta box context. Possible values include 'normal', 'advanced', 'side'.
  1504. * @param WP_Post|object|string $post Post object on Edit Post screen, link object on Edit Link screen,
  1505. * an empty string on Dashboard screen.
  1506. */
  1507. do_action( 'do_meta_boxes', $post_type, 'normal', $post );
  1508. /** This action is documented in wp-admin/includes/meta-boxes.php */
  1509. do_action( 'do_meta_boxes', $post_type, 'advanced', $post );
  1510. /** This action is documented in wp-admin/includes/meta-boxes.php */
  1511. do_action( 'do_meta_boxes', $post_type, 'side', $post );
  1512. }