Title: Need help refining added code in functions.php
Last modified: August 6, 2019

---

# Need help refining added code in functions.php

 *  Resolved [mlaurel](https://wordpress.org/support/users/mlaurel/)
 * (@mlaurel)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/need-help-refining-added-code-in-functions-php/)
 * Hey all,
 * I need an extra set of eyes to help me fix code that automatically sets any post
   to private so only the admin can publish any post draft.
 * The problem I’m running into is that every time a user clicks on the “All Posts”,
   coming from anywhere in the dashboard, an “auto draft” post is created.
 * Here is the code in question (found online & modified for admin only posting):
 *     ```
       //Force posts of custom type to be private
       //…but first make sure they are not 'trash' otherwise it is impossible to trash a post
   
       function force_type_private($post)
       {
           if (($post['post_type'] == 'post')&&(!current_user_can('administrator')))
           {
               if ($post['post_status'] != 'trash')
       		$post['post_status'] = 'private';
           }
   
           return $post;
       }
       add_filter('wp_insert_post_data', 'force_type_private');
       ```
   
 * How can I stop this from adding drafts?
 * Per original code “first make sure they are not ‘trash’ otherwise it is impossible
   to trash a post”.
 * I’m not 100% sure but I think it may be causing a problem?
 * Any ideas are welcome.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/need-help-refining-added-code-in-functions-php/#post-11806574)
 * I placed you code on my site and it did not result in any auto draft posts. Since
   you mentioned it, I did see some older auto draft posts on my site. I think they
   were a result of visiting a new post screen and abandoning it without entering
   anything. In any case, I don’t see how your code could be causing auto drafts
   to be created. It does not even run until a post is already being saved, and 
   it certainly is not adding any additional posts of any sort.
 *  Thread Starter [mlaurel](https://wordpress.org/support/users/mlaurel/)
 * (@mlaurel)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/need-help-refining-added-code-in-functions-php/#post-11809183)
 * Thanks for the help.
 * Not sure what was going on (it was probably as you explained). Ended up double
   checking code again & ran more tests. It is working properly.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/need-help-refining-added-code-in-functions-php/#post-11809905)
 * You’re welcome. I blame caching for anything 🙂 At least it works now.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Need help refining added code in functions.php’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [6 years, 9 months ago](https://wordpress.org/support/topic/need-help-refining-added-code-in-functions-php/#post-11809905)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
