I'm looking for a way to replace the submitdiv meta box (publish box) with just one simple save button. By looking at Core I see there's a simple function returning a submit button: get_submit_button() .
I have no problem replacing the publish metabox , showing just one simple 'save' button and making sure the post has the right status with the wp_insert_post_data() hook. However, when I edit a post and try to save ,the 'Are you sure you want to...' dialog appears. I'm guessing a nonce of some sort is missing, but I can't figure out where.
Please note that I do not just want to blend out stuff with css. This is unsave and quite frankly (in my opinion) , unreliable.
Here's what I have so far:
/* Remove the default publish meta box
*
*/
add_action( 'admin_head', 'cs_admin_meta_boxes' );
function cs_admin_meta_boxes(){
remove_meta_box( 'submitdiv', 'cpt_name', 'side');
}
/* Add meta 'save' meta box
*
*/
add_action( 'add_meta_boxes', 'cs_meta_box_add' );
function cs_meta_box_add(){
add_meta_box( 'cs-save', 'Save', 'cs_meta_box_save', 'cpt_name', 'side', 'high' );
}
/* 'Save' meta box content
*
*/
function cs_meta_box_save(){
echo get_submit_button( $text = 'Save', $type = 'primary', $name = 'submit', $wrap = true, $other_attributes = NULL );
}
/**
* Sets the post status to published
*/
add_filter( 'wp_insert_post_data', 'cs_force_published' );
function cs_force_published( $post ) {
if( in_array( $post[ 'post_type' ], array( 'cpt_name') ) ) {
$post['post_status'] = 'publish';
}
return $post;
}