yan-k
10/20/2014 - 3:02 PM

Codesnippet for manipulating Author Boxes in the WordPress Admin. Credit goes to Patrick Holberg Hesselberg.

Codesnippet for manipulating Author Boxes in the WordPress Admin.

Credit goes to Patrick Holberg Hesselberg.

function site_fix_authordiv() {
        // wp-admin/post-new.php
        if ( !isset($_GET['post_type']) ) {
                $post_type = 'post';
        }
 
        elseif ( in_array( $_GET['post_type'], get_post_types( array('show_ui' => true ) ) ) ) {
                $post_type = $_GET['post_type'];
        }
        else {
                wp_die( __('Invalid post type') );
        }
 
        // wp-admin/edit-form-advanced.php
        if ( post_type_supports($post_type, 'author') ) {
                $post_type_object = get_post_type_object( $post_type );
 
                if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) {
                        remove_meta_box( 'authordiv', 'tip', 'normal' );
                        add_meta_box('site-authordiv', __('Author'), 'site_fix_post_author_meta_box', 'tip', 'normal', 'core');
                }
        }
}
 
// wp-admin/includes/meta-boxes.php
function site_fix_post_author_meta_box($post) {
        global $user_ID;
?>
<label class="screen-reader-text" for="post_author_override"><?php _e('Author'); ?></label>
<?php
        wp_dropdown_users( array(
                'name' => 'post_author_override',
                'selected' => empty($post->ID) ? $user_ID : $post->post_author,
                'include_selected' => true
        ) );
}
 
add_action( 'add_meta_boxes', 'site_fix_authordiv' );