Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function move_submit_box_to_bottom() {
- /**
- * Set a version number for the updated metabox order.
- * If you need to reorder the boxes again, increase this version number
- */
- $mbv = '1.1.3';
- /**
- * Set the content type and the meta box context
- */
- $post_type = 'post';
- $context = 'side';
- if ( ! is_admin() || ! current_user_can( 'edit_posts' ) )
- return;
- global $current_user;
- get_currentuserinfo();
- /**
- * Check to see if we've already updated our metaboxes (we don't want to
- * overwrite a user's manual changes)
- */
- $done = get_user_meta( $current_user->id, 'reordered_' . $post_type . '_meta_boxes', true );
- if ( $mbv === $done )
- return;
- global $wp_meta_boxes;
- if ( ! is_array( $wp_meta_boxes ) )
- return;
- if ( ! array_key_exists( $post_type, $wp_meta_boxes ) || ! array_key_exists( $context, $wp_meta_boxes[$post_type] ) )
- return;
- $all_boxes = array();
- foreach ( $wp_meta_boxes[$post_type][$context] as $priority ) {
- foreach( $priority as $box ) {
- if ( false == $box || ! $box['title'] )
- continue;
- $all_boxes[] = $box['id'];
- }
- }
- /**
- * Retrieve the order of the post meta boxes
- * If you want to update the meta boxes on a content type other than "post",
- * change "_post" to the appropriate content type
- */
- $order = get_user_meta( $current_user->id, 'meta-box-order_' . $post_type, true );
- if ( empty( $order ) )
- $order = array( 'side' => implode( ',', $all_boxes ) );
- else
- $order['side'] = implode( ',', $all_boxes );
- $tmp = explode( ',', $order[$context] );
- if ( count( $tmp ) !== 0 ) {
- if ( false !== ( $i = array_search( 'submitdiv', $tmp ) ) ) {
- unset( $tmp[$i] );
- }
- if ( false !== ( $j = array_search( '', $tmp ) ) ) {
- unset( $tmp[$j] );
- }
- }
- /**
- * Add the Submit meta box to the end of the array
- */
- $tmp[] = 'submitdiv';
- $order['side'] = implode( ',', $tmp );
- /**
- * Save the new meta box order
- */
- update_user_meta( $current_user->id, 'meta-box-order_post', $order );
- /**
- * Update the option that tells us we already did this in the future
- */
- update_user_meta( $current_user->id, 'reordered_' . $post_type . '_meta_boxes', $mbv );
- }
- /**
- * This action seems to be the first place we can hook after the
- * $wp_meta_boxes array is set
- */
- add_action( 'parse_query', 'move_submit_box_to_bottom', 99 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement