diff --git a/Gruntfile.js b/Gruntfile.js index 956a551e59725..927a3a5f16f40 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -258,6 +258,8 @@ module.exports = function(grunt) { [ WORKING_DIR + 'wp-admin/js/inline-edit-post.js' ]: [ './src/js/_enqueues/admin/inline-edit-post.js' ], [ WORKING_DIR + 'wp-admin/js/inline-edit-tax.js' ]: [ './src/js/_enqueues/admin/inline-edit-tax.js' ], [ WORKING_DIR + 'wp-admin/js/language-chooser.js' ]: [ './src/js/_enqueues/lib/language-chooser.js' ], + [ WORKING_DIR + 'wp-admin/js/link-manager.js' ]: [ './src/js/_enqueues/admin/link-manager.js' ], + [ WORKING_DIR + 'wp-admin/js/media-events.js' ]: [ './src/js/_enqueues/admin/media-events.js' ], [ WORKING_DIR + 'wp-admin/js/link.js' ]: [ './src/js/_enqueues/admin/link.js' ], [ WORKING_DIR + 'wp-admin/js/media-gallery.js' ]: [ './src/js/_enqueues/deprecated/media-gallery.js' ], [ WORKING_DIR + 'wp-admin/js/media-upload.js' ]: [ './src/js/_enqueues/admin/media-upload.js' ], @@ -269,10 +271,12 @@ module.exports = function(grunt) { [ WORKING_DIR + 'wp-admin/js/postbox.js' ]: [ './src/js/_enqueues/admin/postbox.js' ], [ WORKING_DIR + 'wp-admin/js/revisions.js' ]: [ './src/js/_enqueues/wp/revisions.js' ], [ WORKING_DIR + 'wp-admin/js/set-post-thumbnail.js' ]: [ './src/js/_enqueues/admin/set-post-thumbnail.js' ], + [ WORKING_DIR + 'wp-admin/js/setup-config.js' ]: [ './src/js/_enqueues/admin/setup-config.js' ], [ WORKING_DIR + 'wp-admin/js/svg-painter.js' ]: [ './src/js/_enqueues/wp/svg-painter.js' ], [ WORKING_DIR + 'wp-admin/js/tags-box.js' ]: [ './src/js/_enqueues/admin/tags-box.js' ], [ WORKING_DIR + 'wp-admin/js/tags-suggest.js' ]: [ './src/js/_enqueues/admin/tags-suggest.js' ], [ WORKING_DIR + 'wp-admin/js/tags.js' ]: [ './src/js/_enqueues/admin/tags.js' ], + [ WORKING_DIR + 'wp-admin/js/themes-list.js' ]: [ './src/js/_enqueues/admin/themes-list.js' ], [ WORKING_DIR + 'wp-admin/js/site-health.js' ]: [ './src/js/_enqueues/admin/site-health.js' ], [ WORKING_DIR + 'wp-admin/js/privacy-tools.js' ]: [ './src/js/_enqueues/admin/privacy-tools.js' ], [ WORKING_DIR + 'wp-admin/js/theme-plugin-editor.js' ]: [ './src/js/_enqueues/wp/theme-plugin-editor.js' ], @@ -310,6 +314,7 @@ module.exports = function(grunt) { [ WORKING_DIR + 'wp-includes/js/heartbeat.js' ]: [ './src/js/_enqueues/wp/heartbeat.js' ], [ WORKING_DIR + 'wp-includes/js/mce-view.js' ]: [ './src/js/_enqueues/wp/mce-view.js' ], [ WORKING_DIR + 'wp-includes/js/media-editor.js' ]: [ './src/js/_enqueues/wp/media/editor.js' ], + [ WORKING_DIR + 'wp-includes/js/metabox-events.js' ]: [ './src/js/_enqueues/lib/metabox-events.js' ], [ WORKING_DIR + 'wp-includes/js/quicktags.js' ]: [ './src/js/_enqueues/lib/quicktags.js' ], [ WORKING_DIR + 'wp-includes/js/shortcode.js' ]: [ './src/js/_enqueues/wp/shortcode.js' ], [ WORKING_DIR + 'wp-includes/js/utils.js' ]: [ './src/js/_enqueues/lib/cookies.js' ], @@ -819,6 +824,8 @@ module.exports = function(grunt) { 'src/wp-admin/js/inline-edit-tax.js': 'src/js/_enqueues/admin/inline-edit-tax.js', 'src/wp-admin/js/language-chooser.js': 'src/js/_enqueues/lib/language-chooser.js', 'src/wp-admin/js/link.js': 'src/js/_enqueues/admin/link.js', + 'src/wp-admin/js/link-manager.js': 'src/js/_enqueues/admin/link-manager.js', + 'src/wp-admin/js/media-events.js': 'src/js/_enqueues/admin/media-events.js', 'src/wp-admin/js/media-gallery.js': 'src/js/_enqueues/deprecated/media-gallery.js', 'src/wp-admin/js/media-upload.js': 'src/js/_enqueues/admin/media-upload.js', 'src/wp-admin/js/media.js': 'src/js/_enqueues/admin/media.js', @@ -829,10 +836,12 @@ module.exports = function(grunt) { 'src/wp-admin/js/postbox.js': 'src/js/_enqueues/admin/postbox.js', 'src/wp-admin/js/revisions.js': 'src/js/_enqueues/wp/revisions.js', 'src/wp-admin/js/set-post-thumbnail.js': 'src/js/_enqueues/admin/set-post-thumbnail.js', + 'src/wp-admin/js/setup-config.js': 'src/js/_enqueues/admin/setup-config.js', 'src/wp-admin/js/svg-painter.js': 'src/js/_enqueues/wp/svg-painter.js', 'src/wp-admin/js/tags-box.js': 'src/js/_enqueues/admin/tags-box.js', 'src/wp-admin/js/tags-suggest.js': 'src/js/_enqueues/admin/tags-suggest.js', 'src/wp-admin/js/tags.js': 'src/js/_enqueues/admin/tags.js', + 'src/wp-admin/js/themes-list.js': 'src/js/_enqueues/admin/themes-list.js', 'src/wp-admin/js/theme-plugin-editor.js': 'src/js/_enqueues/wp/theme-plugin-editor.js', 'src/wp-admin/js/theme.js': 'src/js/_enqueues/wp/theme.js', 'src/wp-admin/js/updates.js': 'src/js/_enqueues/wp/updates.js', @@ -864,6 +873,7 @@ module.exports = function(grunt) { 'src/wp-includes/js/heartbeat.js': 'src/js/_enqueues/wp/heartbeat.js', 'src/wp-includes/js/mce-view.js': 'src/js/_enqueues/wp/mce-view.js', 'src/wp-includes/js/media-editor.js': 'src/js/_enqueues/wp/media/editor.js', + 'src/wp-includes/js/metabox-events.js': 'src/js/_enqueues/lib/metabox-events.js', 'src/wp-includes/js/quicktags.js': 'src/js/_enqueues/lib/quicktags.js', 'src/wp-includes/js/shortcode.js': 'src/js/_enqueues/wp/shortcode.js', 'src/wp-includes/js/utils.js': 'src/js/_enqueues/lib/cookies.js', diff --git a/package-lock.json b/package-lock.json index 7e4873697e0c9..9da7d90514a7e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6363,7 +6363,7 @@ }, "bl": { "version": "1.2.2", - "resolved": "http://registry.npmjs.org/bl/-/bl-1.2.2.tgz", + "resolved": "https://registry.npmjs.org/bl/-/bl-1.2.2.tgz", "integrity": "sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==", "dev": true, "optional": true, @@ -6554,7 +6554,7 @@ }, "browserify-aes": { "version": "1.2.0", - "resolved": "http://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", + "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", "dev": true, "requires": { @@ -9211,7 +9211,7 @@ }, "duplexer": { "version": "0.1.1", - "resolved": "http://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", + "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.1.tgz", "integrity": "sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=", "dev": true }, diff --git a/src/js/_enqueues/admin/common.js b/src/js/_enqueues/admin/common.js index 3832bcac2c3df..33eb0de8ee57f 100644 --- a/src/js/_enqueues/admin/common.js +++ b/src/js/_enqueues/admin/common.js @@ -1939,6 +1939,12 @@ $document.ready( function() { // Toggle the Show Details button expanded state. $( this ).attr( 'aria-expanded', $progressDiv.is( ':visible' ) ); }); + + // Event handler for "Go back" link (if present) + $( '.go-back' ).click( function () { + window.history.go( -1 ); + return false; + } ); }); /** diff --git a/src/js/_enqueues/admin/custom-header.js b/src/js/_enqueues/admin/custom-header.js index b1414a439eed9..a81275f7ef9fa 100644 --- a/src/js/_enqueues/admin/custom-header.js +++ b/src/js/_enqueues/admin/custom-header.js @@ -27,6 +27,13 @@ }); }); + var name = document.getElementById( 'name' ); + if ( name !== null ) { + name.addEventListener( 'click', function ( event ) { + event.preventDefault(); + } ); + } + /** * Opens the 'choose from library' frame and creates it if it doesn't exist. * diff --git a/src/js/_enqueues/admin/edit-comments.js b/src/js/_enqueues/admin/edit-comments.js index 5afe2f793fb19..a78f8ab26433d 100644 --- a/src/js/_enqueues/admin/edit-comments.js +++ b/src/js/_enqueues/admin/edit-comments.js @@ -813,6 +813,13 @@ window.commentReply = { commentReply.close(); }); + $('#the-comment-list').on('click', '.open-comment-reply', function () { + commentReply.open( + this.dataset.commentId, + this.dataset.postId + ); + }); + this.comments_listing = $('#comments-form > input[name="comment_status"]').val() || ''; }, diff --git a/src/js/_enqueues/admin/link-manager.js b/src/js/_enqueues/admin/link-manager.js new file mode 100644 index 0000000000000..3b928f8d99b75 --- /dev/null +++ b/src/js/_enqueues/admin/link-manager.js @@ -0,0 +1,24 @@ +/** + * @output wp-admin/js/link-manager.js + */ +/** + * Link manager event handler + * + * @since 5.6.0 + * + * @param {Object} document The document object. + * + * @return {void} + */ + /* global confirm */ +( function ( document ) { + document.addEventListener( 'DOMContentLoaded', function () { + document.querySelectorAll( '.submitdelete-link' ).forEach( function ( item ) { + item.addEventListener( 'click', function ( event ) { + if ( ! confirm( item.dataset.prompt ) ) { + event.preventDefault(); + } + } ); + } ); + } ); +} )( document ); diff --git a/src/js/_enqueues/admin/link.js b/src/js/_enqueues/admin/link.js index 02698e5eea6eb..fccd028eecc0b 100644 --- a/src/js/_enqueues/admin/link.js +++ b/src/js/_enqueues/admin/link.js @@ -2,7 +2,7 @@ * @output wp-admin/js/link.js */ -/* global postboxes, deleteUserSetting, setUserSetting, getUserSetting */ +/* global confirm, postboxes, deleteUserSetting, setUserSetting, getUserSetting */ jQuery(document).ready( function($) { @@ -43,6 +43,11 @@ jQuery(document).ready( function($) { */ $('#link-category-add-submit').click( function() { newCat.focus(); } ); + // Adds event handler that prompts the user with confirmation dialog + $('.submitdelete-link' ).click( function () { + return confirm( this.dataset.prompt ); + } ); + /** * Synchronize category checkboxes. * diff --git a/src/js/_enqueues/admin/media-events.js b/src/js/_enqueues/admin/media-events.js new file mode 100644 index 0000000000000..e06901d92689b --- /dev/null +++ b/src/js/_enqueues/admin/media-events.js @@ -0,0 +1,118 @@ +/** + * @output wp-admin/js/media-events.js + */ +/** + * Admin media event handlers. + * + * @since 5.6.0 + * + * @requires image-edit + * @requires gallery + * @requires set-post-thumbnail + * + * @param {Object} document The document object. + * @param {Object} window The window object. + * + * @return {void} + */ + + /* global addExtImage, imageEdit, wpgallery, WPSetAsThumbnail */ +( function ( document, window ) { + document.addEventListener( 'DOMContentLoaded', function () { + document + .querySelectorAll( '.imgedit-open-btn' ) + .forEach( function ( item ) { + item.addEventListener( 'click', function () { + imageEdit.open( + parseInt( item.dataset.postId, 10 ), + item.dataset.nonce + ); + } ); + } ); + + document.querySelectorAll( '.del-link' ).forEach( function ( item ) { + item.addEventListener( 'click', function ( event ) { + document.getElementById( + 'del_attachment_' + item.dataset.attachmentId + ).style.display = 'block'; + event.preventDefault(); + } ); + } ); + + document + .querySelectorAll( '.button.cancel-del-link' ) + .forEach( function ( item ) { + item.addEventListener( 'click', function ( event ) { + this.parentNode.style.display = 'none'; + event.preventDefault(); + } ); + } ); + + document + .querySelectorAll( '.wp-post-thumbnail' ) + .forEach( function ( item ) { + item.addEventListener( 'click', function ( event ) { + WPSetAsThumbnail( + item.dataset.attachmentId, + item.dataset.ajaxNonce + ); + event.preventDefault(); + } ); + } ); + + var cancelAsyncUpload = document.getElementById( + 'cancel-async-upload' + ); + if ( cancelAsyncUpload !== null ) { + cancelAsyncUpload.addEventListener( 'click', function ( event ) { + try { + window.top.tb_remove(); + } catch ( e ) {} + event.preventDefault(); + } ); + } + + document + .querySelectorAll( '.button.gallery-actions' ) + .forEach( function ( item ) { + item.addEventListener( 'mousedown', function () { + wpgallery.update(); + } ); + } ); + + var srcInput = document.getElementById( 'src' ); + if ( srcInput !== null ) { + // wp_media_insert_url_form was called. + srcInput.addEventListener( 'blur', function () { + addExtImage.getImageData(); + } ); + + document + .querySelectorAll( 'td.field > input[name="align"]' ) + .forEach( function ( item ) { + item.addEventListener( 'click', function ( event ) { + addExtImage.align = 'align' + event.target.value; + } ); + } ); + + document + .getElementById( 'image-only-none' ) + .addEventListener( 'click', function () { + document.forms[ 0 ].url.value = null; + } ); + + document + .getElementById( 'image-only-link' ) + .addEventListener( 'click', function () { + document.forms[ 0 ].url.value = + document.forms[ 0 ].src.value; + } ); + + document + .getElementById( 'go_button' ) + .addEventListener( 'click', function () { + addExtImage.insert(); + } ); + } + } ); +} )( document, window ); diff --git a/src/js/_enqueues/admin/media.js b/src/js/_enqueues/admin/media.js index c992b5d3a4d25..5fb8f34e6e6a6 100644 --- a/src/js/_enqueues/admin/media.js +++ b/src/js/_enqueues/admin/media.js @@ -171,6 +171,19 @@ } }); + // Binds the click event to the 'Delete Permanently' button. + $( '.warn-media-delete' ).click( function () { + return showNotice.warn(); + }); + + // Binds the click event to the 'Attach' button. + $( '.attach-to-existing' ).each( function () { + $( this ).click( function ( event ) { + findPosts.open( 'media[]', this.dataset.postId ); + event.preventDefault(); + }); + }); + // Binds the click event to the search button. $( '#find-posts-search' ).click( findPosts.send ); diff --git a/src/js/_enqueues/admin/post.js b/src/js/_enqueues/admin/post.js index 17445df17eb1a..18caf7ade0706 100644 --- a/src/js/_enqueues/admin/post.js +++ b/src/js/_enqueues/admin/post.js @@ -4,7 +4,7 @@ * @output wp-admin/js/post.js */ - /* global ajaxurl, wpAjax, postboxes, pagenow, tinymce, alert, deleteUserSetting, ClipboardJS */ + /* global ajaxurl, wpAjax, postboxes, pagenow, prompt, tinymce, alert, deleteUserSetting, ClipboardJS */ /* global theList:true, theExtraList:true, getUserSetting, setUserSetting, commentReply, commentsBox */ /* global WPSetThumbnailHTML, wptitlehint */ @@ -1267,6 +1267,11 @@ jQuery(document).ready( function($) { // Handle success audible feedback. wp.a11y.speak( __( 'The file URL has been copied to your clipboard' ) ); } ); + + // Handle "Get Shortlink" button click event. + $( '#get-shortlink' ).click( function () { + prompt( 'URL:', $( '#shortlink' ).val() ); + } ); } ); /** diff --git a/src/js/_enqueues/admin/setup-config.js b/src/js/_enqueues/admin/setup-config.js new file mode 100644 index 0000000000000..8299c483b34ec --- /dev/null +++ b/src/js/_enqueues/admin/setup-config.js @@ -0,0 +1,23 @@ +/** + * @output wp-admin/js/setup-config.js + */ +/** + * Vanilla JavaScript 'Go back' event handler + * + * @since 5.6.0 + * + * @param {Object} document The document object. + * @param {Object} window The window object. + * + * @return {void} + */ +( function ( document, window ) { + document.addEventListener( 'DOMContentLoaded', function () { + document.querySelectorAll( '.go-back' ).forEach( function ( item ) { + item.addEventListener( 'click', function ( event ) { + window.history.go( -1 ); + event.preventDefault(); + } ); + } ); + } ); +} )( document, window ); diff --git a/src/js/_enqueues/admin/themes-list.js b/src/js/_enqueues/admin/themes-list.js new file mode 100644 index 0000000000000..9bf2550c8790b --- /dev/null +++ b/src/js/_enqueues/admin/themes-list.js @@ -0,0 +1,24 @@ +/** + * @output wp-admin/js/themes-list.js + */ +/** + * Link manager event handler + * + * @since 5.6.0 + * + * @param {Object} document The document object. + * + * @return {void} + */ + /* global confirm */ + ( function ( document ) { + document.addEventListener( 'DOMContentLoaded', function () { + document.querySelectorAll( '.submitdelete-theme' ).forEach( function ( item ) { + item.addEventListener( 'click', function ( event ) { + if ( ! confirm( item.dataset.prompt ) ) { + event.preventDefault(); + } + } ); + } ); + } ); +} )( document ); diff --git a/src/js/_enqueues/lib/image-edit.js b/src/js/_enqueues/lib/image-edit.js index 340966df6d4e5..14999a93ad327 100644 --- a/src/js/_enqueues/lib/image-edit.js +++ b/src/js/_enqueues/lib/image-edit.js @@ -138,9 +138,157 @@ } }); + t.initEventHandlers(); $( document ).on( 'image-editor-ui-ready', this.focusManager ); }, + /** + * Attaches event handlers to buttons and input elements. + * + * @since 5.6 + * + * @memberof imageEdit + * + * @return {void} + */ + initEventHandlers: function () { + $( 'img.image-preview' ).on( 'load', function () { + imageEdit.imgLoaded( parseInt( this.dataset.postId, 10 ) ); + } ); + + $( '.imgedit-crop' ).on( 'click', function () { + imageEdit.handleCropToolClick( + parseInt( this.dataset.postId, 10 ), + this.dataset.nonce, + this + ); + } ); + + $( '.imgedit-rleft' ).on( 'click', function () { + imageEdit.rotate( + 90, + parseInt( this.dataset.postId, 10 ), + this.dataset.nonce, + this + ); + } ); + + $( '.imgedit-rright' ).on( 'click', function () { + imageEdit.rotate( + -90, + parseInt( this.dataset.postId, 10 ), + this.dataset.nonce, + this + ); + } ); + + $( '.imgedit-flipv' ).on( 'click', function () { + imageEdit.flip( + 1, + parseInt( this.dataset.postId, 10 ), + this.dataset.nonce, + this + ); + } ); + + $( '.imgedit-fliph' ).on( 'click', function () { + imageEdit.flip( + 2, + parseInt( this.dataset.postId, 10 ), + this.dataset.nonce, + this + ); + } ); + + $( '.imgedit-undo' ).on( 'click', function () { + imageEdit.undo( + parseInt( this.dataset.postId, 10 ), + this.dataset.nonce, + this + ); + } ); + + $( '.imgedit-redo' ).on( 'click', function () { + imageEdit.redo( + parseInt( this.dataset.postId, 10 ), + this.dataset.nonce, + this + ); + } ); + + $( '.imgedit-cancel-btn' ).on( 'click', function () { + imageEdit.close( this.dataset.postId, 1 ); + } ); + + $( '.imgedit-submit-btn' ).on( 'click', function () { + imageEdit.save( + parseInt( this.dataset.postId, 10 ), + this.dataset.nonce + ); + } ); + + $( 'button.imgedit-help-toggle, #imgedit-restore-original' ).on( + 'click', + function () { + imageEdit.toggleHelp( this ); + } + ); + + $( '.imgedit-scale-width' ).on( 'keyup blur', function () { + imageEdit.scaleChanged( this.dataset.postId, 1, this ); + } ); + + $( '.imgedit-scale-height' ).on( 'keyup blur', function () { + imageEdit.scaleChanged( this.dataset.postId, 0, this ); + } ); + + $( '#imgedit-scale-button' ).on( 'click', function () { + imageEdit.action( + parseInt( this.dataset.postId, 10 ), + this.dataset.nonce, + 'scale' + ); + } ); + + $( '#imgedit-restore-button' ).on( 'click', function () { + imageEdit.action( + parseInt( this.dataset.postId, 10 ), + this.dataset.nonce, + 'restore' + ); + } ); + + $( '.imgedit-crop-width' ).on( 'keyup blur', function () { + imageEdit.setRatioSelection( + parseInt( this.dataset.postId, 10 ), + 0, + this + ); + } ); + + $( '.imgedit-crop-height' ).on( 'keyup blur', function () { + imageEdit.setRatioSelection( + parseInt( this.dataset.postId, 10 ), + 1, + this + ); + } ); + + $( '.imgedit-sel-width' ).on( 'keyup blur', function () { + imageEdit.setNumSelection( + parseInt( this.dataset.postId, 10 ), + this + ); + } ); + + $( '.imgedit-sel-height' ).on( 'keyup blur', function () { + imageEdit.setNumSelection( + parseInt( this.dataset.postId, 10 ), + this + ); + } ); + }, + /** * Toggles the wait/load icon in the editor. * diff --git a/src/js/_enqueues/lib/metabox-events.js b/src/js/_enqueues/lib/metabox-events.js new file mode 100644 index 0000000000000..837f98d4b06c8 --- /dev/null +++ b/src/js/_enqueues/lib/metabox-events.js @@ -0,0 +1,61 @@ +/** + * @output wp-includes/js/metabox-events.js + */ +/** + * Metabox related event handlers. + * + * @since 5.6.0 + * + * @requires common + * @requires edit-comments + * @requires post + * + * @param {Object} document The document object. + * @param {Object} window The window object. + * + * @return {void} + */ + + /* global commentsBox, commentReply, showNotice */ +( function ( document, window ) { + document.addEventListener( 'DOMContentLoaded', function () { + document + .querySelectorAll( 'form.metabox-location' ) + .forEach( function ( item ) { + item.addEventListener( 'submit', function ( event ) { + event.preventDefault(); + } ); + } ); + + document + .querySelectorAll( '.permanent-deletion' ) + .forEach( function ( item ) { + item.addEventListener( 'click', function ( event ) { + if ( ! showNotice.warn() ) { + event.preventDefault(); + } + } ); + } ); + + document + .querySelectorAll( '#add-new-comment > button' ) + .forEach( function ( item ) { + item.addEventListener( 'click', function () { + if ( window.commentReply ) { + commentReply.addcomment( + parseInt( item.dataset.postId, 10 ) + ); + } + } ); + } ); + + document + .querySelectorAll( '#commentstatusdiv' ) + .forEach( function ( item ) { + item.addEventListener( 'click', function ( event ) { + commentsBox.load( item.dataset.total ); + event.preventDefault(); + } ); + } ); + } ); +} )( document, window ); diff --git a/src/js/_enqueues/vendor/thickbox/thickbox.js b/src/js/_enqueues/vendor/thickbox/thickbox.js index 391fd4186e268..52e7cdd5386b7 100644 --- a/src/js/_enqueues/vendor/thickbox/thickbox.js +++ b/src/js/_enqueues/vendor/thickbox/thickbox.js @@ -204,11 +204,14 @@ function tb_show(caption, url, imageGroup) {//function called when the user clic urlNoQuery = url.split('TB_'); jQuery("#TB_iframeContent").remove(); if(params['modal'] != "true"){//iframe no modal - jQuery("#TB_window").append("
"+caption+"
"); + jQuery("#TB_window").append("
"+caption+"
"); }else{//iframe modal jQuery("#TB_overlay").unbind(); - jQuery("#TB_window").append(""); + jQuery("#TB_window").append(""); } + jQuery("#TB_iframeContent").load(function() { + tb_showIframe(); + }); }else{// not an iframe, ajax if(jQuery("#TB_window").css("visibility") != "visible"){ if(params['modal'] != "true"){//ajax no modal diff --git a/src/js/_enqueues/wp/customize/nav-menus.js b/src/js/_enqueues/wp/customize/nav-menus.js index 1ae1f3435cc2c..2a0c1b91b2939 100644 --- a/src/js/_enqueues/wp/customize/nav-menus.js +++ b/src/js/_enqueues/wp/customize/nav-menus.js @@ -776,7 +776,14 @@ help = panelMeta.find( '.customize-help-toggle' ), content = panelMeta.find( '.customize-panel-description' ), options = $( '#screen-options-wrap' ), - button = panelMeta.find( '.customize-screen-options-toggle' ); + button = panelMeta.find( '.customize-screen-options-toggle' ), + focusWidgets = $( '.focus-widgets' ); + + focusWidgets.click( function () { + api.panel( 'widgets' ).focus(); + return false; + } ); + button.on( 'click keydown', function( event ) { if ( api.utils.isKeydownButNotEnterEvent( event ) ) { return; diff --git a/src/js/_enqueues/wp/customize/widgets.js b/src/js/_enqueues/wp/customize/widgets.js index 990a3e19b525a..a0a3398391271 100644 --- a/src/js/_enqueues/wp/customize/widgets.js +++ b/src/js/_enqueues/wp/customize/widgets.js @@ -2281,10 +2281,15 @@ }; /** - * Initialize Edit Menu button in Nav Menu widget. + * Initialize 'Edit Menu' and 'Create some' buttons in Nav Menu widget. */ $( document ).on( 'widget-added', function( event, widgetContainer ) { - var parsedWidgetId, widgetControl, navMenuSelect, editMenuButton; + var parsedWidgetId, + widgetControl, + navMenuSelect, + editMenuButton, + focusNavMenus = $( '.focus-nav-menus' ); + parsedWidgetId = parseWidgetId( widgetContainer.find( '> .widget-inside > .form > .widget-id' ).val() ); if ( 'nav_menu' !== parsedWidgetId.id_base ) { return; @@ -2311,6 +2316,12 @@ focusConstructWithBreadcrumb( section, widgetControl ); } } ); + + // 'Create some' button is shown when there are no menus. Switches focus to nav_menus view. + focusNavMenus.click( function () { + api.panel( 'nav_menus' ).focus(); + return false; + } ); } ); /** diff --git a/src/js/_enqueues/wp/theme-plugin-editor.js b/src/js/_enqueues/wp/theme-plugin-editor.js index cffbc69637ed2..34bd73d29324f 100644 --- a/src/js/_enqueues/wp/theme-plugin-editor.js +++ b/src/js/_enqueues/wp/theme-plugin-editor.js @@ -81,6 +81,24 @@ wp.themePluginEditor = (function( $ ) { component.docsLookUpButton.prop( 'disabled', false ); } } ); + + component.docsLookUpButton.on( 'click', function () { + if ( '' != component.docsLookUpList.val() ) { + window.open( + 'https://api.wordpress.org/core/handbook/1.0/?function=' + + encodeURIComponent( component.docsLookUpList.val() ) + + '&locale=' + + encodeURIComponent( + window.themePluginEditorL10n.locale + ) + + '&version=' + + encodeURIComponent( + window.themePluginEditorL10n.wpVersion + ) + + '&redirect=true' + ); + } + } ); }; /** diff --git a/src/wp-activate.php b/src/wp-activate.php index 65a07d00b99fd..dc12ddadd0d75 100644 --- a/src/wp-activate.php +++ b/src/wp-activate.php @@ -212,9 +212,7 @@ function wpmu_activate_stylesheet() { ?> -
- + diff --git a/src/wp-admin/admin-header.php b/src/wp-admin/admin-header.php index 8eddb2b892143..ddca33b689abc 100644 --- a/src/wp-admin/admin-header.php +++ b/src/wp-admin/admin-header.php @@ -79,18 +79,17 @@ wp_enqueue_script( 'svg-painter' ); $admin_body_class = preg_replace( '/[^a-z0-9_-]+/i', '-', $hook_suffix ); -?> - -id . '", + typenow = "' . $current_screen->post_type . '", + adminpage = "' . $admin_body_class . '", + thousandsSeparator = "' . addslashes( $wp_locale->number_format['thousands_sep'] ) . '", + decimalPoint = "' . addslashes( $wp_locale->number_format['decimal_point'] ) . '", + isRtl = ' . ( (int) is_rtl() ) . ';'; + +wp_print_inline_script_tag( $js ); /** * Enqueue scripts for all admin pages. @@ -232,11 +231,10 @@ $admin_body_classes = ltrim( $admin_body_classes . ' ' . $admin_body_class ); ?> - - %s %s
%s', sprintf( - '', + '', __( 'Dismiss' ) ), sprintf( @@ -106,6 +106,14 @@ ), esc_html( $id->get_error_message() ) ); + $js = <<<'JS' +jQuery(document).ready(function () { + jQuery('#async-upload-dismiss').click(function () { + jQuery(this).parents('div.media-item').slideUp(200, function(){jQuery(this).remove();}); + }); +}); +JS; + wp_print_inline_script_tag( $js ); exit; } diff --git a/src/wp-admin/comment.php b/src/wp-admin/comment.php index ad11f3e05b388..d4373393d787f 100644 --- a/src/wp-admin/comment.php +++ b/src/wp-admin/comment.php @@ -75,7 +75,7 @@ require_once ABSPATH . 'wp-admin/admin-header.php'; if ( ! $comment ) { - comment_footer_die( __( 'Invalid comment ID.' ) . sprintf( ' ' . __( 'Go back' ) . '.', 'javascript:history.go(-1)' ) ); + comment_footer_die( __( 'Invalid comment ID.' ) . sprintf( ' ' . __( 'Go back' ) . '.' ) ); } if ( ! current_user_can( 'edit_comment', $comment_id ) ) { diff --git a/src/wp-admin/customize.php b/src/wp-admin/customize.php index 51335829f0a07..d39dc16f939ce 100644 --- a/src/wp-admin/customize.php +++ b/src/wp-admin/customize.php @@ -60,11 +60,11 @@ ); ob_start(); ?> - - <?php echo esc_html( $admin_title ); ?> + -var ajaxurl = , - pagenow = 'customize'; - +wp_print_inline_script_tag( 'var ajaxurl = ' . wp_json_encode( admin_url( 'admin-ajax.php', 'relative' ) ) . ', pagenow = "customize";' ); -ID ) !== $permalink ) { $sample_permalink_html .= '' . - ''; } @@ -735,8 +735,7 @@ } ?> -post_title ) : ?> - - +post_title ) { + wp_print_inline_script_tag( 'try{document.post.title.focus();}catch(e){}' ); +} diff --git a/src/wp-admin/edit-form-comment.php b/src/wp-admin/edit-form-comment.php index ef0818c510365..b49858c21117a 100644 --- a/src/wp-admin/edit-form-comment.php +++ b/src/wp-admin/edit-form-comment.php @@ -245,9 +245,7 @@ - - - - - - - - - inline_edit(); diff --git a/src/wp-admin/export.php b/src/wp-admin/export.php index a0c76a35b40ab..16543b242a9c0 100644 --- a/src/wp-admin/export.php +++ b/src/wp-admin/export.php @@ -23,8 +23,7 @@ * @since 3.5.0 */ function export_add_js() { - ?> - - '; + $return['head'] = wp_get_script_tag( array( 'src' => $script_src ) ); $return['sandbox'] = true; } diff --git a/src/wp-admin/includes/class-bulk-upgrader-skin.php b/src/wp-admin/includes/class-bulk-upgrader-skin.php index c5cbcd487e55a..e85f5a9a27636 100644 --- a/src/wp-admin/includes/class-bulk-upgrader-skin.php +++ b/src/wp-admin/includes/class-bulk-upgrader-skin.php @@ -105,7 +105,7 @@ public function error( $error ) { } $this->error = implode( ', ', $messages ); } - echo ''; + wp_print_inline_script_tag( 'jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();' ); } /** @@ -126,7 +126,7 @@ public function bulk_footer() { public function before( $title = '' ) { $this->in_loop = true; printf( '

' . $this->upgrader->strings['skin_before_update_header'] . '

', $title, $this->upgrader->update_current, $this->upgrader->update_count ); - echo ''; + wp_print_inline_script_tag( 'jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').css("display", "inline-block");' ); // This progress messages div gets moved via JavaScript when clicking on "Show details.". echo '

'; $this->flush_output(); @@ -144,7 +144,7 @@ public function after( $title = '' ) { echo '

' . sprintf( $this->upgrader->strings['skin_update_failed'], $title ) . '

'; } - echo ''; + wp_print_inline_script_tag( 'jQuery(\'#progress-' . esc_js( $this->upgrader->update_current ) . '\').show();' ); } if ( $this->result && ! is_wp_error( $this->result ) ) { if ( ! $this->error ) { @@ -154,7 +154,7 @@ public function after( $title = '' ) { '

'; } - echo ''; + wp_print_inline_script_tag( 'jQuery(\'.waiting-' . esc_js( $this->upgrader->update_current ) . '\').hide();' ); } $this->reset(); diff --git a/src/wp-admin/includes/class-custom-image-header.php b/src/wp-admin/includes/class-custom-image-header.php index 838ab4a33e286..43b95c05162b1 100644 --- a/src/wp-admin/includes/class-custom-image-header.php +++ b/src/wp-admin/includes/class-custom-image-header.php @@ -340,10 +340,9 @@ public function js_1() { $default_color = '#' . $default_color; } } - ?> - - - - -

onclick="return false;" href="" tabindex="-1">

+

href="" tabindex="-1">

>
diff --git a/src/wp-admin/includes/class-wp-internal-pointers.php b/src/wp-admin/includes/class-wp-internal-pointers.php index a17caf5521774..738a252077c18 100644 --- a/src/wp-admin/includes/class-wp-internal-pointers.php +++ b/src/wp-admin/includes/class-wp-internal-pointers.php @@ -116,35 +116,32 @@ private static function print_js( $pointer_id, $selector, $args ) { return; } - ?> - - ' . __( 'Edit' ) . ''; $actions['delete'] = sprintf( - '%s', + '%s', wp_nonce_url( "link.php?action=delete&link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ), /* translators: %s: Link name. */ - esc_js( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ), + esc_attr( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ), __( 'Delete' ) ); diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php index 0f0c26d087d55..3bdf69fa40ea0 100644 --- a/src/wp-admin/includes/class-wp-list-table.php +++ b/src/wp-admin/includes/class-wp-list-table.php @@ -1506,6 +1506,6 @@ public function _js_vars() { ), ); - printf( "\n", wp_json_encode( $args ) ); + wp_print_inline_script_tag( sprintf( 'list_args = %s;', wp_json_encode( $args ) ) ); } } diff --git a/src/wp-admin/includes/class-wp-media-list-table.php b/src/wp-admin/includes/class-wp-media-list-table.php index 031f306987456..2214fbfa581a0 100644 --- a/src/wp-admin/includes/class-wp-media-list-table.php +++ b/src/wp-admin/includes/class-wp-media-list-table.php @@ -548,7 +548,7 @@ public function column_parent( $post ) { if ( $user_can_edit ) { $title = _draft_or_post_title( $post->post_parent ); printf( - '
%s', + '
%s', $post->ID, /* translators: %s: Attachment title. */ esc_attr( sprintf( __( 'Attach “%s” to existing content' ), $title ) ), @@ -704,9 +704,9 @@ private function _get_row_actions( $post, $att_title ) { _x( 'Trash', 'verb' ) ); } else { - $delete_ays = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : ''; + $delete_ays = ! MEDIA_TRASH ? ' warn-media-delete' : ''; $actions['delete'] = sprintf( - '%s', + '%s', wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID ), $delete_ays, /* translators: %s: Attachment title. */ @@ -725,7 +725,7 @@ private function _get_row_actions( $post, $att_title ) { if ( current_user_can( 'edit_post', $post->ID ) ) { $actions['attach'] = sprintf( - '%s', + '%s', $post->ID, /* translators: %s: Attachment title. */ esc_attr( sprintf( __( 'Attach “%s” to existing content' ), $att_title ) ), @@ -761,9 +761,9 @@ private function _get_row_actions( $post, $att_title ) { ); } if ( $this->is_trash || ! EMPTY_TRASH_DAYS || ! MEDIA_TRASH ) { - $delete_ays = ( ! $this->is_trash && ! MEDIA_TRASH ) ? " onclick='return showNotice.warn();'" : ''; + $delete_ays = ( ! $this->is_trash && ! MEDIA_TRASH ) ? ' warn-media-delete' : ''; $actions['delete'] = sprintf( - '%s', + '%s', wp_nonce_url( "post.php?action=delete&post=$post->ID", 'delete-post_' . $post->ID ), $delete_ays, /* translators: %s: Attachment title. */ diff --git a/src/wp-admin/includes/class-wp-theme-install-list-table.php b/src/wp-admin/includes/class-wp-theme-install-list-table.php index f721f9473dcac..7b3094e357637 100644 --- a/src/wp-admin/includes/class-wp-theme-install-list-table.php +++ b/src/wp-admin/includes/class-wp-theme-install-list-table.php @@ -148,7 +148,19 @@ public function prepare_items() { $api = themes_api( 'query_themes', $args ); if ( is_wp_error( $api ) ) { - wp_die( $api->get_error_message() . '

' . __( 'Try Again' ) . '' ); + wp_die( $api->get_error_message() . '

' . __( 'Try Again' ) . '' ); + + $js = <<<'JS' +document.addEventListener( 'DOMContentLoaded', function () { + document + .getElementById( 'theme-try-again' ) + .addEventListener( 'click', function ( event ) { + document.location.reload(); + event.preventDefault(); + } ); +} ); +JS; + wp_print_inline_script_tag( $js ); } $this->items = $api->themes; diff --git a/src/wp-admin/includes/class-wp-themes-list-table.php b/src/wp-admin/includes/class-wp-themes-list-table.php index 095267c06dcbc..38564ca2e9a0a 100644 --- a/src/wp-admin/includes/class-wp-themes-list-table.php +++ b/src/wp-admin/includes/class-wp-themes-list-table.php @@ -225,11 +225,12 @@ public function display_rows() { } if ( ! is_multisite() && current_user_can( 'delete_themes' ) ) { + wp_enqueue_script( 'themes-list' ); $actions['delete'] = sprintf( - '%s', + '%s', wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet ), /* translators: %s: Theme name. */ - esc_js( sprintf( __( "You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete." ), $title ) ), + esc_attr( sprintf( __( "You are about to delete this theme '%s'\n 'Cancel' to stop, 'OK' to delete." ), $title ) ), __( 'Delete' ) ); } @@ -355,7 +356,7 @@ public function _js_vars( $extra_args = array() ) { $args = array_merge( $args, $extra_args ); } - printf( "\n", wp_json_encode( $args ) ); + wp_print_inline_script_tag( sprintf( 'var theme_list_args = %s;', wp_json_encode( $args ) ) ); parent::_js_vars(); } } diff --git a/src/wp-admin/includes/class-wp-upgrader-skin.php b/src/wp-admin/includes/class-wp-upgrader-skin.php index 06f10cdca3bb2..0cdcd154f15f7 100644 --- a/src/wp-admin/includes/class-wp-upgrader-skin.php +++ b/src/wp-admin/includes/class-wp-upgrader-skin.php @@ -227,19 +227,17 @@ protected function decrement_update_count( $type ) { } if ( defined( 'IFRAME_REQUEST' ) ) { - echo ''; + }'; + wp_print_inline_script_tag( $js ); } else { - echo ''; + })( window.wp );'; + wp_print_inline_script_tag( $js ); } } diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php index d63971c1a2ded..b47bc1d1b9b17 100644 --- a/src/wp-admin/includes/dashboard.php +++ b/src/wp-admin/includes/dashboard.php @@ -711,7 +711,7 @@ function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) { ); $actions['reply'] = sprintf( - '', + '', $comment->comment_ID, $comment->comment_post_ID, esc_attr__( 'Reply to this comment' ), diff --git a/src/wp-admin/includes/deprecated.php b/src/wp-admin/includes/deprecated.php index 40e7ff0dcfb1f..8feb5e37b99d5 100644 --- a/src/wp-admin/includes/deprecated.php +++ b/src/wp-admin/includes/deprecated.php @@ -1500,8 +1500,7 @@ function post_form_autocomplete_off() { * @deprecated 4.9.0 */ function options_permalink_add_js() { - ?> - -

- + - - + + ' . __( 'Image rotation is not supported by your web host.' ) . '

'; @@ -73,12 +73,12 @@ function wp_image_editor( $post_id, $msg = false ) { - - + +
- - + +
@@ -90,12 +90,12 @@ function wp_image_editor( $post_id, $msg = false ) {
- +
- - )" disabled="disabled" class="button button-primary imgedit-submit-btn" value="" /> + +
@@ -103,7 +103,7 @@ function wp_image_editor( $post_id, $msg = false ) {

- +

@@ -124,12 +124,12 @@ function wp_image_editor( $post_id, $msg = false ) {
- + - + ! -
, 'scale')" class="button button-primary" value="" />
+
@@ -141,7 +141,7 @@ function wp_image_editor( $post_id, $msg = false ) {
-

+

- , 'restore')" class="button button-primary" value="" /> + />
@@ -164,7 +164,7 @@ function wp_image_editor( $post_id, $msg = false ) {

- +

@@ -181,10 +181,10 @@ function wp_image_editor( $post_id, $msg = false ) {
- + - +
@@ -192,10 +192,10 @@ function wp_image_editor( $post_id, $msg = false ) {
- + - +
@@ -209,7 +209,7 @@ function wp_image_editor( $post_id, $msg = false ) {

- +

diff --git a/src/wp-admin/includes/media.php b/src/wp-admin/includes/media.php index 3650e2cb29e64..19cc9e8cae41f 100644 --- a/src/wp-admin/includes/media.php +++ b/src/wp-admin/includes/media.php @@ -268,12 +268,10 @@ function _cleanup_image_add_caption( $matches ) { * @param string $html */ function media_send_to_editor( $html ) { - ?> - - - - class="wp-core-ui no-js"> - - - - ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { + wp_enqueue_script( 'media-events' ); $nonce = wp_create_nonce( "image_editor-$post->ID" ); - $image_edit_button = " "; + $image_edit_button = " "; } $attachment_url = get_permalink( $attachment_id ); @@ -1723,12 +1716,13 @@ function get_media_item( $attachment_id, $args = null ) { if ( ! EMPTY_TRASH_DAYS ) { $delete = "" . __( 'Delete Permanently' ) . ''; } elseif ( ! MEDIA_TRASH ) { - $delete = "" . __( 'Delete' ) . " + wp_enqueue_script( 'media-events' ); + $delete = "" . __( 'Delete' ) . " '; } else { $delete = "" . __( 'Move to Trash' ) . " @@ -1752,12 +1746,13 @@ function get_media_item( $attachment_id, $args = null ) { && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) { + wp_enqueue_script( 'media-events' ); $calling_post = get_post( $calling_post_id ); $calling_post_type_object = get_post_type_object( $calling_post->post_type ); $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" ); - $thumbnail = "" . esc_html( $calling_post_type_object->labels->use_featured_image ) . ''; + $thumbnail = "" . esc_html( $calling_post_type_object->labels->use_featured_image ) . ''; } if ( ( $parsed_args['send'] || $thumbnail || $delete ) && ! isset( $form_fields['buttons'] ) ) { @@ -2059,7 +2054,7 @@ function get_compat_media_markup( $attachment_id, $args = null ) { function media_upload_header() { $post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0; - echo ''; + wp_print_inline_script_tag( "post_id = $post_id;" ); if ( empty( $_GET['chromeless'] ) ) { echo '
'; @@ -2194,9 +2189,6 @@ function media_upload_form( $errors = null ) { */ $plupload_init = apply_filters( 'plupload_init', $plupload_init ); - ?> - + $js = "var resize_height = $large_size_h, resize_width = $large_size_w,\n"; + $js .= 'wpUploaderInit = ' . wp_json_encode( $plupload_init ) . ';'; + wp_print_inline_script_tag( $js ); + ?>
- +

- + + $js = <<<'JS' jQuery(function($){ var preloaded = $(".media-item.preloaded"); if ( preloaded.length > 0 ) { @@ -2340,7 +2337,10 @@ function media_upload_type_form( $type = 'file', $errors = null, $id = null ) { } updateMediaForm(); }); - +JS; + wp_print_inline_script_tag( $js ); + + ?>
- - +JS; + wp_print_inline_script_tag( $js ); + ?>
- +JS; + wp_print_inline_script_tag( $js ); + + ?>
@@ -2664,8 +2673,8 @@ function media_upload_gallery_form( $errors ) {

- - + +

@@ -2863,9 +2872,10 @@ function media_upload_library_form( $errors ) {
- + + $js = <<<'JS' jQuery(function($){ var preloaded = $(".media-item.preloaded"); if ( preloaded.length > 0 ) { @@ -2873,8 +2883,9 @@ function media_upload_library_form( $errors ) { updateMediaForm(); } }); - - +JS; + wp_print_inline_script_tag( $js ); + ?>
@@ -2923,6 +2934,8 @@ function wp_media_insert_url_form( $default_view = 'image' ) { $table_class = $view; } + wp_enqueue_script( 'media-events' ); + return '

   

' . @@ -2935,7 +2948,7 @@ function wp_media_insert_url_form( $default_view = 'image' ) { - + @@ -2958,13 +2971,13 @@ function wp_media_insert_url_form( $default_view = 'image' ) {

- + - + - + - + @@ -2975,14 +2988,14 @@ function wp_media_insert_url_form( $default_view = 'image' ) {
- - + +

' . __( 'Enter a link URL or click above for presets.' ) . '

- + @@ -3116,8 +3129,9 @@ function edit_form_image_editor( $post ) { if ( wp_attachment_is_image( $post->ID ) ) : $image_edit_button = ''; if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { + wp_enqueue_script( 'media-events' ); $nonce = wp_create_nonce( "image_editor-$post->ID" ); - $image_edit_button = " "; + $image_edit_button = " "; } $open_style = ''; diff --git a/src/wp-admin/includes/meta-boxes.php b/src/wp-admin/includes/meta-boxes.php index 5d003d3210c0d..18bc9fb65db09 100644 --- a/src/wp-admin/includes/meta-boxes.php +++ b/src/wp-admin/includes/meta-boxes.php @@ -440,8 +440,10 @@ function attachment_submit_meta_box( $post ) { if ( EMPTY_TRASH_DAYS && MEDIA_TRASH ) { echo "" . __( 'Move to Trash' ) . ''; } else { - $delete_ays = ! MEDIA_TRASH ? " onclick='return showNotice.warn();'" : ''; - echo "" . __( 'Delete permanently' ) . ''; + if ( ! MEDIA_TRASH ) { + wp_enqueue_script( 'metabox-events' ); + } + echo "" . __( 'Delete permanently' ) . ''; } } ?> @@ -843,9 +845,10 @@ function post_comment_meta_box_thead( $result ) { * @param WP_Post $post */ function post_comment_meta_box( $post ) { + wp_enqueue_script( 'metabox-events' ); wp_nonce_field( 'get-comments', 'add_comment_nonce', false ); ?> -

+

- - -

+

%s', + '%s', wp_nonce_url( "link.php?action=delete&link_id=$link->link_id", 'delete-bookmark_' . $link->link_id ), /* translators: %s: Link name. */ - esc_js( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ), + esc_attr( sprintf( __( "You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete." ), $link->link_name ) ), __( 'Delete' ) ); } diff --git a/src/wp-admin/includes/misc.php b/src/wp-admin/includes/misc.php index e13a46bc9139b..59c752d7b267e 100644 --- a/src/wp-admin/includes/misc.php +++ b/src/wp-admin/includes/misc.php @@ -1010,7 +1010,7 @@ function wp_color_scheme_settings() { ); } - echo '\n"; + wp_print_inline_script_tag( 'var _wpColorScheme = ' . wp_json_encode( array( 'icons' => $icon_colors ) ) . ';' ); } /** @@ -1279,12 +1279,13 @@ function wp_admin_canonical_url() { $filtered_url = remove_query_arg( $removable_query_args, $current_url ); ?> - - - ' . __( 'Back' ) . '' ); + wp_die( $file['error'] . ' ' . __( 'Back' ) . '' ); } return $file; @@ -840,11 +840,7 @@ function can_edit_network( $network_id ) { * @access private */ function _thickbox_path_admin_subfolder() { - ?> - - - - - - - - - - @@ -2307,7 +2309,7 @@ function the_block_editor_meta_boxes() { -
+ '; - ?> - - - - - - - +JS; + +wp_print_inline_script_tag( $js ); +?> diff --git a/src/wp-admin/link-manager.php b/src/wp-admin/link-manager.php index de57d2cf0d8dc..71834e9e639a1 100644 --- a/src/wp-admin/link-manager.php +++ b/src/wp-admin/link-manager.php @@ -134,4 +134,6 @@
" class="" id="file-form"> - - - +
diff --git a/src/wp-admin/network/site-users.php b/src/wp-admin/network/site-users.php index 319051f89dceb..37460887c87dd 100644 --- a/src/wp-admin/network/site-users.php +++ b/src/wp-admin/network/site-users.php @@ -217,12 +217,10 @@ wp_enqueue_script( 'user-suggest' ); } -require_once ABSPATH . 'wp-admin/admin-header.php'; ?> - - +require_once ABSPATH . 'wp-admin/admin-header.php'; +wp_print_inline_script_tag( 'var current_site_id = ' . $id . ';' ); +?>

diff --git a/src/wp-admin/network/upgrade.php b/src/wp-admin/network/upgrade.php index 8b0194e6ce205..00abe99b92432 100644 --- a/src/wp-admin/network/upgrade.php +++ b/src/wp-admin/network/upgrade.php @@ -122,15 +122,14 @@ } echo ''; ?>

- - '; + wp_print_inline_script_tag( $js ); break; case 'show': default: diff --git a/src/wp-admin/plugin-editor.php b/src/wp-admin/plugin-editor.php index 7467ace6aa119..594dd345d43e8 100644 --- a/src/wp-admin/plugin-editor.php +++ b/src/wp-admin/plugin-editor.php @@ -271,8 +271,8 @@
- -
+ +
diff --git a/src/wp-admin/setup-config.php b/src/wp-admin/setup-config.php index 244f12ed4ae42..dcb464ceef06e 100644 --- a/src/wp-admin/setup-config.php +++ b/src/wp-admin/setup-config.php @@ -40,6 +40,8 @@ nocache_headers(); +wp_print_scripts( 'setup-config' ); + // Support wp-config-sample.php one level up, for the develop repo. if ( file_exists( ABSPATH . 'wp-config-sample.php' ) ) { $config_file = file( ABSPATH . 'wp-config-sample.php' ); @@ -277,7 +279,7 @@ function setup_config_display_header( $body_classes = array() ) { $install .= '?language=en_US'; } - $tryagain_link = '

' . __( 'Try Again' ) . ''; + $tryagain_link = '

' . __( 'Try Again' ) . ''; if ( empty( $prefix ) ) { wp_die( __( 'Error: "Table Prefix" must not be empty.' ) . $tryagain_link ); @@ -416,16 +418,17 @@ function setup_config_display_header( $body_classes = array() ) {

- - - +
diff --git a/src/wp-admin/update-core.php b/src/wp-admin/update-core.php index fcae12eaa08ba..f36c5832f037d 100644 --- a/src/wp-admin/update-core.php +++ b/src/wp-admin/update-core.php @@ -198,15 +198,16 @@ function dismissed_updates() { $show_text = esc_js( __( 'Show hidden updates' ) ); $hide_text = esc_js( __( 'Hide hidden updates' ) ); - ?> - -

'; echo '
    '; foreach ( (array) $dismissed as $update ) { @@ -751,11 +752,10 @@ function do_core_upgrade( $reinstall = false ) { esc_url( self_admin_url( 'about.php?updated' ) ) ) . '' ); + + wp_print_inline_script_tag( sprintf( 'window.location = "%s";', self_admin_url( 'about.php?updated' ) ) ); ?>
- - +JS; +wp_print_inline_script_tag( $js ); +?> + "; + $embed .= wp_get_inline_script_tag( "embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');" ); } } @@ -1074,7 +1074,7 @@ public function embed($options = '', $native = false) } else { - $embed .= ""; + $embed .= wp_get_inline_script_tag( "embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');" ); } } @@ -1096,7 +1096,7 @@ public function embed($options = '', $native = false) } else { - $embed .= ""; + $embed .= wp_get_inline_script_tag( "embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');" ); } } @@ -1110,7 +1110,7 @@ public function embed($options = '', $native = false) } else { - $embed .= ""; + $embed .= wp_get_inline_script_tag( "embed_wmedia('$width', '$height', '" . $this->get_link() . "');" ); } } diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php index a46b97fa5ae92..6c3f6a41b0119 100644 --- a/src/wp-includes/class-wp-customize-manager.php +++ b/src/wp-includes/class-wp-customize-manager.php @@ -461,14 +461,11 @@ protected function wp_die( $ajax_message, $message = null ) { ), 'error' => $ajax_message, ); - ?> - - messenger_channel ) { return; } - ?> - - - - - - ' . __( 'This panel is used for managing navigation menus for content you have already published on your site. You can create menus and add items for existing content such as pages, posts, categories, tags, formats, or custom links.' ) . '

'; if ( current_theme_supports( 'widgets' ) ) { - $description .= '

' . sprintf( - /* translators: %s: URL to the Widgets panel of the Customizer. */ - __( 'Menus can be displayed in locations defined by your theme or in widget areas by adding a “Navigation Menu” widget.' ), - "javascript:wp.customize.panel( 'widgets' ).focus();" - ) . '

'; + /* translators: 'widget areas' link moves view to the Widgets panel of the Customizer. */ + $description .= '

' . + __( 'Menus can be displayed in locations defined by your theme or in by adding a “Navigation Menu” widget.' ) . '

'; } else { $description .= '

' . __( 'Menus can be displayed in locations defined by your theme.' ) . '

'; } @@ -687,8 +685,8 @@ public function customize_register() { } if ( current_theme_supports( 'widgets' ) ) { - /* translators: URL to the Widgets panel of the Customizer. */ - $description .= '

' . sprintf( __( 'If your theme has widget areas, you can also add menus there. Visit the Widgets panel and add a “Navigation Menu widget” to display a menu in a sidebar or footer.' ), "javascript:wp.customize.panel( 'widgets' ).focus();" ) . '

'; + /* translators: 'widget areas' link moves view to the Widgets panel of the Customizer. */ + $description .= '

' . __( 'If your theme has widget areas, you can also add menus there. Visit the and add a “Navigation Menu widget” to display a menu in a sidebar or footer.' ) . '

'; } $this->manager->add_section( @@ -1534,7 +1532,7 @@ public function export_preview_data() { $exports = array( 'navMenuInstanceArgs' => $this->preview_nav_menu_instance_args, ); - printf( '', wp_json_encode( $exports ) ); + wp_print_inline_script_tag( sprintf( 'var _wpCustomizePreviewNavMenusExports = %s;', wp_json_encode( $exports ) ) ); } /** diff --git a/src/wp-includes/class-wp-customize-widgets.php b/src/wp-includes/class-wp-customize-widgets.php index ed9bbe3dfd5e7..7a83c563492ee 100644 --- a/src/wp-includes/class-wp-customize-widgets.php +++ b/src/wp-includes/class-wp-customize-widgets.php @@ -1196,11 +1196,7 @@ public function export_preview_data() { unset( $registered_widget['callback'] ); // May not be JSON-serializeable. } - ?> - - - - \n" . self::wp_mce_translation() . "\n"; + wp_print_inline_script_tag( self::wp_mce_translation() ); } /** @@ -1608,33 +1604,35 @@ public static function editor_js() { * @param array $mce_settings TinyMCE settings array. */ do_action( 'before_wp_tiny_mce', self::$mce_settings ); - ?> - - \n"; + wp_print_script_tag( + array( + 'type' => 'text/javascript', + 'src' => "{$baseurl}/langs/wp-langs-en.js?$version", + ) + ); } } @@ -1648,20 +1646,16 @@ public static function editor_js() { */ do_action( 'wp_tiny_mce_init', self::$mce_settings ); - ?> - - - - ID, 'relative' ) . '"); + });'; + wp_print_inline_script_tag( $js ); } /** diff --git a/src/wp-includes/class.wp-scripts.php b/src/wp-includes/class.wp-scripts.php index aa4935da6b616..cd9368412d3b5 100644 --- a/src/wp-includes/class.wp-scripts.php +++ b/src/wp-includes/class.wp-scripts.php @@ -227,20 +227,14 @@ public function print_extra_script( $handle, $echo = true ) { return $output; } - printf( "\n", $this->type_attr, esc_attr( $handle ) ); + $js = $output; // CDATA is not needed for HTML 5. if ( $this->type_attr ) { - echo "/* */"; } - echo "$output\n"; - - if ( $this->type_attr ) { - echo "/* ]]> */\n"; - } - - echo "\n"; + wp_print_inline_script_tag( $js, array( 'id' => "$handle-js-extra" ) ); return true; } @@ -298,11 +292,17 @@ public function do_item( $handle, $group = false ) { $after_handle = $this->print_inline_script( $handle, 'after', false ); if ( $before_handle ) { - $before_handle = sprintf( "\n%s\n\n", $this->type_attr, esc_attr( $handle ), $before_handle ); + $before_handle = wp_get_inline_script_tag( + $before_handle, + array( 'id' => "$handle-js-before" ) + ); } if ( $after_handle ) { - $after_handle = sprintf( "\n%s\n\n", $this->type_attr, esc_attr( $handle ), $after_handle ); + $after_handle = wp_get_inline_script_tag( + $after_handle, + array( 'id' => "$handle-js-after" ) + ); } if ( $before_handle || $after_handle ) { @@ -313,7 +313,10 @@ public function do_item( $handle, $group = false ) { $translations = $this->print_translations( $handle, false ); if ( $translations ) { - $translations = sprintf( "\n%s\n\n", $this->type_attr, esc_attr( $handle ), $translations ); + $translations = wp_get_inline_script_tag( + $translations, + array( 'id' => "$handle-js-translations" ) + ); } if ( $this->do_concat ) { @@ -385,7 +388,12 @@ public function do_item( $handle, $group = false ) { } $tag = $translations . $cond_before . $before_handle; - $tag .= sprintf( "\n", $this->type_attr, $src, esc_attr( $handle ) ); + $tag .= wp_get_script_tag( + array( + 'src' => $src, + 'id' => "$handle-js", + ) + ); $tag .= $after_handle . $cond_after; /** @@ -458,7 +466,7 @@ public function print_inline_script( $handle, $position = 'after', $echo = true $output = trim( implode( "\n", $output ), "\n" ); if ( $echo ) { - printf( "\n%s\n\n", $this->type_attr, esc_attr( $handle ), esc_attr( $position ), $output ); + wp_print_inline_script_tag( $output, array( 'id' => "$handle-js-$position" ) ); } return $output; @@ -595,7 +603,7 @@ public function print_translations( $handle, $echo = true ) { JS; if ( $echo ) { - printf( "\n%s\n\n", $this->type_attr, esc_attr( $handle ), $output ); + wp_print_inline_script_tag( $output, array( 'id' => "$handle-js-translations" ) ); } return $output; diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php index e3cfdef3123a9..1f5c9c3f03a02 100644 --- a/src/wp-includes/comment-template.php +++ b/src/wp-includes/comment-template.php @@ -1304,7 +1304,7 @@ function wp_comment_form_unfiltered_html_nonce() { if ( current_user_can( 'unfiltered_html' ) ) { wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false ); - echo "\n"; + wp_print_inline_script_tag( "(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();" ); } } @@ -1817,19 +1817,23 @@ function get_post_reply_link( $args = array(), $post = null ) { $args['login_text'] ); } else { - $onclick = sprintf( - 'return addComment.moveForm( "%1$s-%2$s", "0", "%3$s", "%2$s" )', - $args['add_below'], - $post->ID, - $args['respond_id'] - ); - $link = sprintf( - "%s", + "%s", + $post->ID, get_permalink( $post->ID ) . '#' . $args['respond_id'], - $onclick, $args['reply_text'] ); + + $js = <<ID}' ).addEventListener( 'click', function ( event ) { + if ( addComment.moveForm( "{$args['add_below']}-{$post->ID}", "0", "{$args['respond_id']}", "{$post->ID}" ) === false ) { + event.preventDefault(); + } + } ); +} ); +JS; + wp_print_inline_script_tag( $js ); } $formatted_link = $args['before'] . $link . $args['after']; diff --git a/src/wp-includes/customize/class-wp-customize-selective-refresh.php b/src/wp-includes/customize/class-wp-customize-selective-refresh.php index e8658b30a2c05..20e42ee882ed7 100644 --- a/src/wp-includes/customize/class-wp-customize-selective-refresh.php +++ b/src/wp-includes/customize/class-wp-customize-selective-refresh.php @@ -192,7 +192,7 @@ public function export_preview_data() { ); // Export data to JS. - printf( '', wp_json_encode( $exports ) ); + wp_print_inline_script_tag( sprintf( 'var _customizePartialRefreshExports = %s;', wp_json_encode( $exports ) ) ); } /** diff --git a/src/wp-includes/embed.php b/src/wp-includes/embed.php index a9704b78725bb..fd849f9137294 100644 --- a/src/wp-includes/embed.php +++ b/src/wp-includes/embed.php @@ -445,10 +445,9 @@ function get_post_embed_html( $width, $height, $post = null ) { $output = '
' . get_the_title( $post ) . "
\n"; - $output .= ""; + $script_output .= "\n//-->"; + + $output .= wp_get_inline_script_tag( $script_output ); $output .= sprintf( '', @@ -1051,12 +1051,9 @@ function print_embed_styles() { * @since 4.4.0 */ function print_embed_scripts() { - $type_attr = current_theme_supports( 'html5', 'script' ) ? '' : ' type="text/javascript"'; - ?> - > - + $js .= <<<'JS' include "js/wp-embed-template.min.js" - - - apply_filters( 'emoji_svg_ext', '.svg' ), ); - $version = 'ver=' . get_bloginfo( 'version' ); - $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/javascript"'; + $version = 'ver=' . get_bloginfo( 'version' ); if ( SCRIPT_DEBUG ) { $settings['source'] = array( @@ -5706,12 +5705,9 @@ function _print_emoji_detection_script() { 'twemoji' => apply_filters( 'script_loader_src', includes_url( "js/twemoji.js?$version" ), 'twemoji' ), ); - ?> - > - window._wpemojiSettings = ; - - - - > - window._wpemojiSettings = ; - include "js/wp-emoji-loader.min.js" - - $back_text

"; + $message .= "\n

$back_text

"; + + $js = <<<'JS' +document.addEventListener( 'DOMContentLoaded', function () { + document.querySelectorAll( '.go-back' ).forEach( function ( item ) { + item.addEventListener( 'click', function ( event ) { + window.history.go( -1 ); + event.preventDefault(); + } ); + } ); +} ); +JS; + $message .= wp_get_inline_script_tag( $js ); } if ( ! did_action( 'admin_head' ) ) : @@ -6845,21 +6857,19 @@ function wp_post_preview_js() { // Has to match the window name used in post_submit_meta_box(). $name = 'wp-preview-' . (int) $post->ID; - ?> - - ` tag. + * + * Automatically injects type attribute if needed. + * Used by {@see wp_get_script_tag()} and {@see wp_get_inline_script_tag()}. + * + * @since 5.6.0 + * + * @param array $attributes Key-value pairs representing `\n", wp_sanitize_script_attributes( $attributes ) ); +} + +/** + * Prints formatted `\n", wp_sanitize_script_attributes( $attributes ), $javascript ); +} + +/** + * Prints inline JavaScript wrapped in `\n"; + wp_print_inline_script_tag( "\n/* print_code}/* ]]> */\n" ); } $concat = str_split( $concat, 128 ); @@ -1929,7 +1943,7 @@ function _print_scripts() { } $src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}" . $concatenated . '&ver=' . $wp_scripts->default_version; - echo "\n"; + wp_print_script_tag( array( 'src' => $src ) ); } if ( ! empty( $wp_scripts->print_html ) ) { diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index 8e8a5779d4783..a2b38707988dc 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -3548,24 +3548,25 @@ function wp_customize_support_script() { $admin_origin = parse_url( admin_url() ); $home_origin = parse_url( home_url() ); $cross_domain = ( strtolower( $admin_origin['host'] ) != strtolower( $home_origin['host'] ) ); - $type_attr = current_theme_supports( 'html5', 'script' ) ? '' : ' type="text/javascript"'; - ?> - > + + $js = << - request = (function(){ var xhr = new XMLHttpRequest(); return ('withCredentials' in xhr); })(); - - request = true; - + if ( $cross_domain ) { + $js .= "request = (function(){ var xhr = new XMLHttpRequest(); return ('withCredentials' in xhr); })();\n"; + } else { + $js .= "request = true;\n"; + } + $js .= << - > Create some.' ); } else { $url = admin_url( 'nav-menus.php' ); + /* translators: %s: URL to create a new menu. */ + printf( __( 'No menus have been created yet. Create some.' ), esc_attr( $url ) ); } - - /* translators: %s: URL to create a new menu. */ - printf( __( 'No menus have been created yet. Create some.' ), esc_attr( $url ) ); ?>