: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
function editPermalink() {
var i, slug_value, slug_label,
real_slug = $('#post_name'),
revert_slug = real_slug.val(),
permalink = $( '#sample-permalink' ),
permalinkOrig = permalink.html(),
permalinkInner = $( '#sample-permalink a' ).html(),
buttons = $('#edit-slug-buttons'),
buttonsOrig = buttons.html(),
full = $('#editable-post-name-full');
// Deal with Twemoji in the post-name.
full.find( 'img' ).replaceWith( function() { return this.alt; } );
permalink.html( permalinkInner );
// Save current content to revert to when cancelling.
$el = $( '#editable-post-name' );
'<button type="button" class="save button button-small">' + __( 'OK' ) + '</button> ' +
'<button type="button" class="cancel button-link">' + __( 'Cancel' ) + '</button>'
// Save permalink changes.
buttons.children( '.save' ).on( 'click', function() {
var new_slug = $el.children( 'input' ).val();
if ( new_slug == $('#editable-post-name-full').text() ) {
buttons.children('.cancel').trigger( 'click' );
action: 'sample-permalink',
new_title: $('#title').val(),
samplepermalinknonce: $('#samplepermalinknonce').val()
var box = $('#edit-slug-box');
if (box.hasClass('hidden')) {
box.fadeIn('fast', function () {
box.removeClass('hidden');
buttons.html(buttonsOrig);
permalink.html(permalinkOrig);
$( '.edit-slug' ).trigger( 'focus' );
wp.a11y.speak( __( 'Permalink saved' ) );
// Cancel editing of permalink.
buttons.children( '.cancel' ).on( 'click', function() {
$('#view-post-btn').show();
buttons.html(buttonsOrig);
permalink.html(permalinkOrig);
real_slug.val(revert_slug);
$( '.edit-slug' ).trigger( 'focus' );
// If more than 1/4th of 'full' is '%', make it empty.
for ( i = 0; i < full.length; ++i ) {
if ( '%' == full.charAt(i) )
slug_value = ( c > full.length / 4 ) ? '' : full;
slug_label = __( 'URL Slug' );
'<label for="new-post-slug" class="screen-reader-text">' + slug_label + '</label>' +
'<input type="text" id="new-post-slug" value="' + slug_value + '" autocomplete="off" spellcheck="false" />'
).children( 'input' ).on( 'keydown', function( e ) {
// On [Enter], just save the new slug, don't save the post.
buttons.children( '.save' ).trigger( 'click' );
// On [Esc] cancel the editing.
buttons.children( '.cancel' ).trigger( 'click' );
} ).on( 'keyup', function() {
real_slug.val( this.value );
$( '#titlediv' ).on( 'click', '.edit-slug', function() {
* Adds screen reader text to the title label when needed.
* Use the 'screen-reader-text' class to emulate a placeholder attribute
* and hide the label when entering a value.
* @param {string} id Optional. HTML ID to add the screen reader helper text to.
window.wptitlehint = function( id ) {
var title = $( '#' + id ), titleprompt = $( '#' + id + '-prompt-text' );
if ( '' === title.val() ) {
titleprompt.removeClass( 'screen-reader-text' );
title.on( 'input', function() {
if ( '' === this.value ) {
titleprompt.removeClass( 'screen-reader-text' );
titleprompt.addClass( 'screen-reader-text' );
// Resize the WYSIWYG and plain text editors.
$handle = $('#post-status-info'),
$postdivrich = $('#postdivrich');
// If there are no textareas or we are on a touch device, we can't do anything.
if ( ! $textarea.length || 'ontouchstart' in window ) {
// Hide the resize handle.
$('#content-resize-handle').hide();
* @param {Object} event Event containing details about the drag.
function dragging( event ) {
if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) {
editor.theme.resizeTo( null, offset + event.pageY );
$textarea.height( Math.max( 50, offset + event.pageY ) );
* When the dragging stopped make sure we return focus and do a confidence check on the height.
var height, toolbarHeight;
if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) {
toolbarHeight = parseInt( $( '#wp-content-editor-container .mce-toolbar-grp' ).height(), 10 );
if ( toolbarHeight < 10 || toolbarHeight > 200 ) {
height = parseInt( $('#content_ifr').css('height'), 10 ) + toolbarHeight - 28;
$textarea.trigger( 'focus' );
height = parseInt( $textarea.css('height'), 10 );
$document.off( '.wp-editor-resize' );
// Confidence check: normalize height to stay within acceptable ranges.
if ( height && height > 50 && height < 5000 ) {
setUserSetting( 'ed_size', height );
$handle.on( 'mousedown.wp-editor-resize', function( event ) {
if ( typeof tinymce !== 'undefined' ) {
editor = tinymce.get('content');
if ( editor && ! editor.isHidden() ) {
offset = $('#content_ifr').height() - event.pageY;
offset = $textarea.height() - event.pageY;
$textarea.trigger( 'blur' );
$document.on( 'mousemove.wp-editor-resize', dragging )
.on( 'mouseup.wp-editor-resize mouseleave.wp-editor-resize', endDrag );
}).on( 'mouseup.wp-editor-resize', endDrag );
// TinyMCE specific handling of Post Format changes to reflect in the editor.
if ( typeof tinymce !== 'undefined' ) {
// When changing post formats, change the editor body class.
$( '#post-formats-select input.post-format' ).on( 'change.set-editor-class', function() {
var editor, body, format = this.id;
if ( format && $( this ).prop( 'checked' ) && ( editor = tinymce.get( 'content' ) ) ) {
body.className = body.className.replace( /\bpost-format-[^ ]+/, '' );
editor.dom.addClass( body, format == 'post-format-0' ? 'post-format-standard' : format );
$( document ).trigger( 'editor-classchange' );
// When changing page template, change the editor body class.
$( '#page_template' ).on( 'change.set-editor-class', function() {
var editor, body, pageTemplate = $( this ).val() || '';
pageTemplate = pageTemplate.substr( pageTemplate.lastIndexOf( '/' ) + 1, pageTemplate.length )
if ( pageTemplate && ( editor = tinymce.get( 'content' ) ) ) {
body.className = body.className.replace( /\bpage-template-[^ ]+/, '' );
editor.dom.addClass( body, 'page-template-' + pageTemplate );
$( document ).trigger( 'editor-classchange' );
// Save on pressing [Ctrl]/[Command] + [S] in the Text editor.
$textarea.on( 'keydown.wp-autosave', function( event ) {
if ( event.which === 83 ) {
( isMac && ( ! event.metaKey || event.ctrlKey ) ) ||
( ! isMac && ! event.ctrlKey )
wp.autosave && wp.autosave.server.triggerSave();
// If the last status was auto-draft and the save is triggered, edit the current URL.
if ( $( '#original_post_status' ).val() === 'auto-draft' && window.history.replaceState ) {
$( '#publish' ).on( 'click', function() {
location = window.location.href;
location += ( location.indexOf( '?' ) !== -1 ) ? '&' : '?';
location += 'wp-post-new-reload=true';
window.history.replaceState( null, null, location );
* Copies the attachment URL in the Edit Media page to the clipboard.
* @param {MouseEvent} event A click event.
copyAttachmentURLClipboard.on( 'success', function( event ) {
var triggerElement = $( event.trigger ),
successElement = $( '.success', triggerElement.closest( '.copy-to-clipboard-container' ) );
// Clear the selection and move focus back to the trigger.
// Show success visual feedback.
clearTimeout( copyAttachmentURLSuccessTimeout );
successElement.removeClass( 'hidden' );
// Hide success visual feedback after 3 seconds since last success.
copyAttachmentURLSuccessTimeout = setTimeout( function() {
successElement.addClass( 'hidden' );
// Handle success audible feedback.
wp.a11y.speak( __( 'The file URL has been copied to your clipboard' ) );
* TinyMCE word count display
( function( $, counter ) {
var $content = $( '#content' ),
$count = $( '#wp-word-count' ).find( '.word-count' ),
* Get the word count from TinyMCE and display it
if ( ! contentEditor || contentEditor.isHidden() ) {
text = contentEditor.getContent( { format: 'raw' } );
count = counter.count( text );
if ( count !== prevCount ) {
* Bind the word count update triggers.
* When a node change in the main TinyMCE editor has been triggered.
* When a key has been released in the plain text content editor.
$( document ).on( 'tinymce-editor-init', function( event, editor ) {
if ( editor.id !== 'content' ) {
editor.on( 'nodechange keyup', _.debounce( update, 1000 ) );
$content.on( 'input keyup', _.debounce( update, 1000 ) );
} )( jQuery, new wp.utils.WordCounter() );