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.

My website is set up with pages as categories, meaning that if a user publishes without choosing a category, no one can see the post unless they know the specific address.

What do I need to hook into in order to check if a category is chosen after the "publish" button is pressed but before the post is published publicly?

share|improve this question
1  
    
Have you tried to build ontop of any of the solutions there? What worked? What didn't? –  soulseekah Mar 23 '12 at 14:14
    
Yes...those were the type of questions I was looking for - couldn't find them for some reason. –  fdsa Mar 23 '12 at 22:03

2 Answers 2

up vote 0 down vote accepted

Try

function wpse46583_save($post_id,$post) {
     // verify this is not an auto save routine. 
     if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;

     //You should check nonces and permissions here
      if ( !current_user_can( 'edit_page', $post_id )
           return;

     //Get category slugs associated with post
     $cats =get_the_category($post_id);

     if(empty($cats)){
        //No category assigned - do something here.
     }

     return;
}
add_action('save_post','wpse46583_save',10,2);
share|improve this answer
    
Thanks for your help. That's exactly what I was looking for. I used wp_die to pause the publish process. –  fdsa Mar 23 '12 at 22:03

You can hook wp_insert_post_data to get the data that is about to be inserted into the database. What you do with it from there is your call, but you will at least have access to it. Keep in mind that this hook is done before the new post data is inserted into the DB, so you won't be able to interact with the post using a lot of the functions you're used to.

share|improve this answer

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.