post_submit_meta_box

Displays post submit form fields.

Description

post_submit_meta_box( (WP_Post) $post, (array) $args = array() ); 

Parameters (2)

0. $post (WP_Post)
Current post object.
1. $args — Optional. (array) => array()
Array of arguments for building the post submit meta box.

Options

  • id (string) => ''

    Meta box id attribute.

  • title (string) => ''

    Meta box title.

  • callback (callable) => null

    Meta box display callback.

array(

    /**
     * Meta box 'id' attribute.
     *
     * @type string
     * @default ''
     */
    'id' => '',

    /**
     * Meta box title.
     *
     * @type string
     * @default ''
     */
    'title' => '',

    /**
     * Meta box display callback.
     *
     * @type callable
     * @default null
     */
    'callback' => null
);        


Usage

  1. if ( !function_exists( 'post_submit_meta_box' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/meta-boxes.php'; 
  3.  
  4. // Current post object. 
  5. $post = null; 
  6.  
  7. // Array of arguments for building the post submit meta box. 
  8. $args = array( 
  9. 'id' => '', 
  10. 'title' => '', 
  11. 'callback' => null 
  12. ); 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = post_submit_meta_box($post, $args); 
  16.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/meta-boxes.php  
  1. function post_submit_meta_box( $post, $args = array() ) { 
  2. global $action; 
  3.  
  4. $post_type = $post->post_type; 
  5. $post_type_object = get_post_type_object($post_type); 
  6. $can_publish = current_user_can($post_type_object->cap->publish_posts); 
  7. ?> 
  8. <div class="submitbox" id="submitpost"> 
  9.  
  10. <div id="minor-publishing"> 
  11.  
  12. <?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key ?> 
  13. <div style="display:none;"> 
  14. <?php submit_button( __( 'Save' ), '', 'save' ); ?> 
  15. </div> 
  16.  
  17. <div id="minor-publishing-actions"> 
  18. <div id="save-action"> 
  19. <?php if ( 'publish' != $post->post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?> 
  20. <input <?php if ( 'private' == $post->post_status ) { ?>style="display:none"<?php } ?> type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save Draft'); ?>" class="button" /> 
  21. <span class="spinner"></span> 
  22. <?php } elseif ( 'pending' == $post->post_status && $can_publish ) { ?> 
  23. <input type="submit" name="save" id="save-post" value="<?php esc_attr_e('Save as Pending'); ?>" class="button" /> 
  24. <span class="spinner"></span> 
  25. <?php } ?> 
  26. </div> 
  27. <?php if ( is_post_type_viewable( $post_type_object ) ) : ?> 
  28. <div id="preview-action"> 
  29. <?php 
  30. $preview_link = esc_url( get_preview_post_link( $post ) ); 
  31. if ( 'publish' == $post->post_status ) { 
  32. $preview_button = __( 'Preview Changes' ); 
  33. } else { 
  34. $preview_button = __( 'Preview' ); 
  35. ?> 
  36. <a class="preview button" href="<?php echo $preview_link; ?>" target="wp-preview-<?php echo (int) $post->ID; ?>" id="post-preview"><?php echo $preview_button; ?></a> 
  37. <input type="hidden" name="wp-preview" id="wp-preview" value="" /> 
  38. </div> 
  39. <?php endif; // public post type ?> 
  40. <?php 
  41. /** 
  42. * Fires before the post time/date setting in the Publish meta box. 
  43. * @since 4.4.0 
  44. * @param WP_Post $post WP_Post object for the current post. 
  45. */ 
  46. do_action( 'post_submitbox_minor_actions', $post ); 
  47. ?> 
  48. <div class="clear"></div> 
  49. </div><!-- #minor-publishing-actions --> 
  50.  
  51. <div id="misc-publishing-actions"> 
  52.  
  53. <div class="misc-pub-section misc-pub-post-status"> 
  54. <?php _e( 'Status:' ) ?> <span id="post-status-display"><?php 
  55.  
  56. switch ( $post->post_status ) { 
  57. case 'private': 
  58. _e('Privately Published'); 
  59. break; 
  60. case 'publish': 
  61. _e('Published'); 
  62. break; 
  63. case 'future': 
  64. _e('Scheduled'); 
  65. break; 
  66. case 'pending': 
  67. _e('Pending Review'); 
  68. break; 
  69. case 'draft': 
  70. case 'auto-draft': 
  71. _e('Draft'); 
  72. break; 
  73. ?> 
  74. </span> 
  75. <?php if ( 'publish' == $post->post_status || 'private' == $post->post_status || $can_publish ) { ?> 
  76. <a href="#post_status" <?php if ( 'private' == $post->post_status ) { ?>style="display:none;" <?php } ?>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> 
  77.  
  78. <div id="post-status-select" class="hide-if-js"> 
  79. <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); ?>" /> 
  80. <label for="post_status" class="screen-reader-text"><?php _e( 'Set status' ) ?></label> 
  81. <select name="post_status" id="post_status"> 
  82. <?php if ( 'publish' == $post->post_status ) : ?> 
  83. <option<?php selected( $post->post_status, 'publish' ); ?> value='publish'><?php _e('Published') ?></option> 
  84. <?php elseif ( 'private' == $post->post_status ) : ?> 
  85. <option<?php selected( $post->post_status, 'private' ); ?> value='publish'><?php _e('Privately Published') ?></option> 
  86. <?php elseif ( 'future' == $post->post_status ) : ?> 
  87. <option<?php selected( $post->post_status, 'future' ); ?> value='future'><?php _e('Scheduled') ?></option> 
  88. <?php endif; ?> 
  89. <option<?php selected( $post->post_status, 'pending' ); ?> value='pending'><?php _e('Pending Review') ?></option> 
  90. <?php if ( 'auto-draft' == $post->post_status ) : ?> 
  91. <option<?php selected( $post->post_status, 'auto-draft' ); ?> value='draft'><?php _e('Draft') ?></option> 
  92. <?php else : ?> 
  93. <option<?php selected( $post->post_status, 'draft' ); ?> value='draft'><?php _e('Draft') ?></option> 
  94. <?php endif; ?> 
  95. </select> 
  96. <a href="#post_status" class="save-post-status hide-if-no-js button"><?php _e('OK'); ?></a> 
  97. <a href="#post_status" class="cancel-post-status hide-if-no-js button-cancel"><?php _e('Cancel'); ?></a> 
  98. </div> 
  99.  
  100. <?php } ?> 
  101. </div><!-- .misc-pub-section --> 
  102.  
  103. <div class="misc-pub-section misc-pub-visibility" id="visibility"> 
  104. <?php _e('Visibility:'); ?> <span id="post-visibility-display"><?php 
  105.  
  106. if ( 'private' == $post->post_status ) { 
  107. $post->post_password = ''; 
  108. $visibility = 'private'; 
  109. $visibility_trans = __('Private'); 
  110. } elseif ( !empty( $post->post_password ) ) { 
  111. $visibility = 'password'; 
  112. $visibility_trans = __('Password protected'); 
  113. } elseif ( $post_type == 'post' && is_sticky( $post->ID ) ) { 
  114. $visibility = 'public'; 
  115. $visibility_trans = __('Public, Sticky'); 
  116. } else { 
  117. $visibility = 'public'; 
  118. $visibility_trans = __('Public'); 
  119.  
  120. echo esc_html( $visibility_trans ); ?></span> 
  121. <?php if ( $can_publish ) { ?> 
  122. <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> 
  123.  
  124. <div id="post-visibility-select" class="hide-if-js"> 
  125. <input type="hidden" name="hidden_post_password" id="hidden-post-password" value="<?php echo esc_attr($post->post_password); ?>" /> 
  126. <?php if ($post_type == 'post'): ?> 
  127. <input type="checkbox" style="display:none" name="hidden_post_sticky" id="hidden-post-sticky" value="sticky" <?php checked(is_sticky($post->ID)); ?> /> 
  128. <?php endif; ?> 
  129. <input type="hidden" name="hidden_post_visibility" id="hidden-post-visibility" value="<?php echo esc_attr( $visibility ); ?>" /> 
  130. <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 /> 
  131. <?php if ( $post_type == 'post' && current_user_can( 'edit_others_posts' ) ) : ?> 
  132. <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> 
  133. <?php endif; ?> 
  134. <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 /> 
  135. <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> 
  136. <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 /> 
  137.  
  138. <p> 
  139. <a href="#visibility" class="save-post-visibility hide-if-no-js button"><?php _e('OK'); ?></a> 
  140. <a href="#visibility" class="cancel-post-visibility hide-if-no-js button-cancel"><?php _e('Cancel'); ?></a> 
  141. </p> 
  142. </div> 
  143. <?php } ?> 
  144.  
  145. </div><!-- .misc-pub-section --> 
  146.  
  147. <?php 
  148. /** translators: Publish box date format, see https://secure.php.net/date */ 
  149. $datef = __( 'M j, Y @ H:i' ); 
  150. if ( 0 != $post->ID ) { 
  151. if ( 'future' == $post->post_status ) { // scheduled for publishing at a future date 
  152. /** translators: Post date information. 1: Date on which the post is currently scheduled to be published */ 
  153. $stamp = __('Scheduled for: <b>%1$s</b>'); 
  154. } elseif ( 'publish' == $post->post_status || 'private' == $post->post_status ) { // already published 
  155. /** translators: Post date information. 1: Date on which the post was published */ 
  156. $stamp = __('Published on: <b>%1$s</b>'); 
  157. } elseif ( '0000-00-00 00:00:00' == $post->post_date_gmt ) { // draft, 1 or more saves, no date specified 
  158. $stamp = __('Publish <b>immediately</b>'); 
  159. } elseif ( time() < strtotime( $post->post_date_gmt . ' +0000' ) ) { // draft, 1 or more saves, future date specified 
  160. /** translators: Post date information. 1: Date on which the post is to be published */ 
  161. $stamp = __('Schedule for: <b>%1$s</b>'); 
  162. } else { // draft, 1 or more saves, date specified 
  163. /** translators: Post date information. 1: Date on which the post is to be published */ 
  164. $stamp = __('Publish on: <b>%1$s</b>'); 
  165. $date = date_i18n( $datef, strtotime( $post->post_date ) ); 
  166. } else { // draft (no saves, and thus no date specified) 
  167. $stamp = __('Publish <b>immediately</b>'); 
  168. $date = date_i18n( $datef, strtotime( current_time('mysql') ) ); 
  169.  
  170. if ( ! empty( $args['args']['revisions_count'] ) ) : ?> 
  171. <div class="misc-pub-section misc-pub-revisions"> 
  172. <?php 
  173. /** translators: Post revisions heading. 1: The number of available revisions */ 
  174. printf( __( 'Revisions: %s' ), '<b>' . number_format_i18n( $args['args']['revisions_count'] ) . '</b>' ); 
  175. ?> 
  176. <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> 
  177. </div> 
  178. <?php endif; 
  179.  
  180. if ( $can_publish ) : // Contributors don't get to choose the date of publish ?> 
  181. <div class="misc-pub-section curtime misc-pub-curtime"> 
  182. <span id="timestamp"> 
  183. <?php printf($stamp, $date); ?></span> 
  184. <a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" role="button"><span aria-hidden="true"><?php _e( 'Edit' ); ?></span> <span class="screen-reader-text"><?php _e( 'Edit date and time' ); ?></span></a> 
  185. <fieldset id="timestampdiv" class="hide-if-js"> 
  186. <legend class="screen-reader-text"><?php _e( 'Date and time' ); ?></legend> 
  187. <?php touch_time( ( $action === 'edit' ), 1 ); ?> 
  188. </fieldset> 
  189. </div><?php // /misc-pub-section ?> 
  190. <?php endif; ?> 
  191.  
  192. <?php 
  193. /** 
  194. * Fires after the post time/date setting in the Publish meta box. 
  195. * @since 2.9.0 
  196. * @since 4.4.0 Added the `$post` parameter. 
  197. * @param WP_Post $post WP_Post object for the current post. 
  198. */ 
  199. do_action( 'post_submitbox_misc_actions', $post ); 
  200. ?> 
  201. </div> 
  202. <div class="clear"></div> 
  203. </div> 
  204.  
  205. <div id="major-publishing-actions"> 
  206. <?php 
  207. /** 
  208. * Fires at the beginning of the publishing actions section of the Publish meta box. 
  209. * @since 2.7.0 
  210. */ 
  211. do_action( 'post_submitbox_start' ); 
  212. ?> 
  213. <div id="delete-action"> 
  214. <?php 
  215. if ( current_user_can( "delete_post", $post->ID ) ) { 
  216. if ( !EMPTY_TRASH_DAYS
  217. $delete_text = __('Delete Permanently'); 
  218. else 
  219. $delete_text = __('Move to Trash'); 
  220. ?> 
  221. <a class="submitdelete deletion" href="<?php echo get_delete_post_link($post->ID); ?>"><?php echo $delete_text; ?></a><?php 
  222. } ?> 
  223. </div> 
  224.  
  225. <div id="publishing-action"> 
  226. <span class="spinner"></span> 
  227. <?php 
  228. if ( !in_array( $post->post_status, array('publish', 'future', 'private') ) || 0 == $post->ID ) { 
  229. if ( $can_publish ) : 
  230. if ( !empty($post->post_date_gmt) && time() < strtotime( $post->post_date_gmt . ' +0000' ) ) : ?> 
  231. <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Schedule') ?>" /> 
  232. <?php submit_button( __( 'Schedule' ), 'primary large', 'publish', false ); ?> 
  233. <?php else : ?> 
  234. <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Publish') ?>" /> 
  235. <?php submit_button( __( 'Publish' ), 'primary large', 'publish', false ); ?> 
  236. <?php endif; 
  237. else : ?> 
  238. <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Submit for Review') ?>" /> 
  239. <?php submit_button( __( 'Submit for Review' ), 'primary large', 'publish', false ); ?> 
  240. <?php 
  241. endif; 
  242. } else { ?> 
  243. <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Update') ?>" /> 
  244. <input name="save" type="submit" class="button button-primary button-large" id="publish" value="<?php esc_attr_e( 'Update' ) ?>" /> 
  245. <?php 
  246. } ?> 
  247. </div> 
  248. <div class="clear"></div> 
  249. </div> 
  250. </div> 
  251.  
  252. <?php