I have tied an action into a status change, which works on the backend. However,using a frontend button for updating post status does not trigger the action(http://wordpress.stackexchange.com/questions/17794/publish-pending-article-from-front-end-with-a-button), but it does update the post status.
So I have this button for updating a post from 'draft to rejected'
function show_reject_button(){
global $post;
echo '<form name="front_end_reject" method="POST" action="">
<input type="hidden" name="pid2" id="pid2" value="'.$post->ID.'">
<input type="hidden" name="FE_REJECT" id="FE_REJECT" value="FE_REJECT">
<input type="image" src="https://---.com/images/logo1/sreject.png" alt="reject" title="Reject this reservation" style="background: none !important; border: none !important;">
</form>';
}
function change_post_status($post_id,$status){
$current_post = get_post( $post_id, 'ARRAY_A' );
$current_post['post_status'] = $status;
wp_update_post($current_post);
}
if (isset($_POST['FE_REJECT']) && $_POST['FE_REJECT'] == 'FE_REJECT'){
if (isset($_POST['pid2']) && !empty($_POST['pid2'])){
change_post_status((int)$_POST['pid2'],'rejected');
}
}
I'd like to thank Bainternet for that code.
I have the action of changing a post from draft to rejected tied into a function for changing some post meta.
add_action ('draft_to_rejected', 'void_payment_hold' );
function void_payment_hold() {
global $post;
$type = get_post_type( $post->ID );
if( $type == 'tribe_events' ){
$order_id = get_post_meta($post->ID, 'order', TRUE);
$current_hold = get_post_meta($order_id, 'hold', TRUE);
$released_amount = get_post_meta($post->ID, 'amount', TRUE);
$remaining_hold = $current_hold - $released_amount;
__update_post_meta($order_id, 'hold', $remaining_hold);
}
}
When I execute this on the backend it works, but when I update the post status with the button the function does not execute. Does anyone know why this may be happening?
Thanks for your time