: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$headerEnd = $( '.wrap h1, .wrap h2' ).first();
$notice = $( '#local-storage-notice' )
.insertAfter( $headerEnd )
.addClass( 'notice-warning' );
if ( $newerAutosaveNotice.length ) {
// If there is a "server" autosave notice, hide it.
// The data in the session storage is either the same or newer.
$newerAutosaveNotice.slideUp( 150, function() {
$notice.slideDown( 150 );
$notice.slideDown( 200 );
$notice.find( '.restore-backup' ).on( 'click.autosave-local', function() {
$notice.fadeTo( 250, 0, function() {
* Restores the current title, content and excerpt from postData.
* @param {Object} postData The object containing all post data.
* @return {boolean} True if the post is restored.
function restorePost( postData ) {
// Set the last saved data.
lastCompareString = getCompareString( postData );
if ( $( '#title' ).val() !== postData.post_title ) {
$( '#title' ).trigger( 'focus' ).val( postData.post_title || '' );
$( '#excerpt' ).val( postData.excerpt || '' );
if ( editor && ! editor.isHidden() && typeof switchEditors !== 'undefined' ) {
if ( editor.settings.wpautop && postData.content ) {
postData.content = switchEditors.wpautop( postData.content );
// Make sure there's an undo level in the editor.
editor.undoManager.transact( function() {
editor.setContent( postData.content || '' );
// Make sure the Text editor is selected.
$( '#content-html' ).trigger( 'click' );
$( '#content' ).trigger( 'focus' );
// Using document.execCommand() will let the user undo.
document.execCommand( 'selectAll' );
document.execCommand( 'insertText', false, postData.content || '' );
blog_id = typeof window.autosaveL10n !== 'undefined' && window.autosaveL10n.blog_id;
* Check if the browser supports sessionStorage and it's not disabled,
* then initialize and run checkPost().
* Don't run if the post type supports neither 'editor' (textarea#content) nor 'excerpt'.
if ( checkStorage() && blog_id && ( $('#content').length || $('#excerpt').length ) ) {
getSavedPostData: getSavedPostData,
* Auto saves the post on the server.
* tempBlockSave: tempBlockSave,
* triggerSave: triggerSave,
* postChanged: postChanged,
* } The object all functions for autosave.
function autosaveServer() {
var _blockSave, _blockSaveTimer, previousCompareString, lastCompareString,
* Blocks saving for the next 10 seconds.
function tempBlockSave() {
window.clearTimeout( _blockSaveTimer );
_blockSaveTimer = window.setTimeout( function() {
* Sets isSuspended to true.
* Sets isSuspended to false.
* Triggers the autosave with the post data.
* @param {Object} data The post data.
function response( data ) {
lastCompareString = previousCompareString;
previousCompareString = '';
$document.trigger( 'after-autosave', [data] );
// No longer an auto-draft.
$( '#auto_draft' ).val('');
* Resets the timing and tells heartbeat to connect now.
wp.heartbeat.connectNow();
* Checks if the post content in the textarea has changed since page load.
* This also happens when TinyMCE is active and editor.save() is triggered by
* wp.autosave.getPostData().
* @return {boolean} True if the post has been changed.
// If there are TinyMCE instances, loop through them.
window.tinymce.each( [ 'content', 'excerpt' ], function( field ) {
var editor = window.tinymce.get( field );
if ( ! editor || editor.isHidden() ) {
if ( ( $( '#' + field ).val() || '' ) !== initialCompareData[ field ] ) {
} else if ( editor.isDirty() ) {
if ( ( $( '#title' ).val() || '' ) !== initialCompareData.post_title ) {
return getCompareString() !== initialCompareString;
* Checks if the post can be saved or not.
* If the post hasn't changed or it cannot be updated,
* because the autosave is blocked or suspended, the function returns false.
* @return {Object} Returns the post data.
var postData, compareString;
// window.autosave() used for back-compat.
if ( isSuspended || _blockSave || ! window.autosave() ) {
if ( ( new Date() ).getTime() < nextRun ) {
postData = getPostData();
compareString = getCompareString( postData );
if ( typeof lastCompareString === 'undefined' ) {
lastCompareString = initialCompareString;
if ( compareString === lastCompareString ) {
previousCompareString = compareString;
$document.trigger( 'wpcountwords', [ postData.content ] )
.trigger( 'before-autosave', [ postData ] );
postData._wpnonce = $( '#_wpnonce' ).val() || '';
* Sets the next run, based on the autosave interval.
nextRun = ( new Date() ).getTime() + ( autosaveL10n.autosaveInterval * 1000 ) || 60000;
* Sets the autosaveData on the autosave heartbeat.
}).on( 'heartbeat-send.autosave', function( event, data ) {
var autosaveData = save();
data.wp_autosave = autosaveData;
* Triggers the autosave of the post with the autosave data on the autosave
}).on( 'heartbeat-tick.autosave', function( event, data ) {
if ( data.wp_autosave ) {
response( data.wp_autosave );
* Disables buttons and throws a notice when the connection is lost.
}).on( 'heartbeat-connection-lost.autosave', function( event, error, status ) {
// When connection is lost, keep user from submitting changes.
if ( 'timeout' === error || 603 === status ) {
var $notice = $('#lost-connection-notice');
if ( ! wp.autosave.local.hasStorage ) {
$notice.find('.hide-if-no-sessionstorage').hide();
* Enables buttons when the connection is restored.
}).on( 'heartbeat-connection-restored.autosave', function() {
$('#lost-connection-notice').hide();
tempBlockSave: tempBlockSave,
triggerSave: triggerSave,
postChanged: postChanged,
* Sets the autosave time out.
* Wait for TinyMCE to initialize plus 1 second. for any external css to finish loading,
* then save to the textarea before setting initialCompareString.
* This avoids any insignificant differences between the initial textarea content and the content
* extracted from the editor.
// Set the initial compare string in case TinyMCE is not used or not loaded first.
}).on( 'tinymce-editor-init.autosave', function( event, editor ) {
// Reset the initialCompare data after the TinyMCE instances have been initialized.
if ( 'content' === editor.id || 'excerpt' === editor.id ) {
window.setTimeout( function() {
getPostData: getPostData,
getCompareString: getCompareString,
disableButtons: disableButtons,
enableButtons: enableButtons,
window.wp = window.wp || {};
window.wp.autosave = autosave();