1

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;

}
  • Please post your answer below as a response to this question. – iyrin Dec 2 '14 at 16:14
0

SOLVED: Found the solution. Trick is to disable the autosave. But take care to only do this on a non-ajax save.

add_action( 'admin_enqueue_scripts', 'my_admin_enqueue_scripts' );
function my_admin_enqueue_scripts() {
       if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return false; // don't disable if it is an auto-autosave
    if ( 'POST_TYPE' == get_post_type() ){

       wp_dequeue_script( 'autosave' );    
    }
}

Hope this helps someone.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.