Advertisement
wp-coding

Move Author metabox to Publish Metatbox

Sep 6th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.65 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Move author metabox to publish metabox
  4.  *
  5.  * NOT with Gutenberg enabled {use @link https://wordpress.org/plugins/disable-gutenberg/}
  6.  *
  7.  * The first function will remove the original author metabox
  8.  * and the second function will add the author metabox to the publish metabox
  9.  * The first function will also do a check for if( is_admin) so it will only run
  10.  * in the back-end.
  11.  *
  12.  * Read more {@link https://codex.wordpress.org/Plugin_API/Action_Reference/post_submitbox_misc_actions}
  13.  *           {@link https://developer.wordpress.org/reference/functions/remove_meta_box/}
  14.  *           {@link https://developer.wordpress.org/reference/functions/add_meta_box/}
  15.  *
  16.  * Works with WP @version 5.0.3 and below
  17.  */
  18.  
  19. /**
  20.  * Remove the author metabox
  21.  */
  22. add_action('add_meta_boxes', 'remove_author_metabox', 999);  
  23. function remove_author_metabox()
  24. {
  25.     if( is_admin() )
  26.     {
  27.    
  28.     $post_types = get_post_types();
  29.         foreach ( $post_types as $post_type )
  30.         {
  31.             remove_meta_box('authordiv', $post_type, 'normal');
  32.         }
  33.     }
  34. }
  35.  
  36. /**
  37.  * Add author metabox to the publish metabox
  38.  */
  39. add_action( 'post_submitbox_misc_actions', 'add_author_metabox_to_publish_metabox' );
  40. function add_author_metabox_to_publish_metabox()
  41. {
  42.     ?><style>
  43.     .misc-pub-section {
  44.         border-top-style:solid;
  45.         border-top-width:1px;
  46.         border-top-color:#EEEEEE;
  47.         border-bottom-width:0px;
  48.     }
  49.     </style><?php
  50.  
  51.     global $post_ID;
  52.     $post = get_post( $post_ID );
  53.  
  54.     echo '<div id="author" class="misc-pub-section" >Author: ';
  55.     post_author_meta_box( $post );
  56.     echo '</div>';
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement