Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have similar problem as described in How to trap "Publish" button to check for meta box validation? Answer there is to hook into save_post and change post type. How can I do it? I try to use wp_transition_post_status but it doesn't work for me...

function myHook( $post_ID, $post )
{

    wp_transition_post_status('pending', $post->post_status, $post );

}

add_action( 'save_post', 'myHook', 10, 2 );

Edit: I have clear wordpress installation without any plugins, additional code and similar

share|improve this question
1  
Please add your relevant code. "Try" is very vague... –  kaiser Jan 5 '13 at 18:21

1 Answer 1

You get the full post object as a second parameter on save_post. Use it to change the status just like the following code.

add_action( 'save_post', 'wpse_78351_status', 10, 2 );

function wpse_78351_status( $post_ID, $post )
{
    remove_filter( current_filter(), __FUNCTION__ );

    if ( 'trash' !== $post->post_status ) //adjust the condition
    {
        $post->post_status = 'draft'; // use any post status
        wp_update_post( $post );
    }
}

See this answer for a list of post statuses.

share|improve this answer
    
Your code causes Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/localhost/htdocs/wordpress1/wp-includes/kses.php on line 1023 –  user1666774 Jan 5 '13 at 19:20
    
@SomeoneHere Indeed, sorry, fixed. See my update. :) –  toscho Jan 5 '13 at 19:24
    
I also found another fix: add remove_action( 'save_post', 'myHook'); before wp_update_post( $post ); and add_action( 'save_post', 'myHook', 10, 2 ); after It works :) Thank you a lot for help :) –  user1666774 Jan 5 '13 at 19:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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