Advertisement
cgrymala

Move "Submit" meta box to bottom of side panel in WordPress

Mar 21st, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.37 KB | None | 0 0
  1. <?php
  2. function move_submit_box_to_bottom() {
  3.     /**
  4.      * Set a version number for the updated metabox order.
  5.      * If you need to reorder the boxes again, increase this version number
  6.      */
  7.     $mbv = '1.1.3';
  8.    
  9.     /**
  10.      * Set the content type and the meta box context
  11.      */
  12.     $post_type = 'post';
  13.     $context = 'side';
  14.    
  15.     if ( ! is_admin() || ! current_user_can( 'edit_posts' ) )
  16.         return;
  17.    
  18.     global $current_user;
  19.     get_currentuserinfo();
  20.     /**
  21.      * Check to see if we've already updated our metaboxes (we don't want to
  22.      *      overwrite a user's manual changes)
  23.      */
  24.     $done = get_user_meta( $current_user->id, 'reordered_' . $post_type . '_meta_boxes', true );
  25.     if ( $mbv === $done )
  26.         return;
  27.    
  28.     global $wp_meta_boxes;
  29.     if ( ! is_array( $wp_meta_boxes ) )
  30.         return;
  31.    
  32.     if ( ! array_key_exists( $post_type, $wp_meta_boxes ) || ! array_key_exists( $context, $wp_meta_boxes[$post_type] ) )
  33.         return;
  34.     $all_boxes = array();
  35.     foreach ( $wp_meta_boxes[$post_type][$context] as $priority ) {
  36.         foreach( $priority as $box ) {
  37.             if ( false == $box || ! $box['title'] )
  38.                 continue;
  39.            
  40.             $all_boxes[] = $box['id'];
  41.         }
  42.     }
  43.    
  44.     /**
  45.      * Retrieve the order of the post meta boxes
  46.      * If you want to update the meta boxes on a content type other than "post",
  47.      *      change "_post" to the appropriate content type
  48.      */
  49.     $order = get_user_meta( $current_user->id, 'meta-box-order_' . $post_type, true );
  50.     if ( empty( $order ) )
  51.         $order = array( 'side' => implode( ',', $all_boxes ) );
  52.     else
  53.         $order['side'] = implode( ',', $all_boxes );
  54.    
  55.     $tmp = explode( ',', $order[$context] );
  56.     if ( count( $tmp ) !== 0 ) {
  57.         if ( false !== ( $i = array_search( 'submitdiv', $tmp ) ) ) {
  58.             unset( $tmp[$i] );
  59.         }
  60.         if ( false !== ( $j = array_search( '', $tmp ) ) ) {
  61.             unset( $tmp[$j] );
  62.         }
  63.     }
  64.    
  65.     /**
  66.      * Add the Submit meta box to the end of the array
  67.      */
  68.     $tmp[] = 'submitdiv';
  69.     $order['side'] = implode( ',', $tmp );
  70.    
  71.     /**
  72.      * Save the new meta box order
  73.      */
  74.     update_user_meta( $current_user->id, 'meta-box-order_post', $order );
  75.    
  76.     /**
  77.      * Update the option that tells us we already did this in the future
  78.      */
  79.     update_user_meta( $current_user->id, 'reordered_' . $post_type . '_meta_boxes', $mbv );
  80. }
  81. /**
  82.  * This action seems to be the first place we can hook after the
  83.  *      $wp_meta_boxes array is set
  84.  */
  85. add_action( 'parse_query', 'move_submit_box_to_bottom', 99 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement