* @output wp-admin/js/common.js
/* global setUserSetting, ajaxurl, alert, confirm, pagenow */
/* global columns, screenMeta */
* Adds common WordPress functionality to the window.
* @param {jQuery} $ jQuery object.
* @param {Object} window The window object.
* @param {mixed} undefined Unused.
( function( $, window, undefined ) {
var $document = $( document ),
$body = $( document.body ),
sprintf = wp.i18n.sprintf;
* Throws an error for a deprecated property.
* @param {string} propName The property that was used.
* @param {string} version The version of WordPress that deprecated the property.
* @param {string} replacement The property that should have been used.
function deprecatedProperty( propName, version, replacement ) {
if ( 'undefined' !== typeof replacement ) {
/* translators: 1: Deprecated property name, 2: Version number, 3: Alternative property name. */
__( '%1$s is deprecated since version %2$s! Use %3$s instead.' ),
/* translators: 1: Deprecated property name, 2: Version number. */
__( '%1$s is deprecated since version %2$s with no alternative available.' ),
window.console.warn( message );
* Deprecate all properties on an object.
* @since 5.6.0 Added the `version` parameter.
* @param {string} name The name of the object, i.e. commonL10n.
* @param {object} l10nObject The object to deprecate the properties on.
* @param {string} version The version of WordPress that deprecated the property.
* @return {object} The object with all its properties deprecated.
function deprecateL10nObject( name, l10nObject, version ) {
var deprecatedObject = {};
Object.keys( l10nObject ).forEach( function( key ) {
var prop = l10nObject[ key ];
var propName = name + '.' + key;
if ( 'object' === typeof prop ) {
Object.defineProperty( deprecatedObject, key, { get: function() {
deprecatedProperty( propName, version, prop.alternative );
Object.defineProperty( deprecatedObject, key, { get: function() {
deprecatedProperty( propName, version, 'wp.i18n' );
window.wp.deprecateL10nObject = deprecateL10nObject;
* Removed in 5.5.0, needed for back-compatibility.
window.commonL10n = window.commonL10n || {
window.commonL10n = deprecateL10nObject( 'commonL10n', window.commonL10n, '5.5.0' );
* Removed in 5.5.0, needed for back-compatibility.
window.wpPointerL10n = window.wpPointerL10n || {
window.wpPointerL10n = deprecateL10nObject( 'wpPointerL10n', window.wpPointerL10n, '5.5.0' );
* Removed in 5.5.0, needed for back-compatibility.
window.userProfileL10n = window.userProfileL10n || {
window.userProfileL10n = deprecateL10nObject( 'userProfileL10n', window.userProfileL10n, '5.5.0' );
* Removed in 5.5.0, needed for back-compatibility.
window.privacyToolsL10n = window.privacyToolsL10n || {
window.privacyToolsL10n = deprecateL10nObject( 'privacyToolsL10n', window.privacyToolsL10n, '5.5.0' );
* Removed in 5.5.0, needed for back-compatibility.
window.authcheckL10n = window.authcheckL10n || deprecateL10nObject( 'authcheckL10n', window.authcheckL10n, '5.5.0' );
* Removed in 5.5.0, needed for back-compatibility.
window.tagsl10n = window.tagsl10n || deprecateL10nObject( 'tagsl10n', window.tagsl10n, '5.5.0' );
* Removed in 5.5.0, needed for back-compatibility.
window.adminCommentsL10n = window.adminCommentsL10n || {
hotkeys_highlight_first: {
alternative: 'window.adminCommentsSettings.hotkeys_highlight_first',
func: function() { return window.adminCommentsSettings.hotkeys_highlight_first; }
hotkeys_highlight_last: {
alternative: 'window.adminCommentsSettings.hotkeys_highlight_last',
func: function() { return window.adminCommentsSettings.hotkeys_highlight_last; }
docTitleCommentsCount: ''
window.adminCommentsL10n = deprecateL10nObject( 'adminCommentsL10n', window.adminCommentsL10n, '5.5.0' );
* Removed in 5.5.0, needed for back-compatibility.
window.tagsSuggestL10n = window.tagsSuggestL10n || {
window.tagsSuggestL10n = deprecateL10nObject( 'tagsSuggestL10n', window.tagsSuggestL10n, '5.5.0' );
* Removed in 5.5.0, needed for back-compatibility.
window.wpColorPickerL10n = window.wpColorPickerL10n || {
window.wpColorPickerL10n = deprecateL10nObject( 'wpColorPickerL10n', window.wpColorPickerL10n, '5.5.0' );
* Removed in 5.5.0, needed for back-compatibility.
window.attachMediaBoxL10n = window.attachMediaBoxL10n || {
window.attachMediaBoxL10n = deprecateL10nObject( 'attachMediaBoxL10n', window.attachMediaBoxL10n, '5.5.0' );
* Removed in 5.5.0, needed for back-compatibility.
window.postL10n = window.postL10n || {
window.postL10n = deprecateL10nObject( 'postL10n', window.postL10n, '5.5.0' );
* Removed in 5.5.0, needed for back-compatibility.
window.inlineEditL10n = window.inlineEditL10n || {
window.inlineEditL10n = deprecateL10nObject( 'inlineEditL10n', window.inlineEditL10n, '5.5.0' );
* Removed in 5.5.0, needed for back-compatibility.
window.plugininstallL10n = window.plugininstallL10n || {
window.plugininstallL10n = deprecateL10nObject( 'plugininstallL10n', window.plugininstallL10n, '5.5.0' );
* Removed in 5.5.0, needed for back-compatibility.
window.navMenuL10n = window.navMenuL10n || {
window.navMenuL10n = deprecateL10nObject( 'navMenuL10n', window.navMenuL10n, '5.5.0' );
* Removed in 5.5.0, needed for back-compatibility.
window.commentL10n = window.commentL10n || {
window.commentL10n = deprecateL10nObject( 'commentL10n', window.commentL10n, '5.5.0' );
* Removed in 5.5.0, needed for back-compatibility.
window.setPostThumbnailL10n = window.setPostThumbnailL10n || {
window.setPostThumbnailL10n = deprecateL10nObject( 'setPostThumbnailL10n', window.setPostThumbnailL10n, '5.5.0' );
* Removed in 3.3.0, needed for back-compatibility.
restoreMenuState : function() {},
favorites : function() {}
// Show/hide/save table columns.
* Initializes the column toggles in the screen options.
* Binds an onClick event to the checkboxes to show or hide the table columns
* based on their toggled state. And persists the toggled state.
$('.hide-column-tog', '#adv-settings').on( 'click', function() {
var $t = $(this), column = $t.val();
if ( $t.prop('checked') )
columns.saveManageColumnsState();
* Saves the toggled state for the columns.
* Saves whether the columns should be shown or hidden on a page.
saveManageColumnsState : function() {
var hidden = this.hidden();
action: 'hidden-columns',
screenoptionnonce: $('#screenoptionnonce').val(),
* Makes a column visible and adjusts the column span for the table.
* @param {string} column The column name.
checked : function(column) {
$('.column-' + column).removeClass( 'hidden' );
* Hides a column and adjusts the column span for the table.
* @param {string} column The column name.
unchecked : function(column) {
$('.column-' + column).addClass( 'hidden' );
* Gets all hidden columns.
* @return {string} The hidden column names separated by a comma.
return $( '.manage-column[id]' ).filter( '.hidden' ).map(function() {
* Gets the checked column toggles from the screen options.
* @return {string} String containing the checked column names.
useCheckboxesForHidden : function() {
this.hidden = function(){
return $('.hide-column-tog').not(':checked').map(function() {
return id.substring( id, id.length - 5 );
* Adjusts the column span for the table.
* @param {number} diff The modifier for the column span.
colSpanChange : function(diff) {
var $t = $('table').find('.colspanchange'), n;
n = parseInt( $t.attr('colspan'), 10 ) + diff;
$t.attr('colspan', n.toString());
$document.ready(function(){columns.init();});
* Validates that the required form fields are not empty.
* @param {jQuery} form The form to validate.
* @return {boolean} Returns true if all required fields are not an empty string.
window.validateForm = function( form ) {
.find( '.form-required' )
.filter( function() { return $( ':input:visible', this ).val() === ''; } )