Created
May 14, 2015 19:06
-
-
Save anonymous/b2ff66c279a7cd1d7079 to your computer and use it in GitHub Desktop.
WPSE 188373
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function fb_modify_author_meta_boxes() { | |
remove_meta_box('authordiv', 'post', 'normal'); | |
add_meta_box('fb_authordiv', __('Author'), 'fb_post_author_meta_box', 'post', 'normal', 'core'); | |
} | |
add_action( 'admin_menu', 'fb_modify_author_meta_boxes' ); | |
function fb_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 | |
)); | |
$show_author = !! get_post_meta( $post->ID, 'show_author', true ); | |
?> | |
<input type="checkbox" name="show_author" <?php checked( $show_author ) /* WordPress helper function */ ?> style="margin-left:15px" /> Check the box to display the author's byline and author box. | |
<input type="hidden" name="do_show_author" value="1" /> | |
<?php | |
} | |
/* Save checkbox status */ | |
function save_details( $post_ID ) { | |
if ( isset( $_POST['do_show_author'] ) ) { | |
// Use isset - unchecked checkboxes won't send a value to $_POST, you'll get an undefined index error | |
update_post_meta( $post_ID, 'show_author', isset( $_POST['show_author'] ) ? '1' : '0' ); | |
} | |
} | |
add_action( 'save_post', 'save_details' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment