1

Setting:

three open Tabs in browser:

Tab 1: Admin edit post

Tab 2: Frontend view of that post in "editing mode"

Tab 3: Frontend view in "non-editing" mode (default request)

I edit the post on Tab 2 (frontend editing) and save it via AJAX (via wp_update_post). When I refresh this Tab, or Tab 3, I can see the changes.

But when I refresh Tab 1 (WP Backend edit-posts page), I see the old content in the editor, but a new revision was added. When I hard-refresh that page, it works as expected. (This might be very confusing to editors)

So why does it work only on hard refresh, but not on normal refresh? Is there any kind of caching active? (couldn't find anything in the codex)

Simlified Ajax save action:

function save_page() {
    $postID = (int)$_POST['postID'];
    $content = $_POST['content'];

    $my_post = array(
        'ID'           => $postID,
        'post_content' => $content
    );

    wp_update_post( $my_post );

    exit;
}

Edit:

In the Backend, on normal refresh:

    global $post;
    echo "<pre>";
    print_r($post->post_content);
    echo "</pre>";

prints a different result content than shown in the editor.

4
  • 1
    Whats your problem? Mar 1, 2014 at 11:34
  • That if a editor has the post open in frontend-editing mode, and the back end edit post page, he will get confused. He edits the post on frontend, saves, refreshes the backend and won't see the changes (although the changes are saved).
    – xsonic
    Mar 1, 2014 at 11:46
  • When you say front end, are you talking about a published post or a preview? If you're trying to implement frontend editing you may want to look at the frontend editing plugin being worked on by WP Core
    – Tom J Nowell
    Mar 1, 2014 at 12:25
  • Thank you. This Plugin has the same issue, but I noticed, that this issue is only present in FF, so I found the solution.
    – xsonic
    Mar 1, 2014 at 13:19

2 Answers 2

0

You can stop post revisions using define('WP_POST_REVISIONS', false); in wp-config.php or try below if it works.

function save_page() {
    exit( wp_update_post( array(
        'ID'           => absint( esc_attr( $_POST['postID'] ) ),
        'post_type'    =>'your post type'
        'post_content' => esc_attr( $_POST['content'] )
    ) ) );
}
3
  • Thanks a lot, but had no success. Same result. I see the changes in the backend only on hard refresh, or when I switch pages.
    – xsonic
    Mar 1, 2014 at 11:53
  • Rajeev, please only input escaped data into the database. You're opening serious security holes else.
    – kaiser
    Mar 1, 2014 at 15:12
  • Is this really necessary? Doesn't the data get sanitized in wp_insert_post() as in this question: wordpress.stackexchange.com/questions/9515/…
    – xsonic
    Mar 2, 2014 at 8:54
0

Problem was Textarea autocompleting in Firefox (this problem was only present in FF, as I noticed)

For now, I have added autocomplete="off" to the textarea created in class-wp-editor.php

Adding it via JS didn't work (most likely because FF placed the text into the textarea before my JS was fired)

EDIT:

Within WP 3.9 an option will be added to set autocomplete="off" for the editor instance: https://core.trac.wordpress.org/ticket/27251

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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