Here's what I do. It doesn't create a new button, but will put a check mark right next to the publish/update button. The idea is that if you check the button before hitting the publish/update. it will run your function in the save. if it isn't check the system will save as normal. I have generalized the function names so you can make them more specific as well as button titles.
function rt_custom_save_action(){
global $post;
if (get_post_type($post) != 'post') //Choose Post type HERE
return false;
$html = '<div id="major-publishing-actions" style="overflow:hidden">';
$html .= '<div id="publishing-action">';
$html .= '<label><input type="checkbox" value="1" name="custom_action" />SAVE WITH FUNCTION</label>';
$html .= '</div>';
$html .= '</div>';
echo $html;
}
add_action( 'post_submitbox_misc_actions', 'rt_custom_save_action' );
function rt_project_updated_save_dosomething( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// If this is just a revision, don't do anything.
//if ( wp_is_post_revision( $post_id ) )
// return;
// only go if user checked action checkbox.
if(isset($_POST['custom_action'])){
//PUT SOMETHING HERE THAT YOU WANT TO HAPPEN
}
}
add_action( 'save_post', 'rt_project_updated_save_dosomething' ); //if you change the custom post type above, you have to change it here too (save_post_CUSTOMPOSTNAME)
If you wanted to use a button i suppose you could do this, i've removed the checkbox check in the function and added 2 button options. Try one then the other:
function rt_custom_save_action(){
global $post;
if (get_post_type($post) != 'post') //Choose Post type HERE
return false;
$html = '<div id="major-publishing-actions" style="overflow:hidden">';
$html .= '<div id="publishing-action">';
// $html .= '<input type="submit" accesskey="p" tabindex="5" value="custom_action" class="button-primary" id="custom" name="custom_action" value="submitted">';
//try this button code first.
//$html .= '<button onclick="rt_project_updated_save_dosomething( $post_id );" accesskey="p" tabindex="5" class="button-primary" id="custom" name="custom_action">SEND WITH FUNCTION</button>';
//try this one next but don't use both.
$html .= '</div>';
$html .= '</div>';
echo $html;
}
add_action( 'post_submitbox_misc_actions', 'rt_custom_save_action' );
function rt_project_updated_save_dosomething( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// If this is just a revision, don't do anything.
if ( wp_is_post_revision( $post_id ) )
return;
//PUT SOMETHING HERE THAT YOU WANT TO HAPPEN
}
add_action( 'save_post', 'rt_project_updated_save_dosomething' ); //if you change the custom post type above, you have to change it here too (save_post_CUSTOMPOSTNAME)