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.
You can stop post revisions using
define('WP_POST_REVISIONS', false);
in wp-config.php or try below if it works.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 inclass-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