Title: Create draft and redirect
Last modified: August 21, 2016

---

# Create draft and redirect

 *  Resolved [Henry Wright](https://wordpress.org/support/users/henrywright/)
 * (@henrywright)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/)
 * I noticed you have ‘Create draft and redirect’ on the to do list in the Tasks
   document.
 * Would this be the process?
 * 1. User clicks on create new button in the toolbar
    2. A draft post is created
   in it’s most very basic form (just an ID is assigned – no title, no content, 
   no tags…) 3. A redirect takes the user to the post edit page. For example, if
   permalinks were set to `post_id` then the URL would be `example.com/post_id/edit/`
   4. The Front-end Editor does it’s stuff. 5. Click save to publish
 * To me this seems the most obvious way of creating new posts. If this is the intended
   approach, I have a question – how would you handle drafts being discarded during
   step 4? For example, if the user decides not to proceed with the update and closes
   the browser window you’d be left with lots of empty posts. Just trying to think
   of a way around this?
 * [http://wordpress.org/plugins/wp-front-end-editor/](http://wordpress.org/plugins/wp-front-end-editor/)

Viewing 15 replies - 1 through 15 (of 19 total)

1 [2](https://wordpress.org/support/topic/create-draft-and-redirect/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/create-draft-and-redirect/page/2/?output_format=md)

 *  Plugin Author [Ella Van Durpe](https://wordpress.org/support/users/ellatrix/)
 * (@ellatrix)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/#post-4468517)
 * That’s about the way it’s going to go. Discarding drafts will probably work similarly
   to discarding auto-drafts in the back-end.
 *  Thread Starter [Henry Wright](https://wordpress.org/support/users/henrywright/)
 * (@henrywright)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/#post-4468520)
 * That sounds pretty cool.
 * I’ve been trying to create a mock up of the process but found you can’t create
   a new post with empty `post_title` or `post_content`.
 * e.g. this doesn’t seem to be possible:
 *     ```
       $post_data = array(
           'post_title'    => '',
           'post_type'     => 'post',
           'post_content'  => '',
           'post_status'   => 'draft',
           'post_author'   => $user_id
       );
   
       // insert the post into the database
       $post_id = wp_insert_post( $post_data );
       ```
   
 * Pre-filling title and content with a placeholder (perhaps a non-breaking space)
   doesn’t seem a clean approach to me? What are your thoughts on this?
 *  Thread Starter [Henry Wright](https://wordpress.org/support/users/henrywright/)
 * (@henrywright)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/#post-4468527)
 * I wonder if using `'post_status' => 'auto-draft',` would work?
 * That would allow for a post with empty title and content. The problem is it wouldn’t
   give the URL that is needed for editing e.g. `example.com/post_id/edit/` because
   visiting an auto-draft post results in a 404.
 *  Plugin Author [Ella Van Durpe](https://wordpress.org/support/users/ellatrix/)
 * (@ellatrix)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/#post-4468546)
 * No, you need to fill in either post_title or post_content (or both). You could
   put a placeholder in the title, and then remove it again. But I’m not sure if
   it’s not better to leave it. No, we can’t use auto-draft, unless we change that
   in core. I’ll need to think more about this… 🙂
 *  Thread Starter [Henry Wright](https://wordpress.org/support/users/henrywright/)
 * (@henrywright)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/#post-4468549)
 * > You could put a placeholder in the title, and then remove it again. But I’m
   > not sure if it’s not better to leave it.
 * I’m not sure if there is any benefit to leaving in the placeholder?
 * You could add a placeholder then remove it like this:
 *     ```
       function custom_mask_empty( $value ) {
           if ( empty( $value ) ) {
               return ' ';
           }
           return $value;
       }
       add_filter( 'pre_post_title', 'custom_mask_empty' );
       add_filter( 'pre_post_content', 'custom_mask_empty' );
       ```
   
 *     ```
       function custom_unmask_empty( $data ) {
   
           if ( ' ' == $data['post_title'] ) {
               $data['post_title'] = '';
           }
   
           if ( ' ' == $data['post_content'] ) {
               $data['post_content'] = '';
           }
   
           return $data;
       }
       add_filter( 'wp_insert_post_data', 'custom_unmask_empty' );
       ```
   
 * Modified slighty from accepted answer here:
    [http://wordpress.stackexchange.com/questions/28021/how-to-publish-a-post-with-empty-title-and-empty-content](http://wordpress.stackexchange.com/questions/28021/how-to-publish-a-post-with-empty-title-and-empty-content)
 * One issue that arrives as a result of this is when viewing the `/edit/` page –
   your editable title and content regions will be blank. This could be resolved
   by adding placeholder text (similar to how you would with an empty text form 
   input e.g. `placeholder="Title here"`)
 *  Thread Starter [Henry Wright](https://wordpress.org/support/users/henrywright/)
 * (@henrywright)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/#post-4468554)
 * Then all that is outstanding to do is discard the draft post if the user decides
   not to save (e.g. closes the browser window or navigates away from the page).
   I’m trying to figure out how to discard ‘draft’ posts. How does WordPress discard‘
   auto-draft’ posts? Perhaps the same process can be applied to discarding ‘draft’
   posts.
 *  Plugin Author [Ella Van Durpe](https://wordpress.org/support/users/ellatrix/)
 * (@ellatrix)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/#post-4468556)
 * I think it schedules an action, not entirely sure.
    Sure you could work around
   it like that, but it’s not a ‘clean’ solution. A lot of the things in the plugin
   aren’t ‘clean’ solutions though, there’s just no other way to do it.
 *  Thread Starter [Henry Wright](https://wordpress.org/support/users/henrywright/)
 * (@henrywright)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/#post-4468557)
 * > Sure you could work around it like that, but it’s not a ‘clean’ solution
 * Noted! I’ll have a think of what else can be done.
 * > I think it schedules an action, not entirely sure.
 * I’ll have a think about this too…
 *  Thread Starter [Henry Wright](https://wordpress.org/support/users/henrywright/)
 * (@henrywright)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/#post-4468572)
 * Of course an alternative approach would be to click on ‘create new post’ in the
   toolbar and have the user redirected to page `example.com/new/` where each of
   the contributable regions are displayed. Obviously these would be empty regions
   as no post (draft, auto-draft or publish) has yet been created.
 * Once these regions are completed the user will be free to save (which then creates
   the post).
 *  Plugin Author [Ella Van Durpe](https://wordpress.org/support/users/ellatrix/)
 * (@ellatrix)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/#post-4468731)
 * The problem with example.com/new/ is that you need to insert a post first anyway,
   you need it for some things like uploading media.
 * I’m going to use auto-draft. I’ll hack it so it works on the front-end.
 *  Thread Starter [Henry Wright](https://wordpress.org/support/users/henrywright/)
 * (@henrywright)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/#post-4468732)
 * > The problem with example.com/new/ is that you need to insert a post first anyway,
   > you need it for some things like uploading media.
 * Humm, didn’t think of that. Auto-draft posts will give you the all-needed post
   ID. Would you need a scheduled action to remove all unused auto-drafts? I’m thinking
   for housekeeping?
 *  Plugin Author [Ella Van Durpe](https://wordpress.org/support/users/ellatrix/)
 * (@ellatrix)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/#post-4468733)
 * Auto-drafts are not visible at all in the back-end, and they’re automatically
   removed by core after a while (7 days I think).
 *  Thread Starter [Henry Wright](https://wordpress.org/support/users/henrywright/)
 * (@henrywright)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/#post-4468734)
 * Great, looks like a solution then! Nice and consistent with how it is done in
   core too.
 *  Thread Starter [Henry Wright](https://wordpress.org/support/users/henrywright/)
 * (@henrywright)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/#post-4468735)
 * Would you keep _permalink_/edit/ as the endpoint? or would you have _permalink_/
   new/?
 *  Plugin Author [Ella Van Durpe](https://wordpress.org/support/users/ellatrix/)
 * (@ellatrix)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/#post-4468736)
 * example.com/?p=#&edit

Viewing 15 replies - 1 through 15 (of 19 total)

1 [2](https://wordpress.org/support/topic/create-draft-and-redirect/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/create-draft-and-redirect/page/2/?output_format=md)

The topic ‘Create draft and redirect’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-front-end-editor_ffffff.svg)
 * [Front-end Editor for WordPress](https://wordpress.org/plugins/wp-front-end-editor/)
 * [Support Threads](https://wordpress.org/support/plugin/wp-front-end-editor/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-front-end-editor/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-front-end-editor/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-front-end-editor/reviews/)

 * 19 replies
 * 2 participants
 * Last reply from: [Ella Van Durpe](https://wordpress.org/support/users/ellatrix/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/create-draft-and-redirect/page/2/#post-4468750)
 * Status: resolved