I don’t know if I’m missing something here but there are several ways to add Html to Existing core Author meta box and save a custom field -related to the post.
One option is to assign a new callback for the authordiv
html content, or add the html by filtering the output of the author dropdown select list on this box.
I prefer the latter, in case some plugin already created a callback. The filter is applied just before the boxes are rendered, and removed immediately after the first occurence of wp_dropdown_users
.
However, In any case, you need an action to the add_meta_boxes
hook:
function ua_add_meta_boxes($post_type, $post){
global $wp_meta_boxes;
if(!isset($wp_meta_boxes[$post_type]['normal']['core']['authordiv'])) return;
// Change the callback
$wp_meta_boxes[$post_type]['normal']['core']['authordiv']['callback'] = 'my_callback_authordiv_html';
// Or hook into the dropdown html created Html
add_filter('wp_dropdown_users', 'ua_extend_metbox_authordiv', 10, 1);
}
add_action('add_meta_boxes', 'ua_add_meta_boxes', 5, 2);
In case callback:
function my_callback_authordiv_html(){
// copy the default select stuff and add some more HTML of our own
}
In case filter the dropdown (with custom field example added):
function ua_extend_metbox_authordiv($html){
global $post;
remove_filter('wp_dropdown_users', 'ua_expand_author_box', 10, 1);
$meta = get_post_meta($post->ID, 'my_custom field', true);
$label = __('Check my checkbox', 'text-domain');
$html .= '<input type="hidden" name="ua_author_metabox_check_nonce" value="'. wp_create_nonce(basename(__FILE__)). '" />';
$html .= '<label><input type="checkbox" name="my_custom field" id="my_custom field"' . ( $meta ? ' checked="checked"' : '' ) . ' /> '.$label.'</label>';
return $html;
}
Then, you need the Save post actions for the custom field, but that is another topic.