: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
changed = wp.autosave.server.postChanged();
changed = ( ! editor.isHidden() && editor.isDirty() );
// The return string is needed for browser compat.
// See https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event.
return __( 'The changes you made will be lost if you navigate away from this page.' );
}).on( 'pagehide.edit-post', function( event ) {
* Unload is triggered (by hand) on removing the Thickbox iframe.
* Make sure we process only the main document unload.
if ( event.target && event.target.nodeName != '#document' ) {
var postID = $('#post_ID').val();
var postLock = $('#active_post_lock').val();
if ( ! postID || ! postLock ) {
action: 'wp-remove-post-lock',
_wpnonce: $('#_wpnonce').val(),
active_post_lock: postLock
if ( window.FormData && window.navigator.sendBeacon ) {
var formData = new window.FormData();
$.each( data, function( key, value ) {
formData.append( key, value );
if ( window.navigator.sendBeacon( ajaxurl, formData ) ) {
// Fall back to a synchronous POST request.
// See https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon
if ( $('#tagsdiv-post_tag').length ) {
window.tagBox && window.tagBox.init();
$('.meta-box-sortables').children('div.postbox').each(function(){
if ( this.id.indexOf('tagsdiv-') === 0 ) {
window.tagBox && window.tagBox.init();
$('.categorydiv').each( function(){
var this_id = $(this).attr('id'), catAddBefore, catAddAfter, taxonomyParts, taxonomy, settingName;
taxonomyParts = this_id.split('-');
taxonomy = taxonomyParts.join('-');
settingName = taxonomy + '_tab';
if ( taxonomy == 'category' ) {
// @todo Move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js.
$('a', '#' + taxonomy + '-tabs').on( 'click', function( e ) {
var t = $(this).attr('href');
$(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
$('#' + taxonomy + '-tabs').siblings('.tabs-panel').hide();
if ( '#' + taxonomy + '-all' == t ) {
deleteUserSetting( settingName );
setUserSetting( settingName, 'pop' );
if ( getUserSetting( settingName ) )
$('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').trigger( 'click' );
// Add category button controls.
$('#new' + taxonomy).one( 'focus', function() {
$( this ).val( '' ).removeClass( 'form-input-tip' );
// On [Enter] submit the taxonomy.
$('#new' + taxonomy).on( 'keypress', function(event){
if( 13 === event.keyCode ) {
$('#' + taxonomy + '-add-submit').trigger( 'click' );
// After submitting a new taxonomy, re-focus the input field.
$('#' + taxonomy + '-add-submit').on( 'click', function() {
$('#new' + taxonomy).trigger( 'focus' );
* Before adding a new taxonomy, disable submit button.
* @param {Object} s Taxonomy object which will be added.
catAddBefore = function( s ) {
if ( !$('#new'+taxonomy).val() ) {
s.data += '&' + $( ':checked', '#'+taxonomy+'checklist' ).serialize();
$( '#' + taxonomy + '-add-submit' ).prop( 'disabled', true );
* Re-enable submit button after a taxonomy has been added.
* Re-enable submit button.
* If the taxonomy has a parent place the taxonomy underneath the parent.
* @param {Object} r Response.
* @param {Object} s Taxonomy data.
catAddAfter = function( r, s ) {
var sup, drop = $('#new'+taxonomy+'_parent');
$( '#' + taxonomy + '-add-submit' ).prop( 'disabled', false );
if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) {
$('#' + taxonomy + 'checklist').wpList({
response: taxonomy + '-ajax-response',
// Add new taxonomy button toggles input form visibility.
$('#' + taxonomy + '-add-toggle').on( 'click', function( e ) {
$('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' );
$('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').trigger( 'click' );
$('#new'+taxonomy).trigger( 'focus' );
// Sync checked items between "All {taxonomy}" and "Most used" lists.
$('#' + taxonomy + 'checklist, #' + taxonomy + 'checklist-pop').on(
'li.popular-category > label input[type="checkbox"]',
var t = $(this), c = t.is(':checked'), id = t.val();
if ( id && t.parents('#taxonomy-'+taxonomy).length )
$('#in-' + taxonomy + '-' + id + ', #in-popular-' + taxonomy + '-' + id).prop( 'checked', c );
// Custom Fields postbox.
if ( $('#postcustom').length ) {
$( '#the-list' ).wpList( {
* Add current post_ID to request to fetch custom fields
* @param {Object} s Request object.
* @return {Object} Data modified with post_ID attached.
addBefore: function( s ) {
s.data += '&post_id=' + $('#post_ID').val();
* Show the listing of custom fields after fetching.
$('table#list-table').show();
* Publish Post box (#submitdiv)
if ( $('#submitdiv').length ) {
stamp = $('#timestamp').html();
visibility = $('#post-visibility-display').html();
* When the visibility of a post changes sub-options should be shown or hidden.
updateVisibility = function() {
// Show sticky for public posts.
if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) {
$('#sticky').prop('checked', false);
$('#sticky-span').hide();
$('#sticky-span').show();
// Show password input field for password protected post.
if ( $postVisibilitySelect.find('input:radio:checked').val() != 'password' ) {
$('#password-span').hide();
$('#password-span').show();
* Make sure all labels represent the current settings.
* @return {boolean} False when an invalid timestamp has been selected, otherwise True.
updateText = function() {
if ( ! $timestampdiv.length )
var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'),
optPublish = $('option[value="publish"]', postStatus), aa = $('#aa').val(),
mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val();
attemptedDate = new Date( aa, mm - 1, jj, hh, mn );
$('#hidden_mm').val() -1,
// Catch unexpected date problems.
attemptedDate.getFullYear() != aa ||
(1 + attemptedDate.getMonth()) != mm ||
attemptedDate.getDate() != jj ||
attemptedDate.getMinutes() != mn
$timestampdiv.find('.timestamp-wrap').addClass('form-invalid');
$timestampdiv.find('.timestamp-wrap').removeClass('form-invalid');
// Determine what the publish should be depending on the date and post status.
if ( attemptedDate > currentDate ) {
publishOn = __( 'Schedule for:' );
$('#publish').val( _x( 'Schedule', 'post action/button label' ) );
} else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) {
publishOn = __( 'Publish on:' );
$('#publish').val( __( 'Publish' ) );
publishOn = __( 'Published on:' );
$('#publish').val( __( 'Update' ) );
// If the date is the same, set it to trigger update events.
if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) {
// Re-set to the current value.
$('#timestamp').html(stamp);
'\n' + publishOn + ' <b>' +
// translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute.
__( '%1$s %2$s, %3$s at %4$s:%5$s' )
.replace( '%1$s', $( 'option[value="' + mm + '"]', '#mm' ).attr( 'data-text' ) )
.replace( '%2$s', parseInt( jj, 10 ) )
.replace( '%4$s', ( '00' + hh ).slice( -2 ) )
.replace( '%5$s', ( '00' + mn ).slice( -2 ) ) +
// Add "privately published" to post status when applies.
if ( $postVisibilitySelect.find('input:radio:checked').val() == 'private' ) {
$('#publish').val( __( 'Update' ) );
if ( 0 === optPublish.length ) {
postStatus.append('<option value="publish">' + __( 'Privately Published' ) + '</option>');
optPublish.html( __( 'Privately Published' ) );
$('option[value="publish"]', postStatus).prop('selected', true);
$('#misc-publishing-actions .edit-post-status').hide();
if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) {
if ( optPublish.length ) {
postStatus.val($('#hidden_post_status').val());
optPublish.html( __( 'Published' ) );
if ( postStatus.is(':hidden') )
$('#misc-publishing-actions .edit-post-status').show();
// Update "Status:" to currently selected status.
$('#post-status-display').text(
// Remove any potential tags from post status text.
wp.sanitize.stripTagsAndEncodeText( $('option:selected', postStatus).text() )
// Show or hide the "Save Draft" button.
$('option:selected', postStatus).val() == 'private' ||
$('option:selected', postStatus).val() == 'publish'
if ( $('option:selected', postStatus).val() == 'pending' ) {
$('#save-post').show().val( __( 'Save as Pending' ) );
$('#save-post').show().val( __( 'Save Draft' ) );
// Show the visibility options and hide the toggle button when opened.
$( '#visibility .edit-visibility').on( 'click', function( e ) {
if ( $postVisibilitySelect.is(':hidden') ) {
$postVisibilitySelect.slideDown( 'fast', function() {
$postVisibilitySelect.find( 'input[type="radio"]' ).first().trigger( 'focus' );
// Cancel visibility selection area and hide it from view.
$postVisibilitySelect.find('.cancel-post-visibility').on( 'click', function( event ) {
$postVisibilitySelect.slideUp('fast');
$('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true);
$('#post_password').val($('#hidden-post-password').val());
$('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked'));
$('#post-visibility-display').html(visibility);
$('#visibility .edit-visibility').show().trigger( 'focus' );
// Set the selected visibility as current.
$postVisibilitySelect.find('.save-post-visibility').on( 'click', function( event ) { // Crazyhorse branch - multiple OK cancels.
var visibilityLabel = '', selectedVisibility = $postVisibilitySelect.find('input:radio:checked').val();
$postVisibilitySelect.slideUp('fast');
$('#visibility .edit-visibility').show().trigger( 'focus' );
if ( 'public' !== selectedVisibility ) {
$('#sticky').prop('checked', false);
switch ( selectedVisibility ) {
visibilityLabel = $( '#sticky' ).prop( 'checked' ) ? __( 'Public, Sticky' ) : __( 'Public' );
visibilityLabel = __( 'Private' );
visibilityLabel = __( 'Password Protected' );
$('#post-visibility-display').text( visibilityLabel );
// When the selection changes, update labels.
$postVisibilitySelect.find('input:radio').on( 'change', function() {
// Edit publish time click.
$timestampdiv.siblings('a.edit-timestamp').on( 'click', function( event ) {
if ( $timestampdiv.is( ':hidden' ) ) {
$timestampdiv.slideDown( 'fast', function() {
$( 'input, select', $timestampdiv.find( '.timestamp-wrap' ) ).first().trigger( 'focus' );
// Cancel editing the publish time and hide the settings.
$timestampdiv.find('.cancel-timestamp').on( 'click', function( event ) {
$timestampdiv.slideUp('fast').siblings('a.edit-timestamp').show().trigger( 'focus' );
$('#mm').val($('#hidden_mm').val());
$('#jj').val($('#hidden_jj').val());
$('#aa').val($('#hidden_aa').val());
$('#hh').val($('#hidden_hh').val());
$('#mn').val($('#hidden_mn').val());
// Save the changed timestamp.
$timestampdiv.find('.save-timestamp').on( 'click', function( event ) { // Crazyhorse branch - multiple OK cancels.
$timestampdiv.slideUp('fast');
$timestampdiv.siblings('a.edit-timestamp').show().trigger( 'focus' );
// Cancel submit when an invalid timestamp has been selected.
$('#post').on( 'submit', function( event ) {
wp.autosave.enableButtons();
$( '#publishing-action .spinner' ).removeClass( 'is-active' );
// Post Status edit click.
$postStatusSelect.siblings('a.edit-post-status').on( 'click', function( event ) {
if ( $postStatusSelect.is( ':hidden' ) ) {
$postStatusSelect.slideDown( 'fast', function() {
$postStatusSelect.find('select').trigger( 'focus' );
// Save the Post Status changes and hide the options.
$postStatusSelect.find('.save-post-status').on( 'click', function( event ) {
$postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().trigger( 'focus' );
// Cancel Post Status editing and hide the options.
$postStatusSelect.find('.cancel-post-status').on( 'click', function( event ) {
$postStatusSelect.slideUp( 'fast' ).siblings( 'a.edit-post-status' ).show().trigger( 'focus' );
$('#post_status').val( $('#hidden_post_status').val() );
* Handle the editing of the post_name. Create the required HTML elements and
* update the changes via Ajax.