• Resolved Henry Wright

    (@henrywright)


    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/

Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Author Ella Van Durpe

    (@ellatrix)

    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

    (@henrywright)

    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

    (@henrywright)

    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

    (@ellatrix)

    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

    (@henrywright)

    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

    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

    (@henrywright)

    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

    (@ellatrix)

    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

    (@henrywright)

    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

    (@henrywright)

    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

    (@ellatrix)

    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

    (@henrywright)

    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

    (@ellatrix)

    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

    (@henrywright)

    Great, looks like a solution then! Nice and consistent with how it is done in core too.

    Thread Starter Henry Wright

    (@henrywright)

    Would you keep permalink/edit/ as the endpoint? or would you have permalink/new/?

    Plugin Author Ella Van Durpe

    (@ellatrix)

    example.com/?p=#&edit

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

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