: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @output wp-includes/js/wp-lists.js
/* global ajaxurl, wpAjax */
* @param {jQuery} $ jQuery object.
* The HTTP method to use for Ajax requests.
* ID of the element the parsed Ajax response will be stored in.
response: 'ajax-response',
* CSS class name for alternate styling.
* Offset to start alternate styling from.
* Color used in animation when adding an element.
* Can be 'none' to disable the animation.
* Color used in animation when deleting an element.
* Can be 'none' to disable the animation.
* Color used in dim add animation.
* Can be 'none' to disable the animation.
* Color used in dim delete animation.
* Can be 'none' to disable the animation.
* Callback that's run before a request is made.
* @callback wpList~confirm
* @param {HTMLElement} list The list DOM element.
* @param {object} settings Settings for the current list.
* @param {string} action The type of action to perform: 'add', 'delete', or 'dim'.
* @param {string} backgroundColor Background color of the list's DOM element.
* @return {boolean} Whether to proceed with the action or not.
* Callback that's run before an item gets added to the list.
* Allows to cancel the request.
* @callback wpList~addBefore
* @param {object} settings Settings for the Ajax request.
* @return {object|boolean} Settings for the Ajax request or false to abort.
* Callback that's run after an item got added to the list.
* @callback wpList~addAfter
* @param {XML} returnedResponse Raw response returned from the server.
* @param {object} settings Settings for the Ajax request.
* @param {jqXHR} settings.xml jQuery XMLHttpRequest object.
* @param {string} settings.status Status of the request: 'success', 'notmodified', 'nocontent', 'error',
* 'timeout', 'abort', or 'parsererror'.
* @param {object} settings.parsed Parsed response object.
* Callback that's run before an item gets deleted from the list.
* Allows to cancel the request.
* @callback wpList~delBefore
* @param {object} settings Settings for the Ajax request.
* @param {HTMLElement} list The list DOM element.
* @return {object|boolean} Settings for the Ajax request or false to abort.
* Callback that's run after an item got deleted from the list.
* @callback wpList~delAfter
* @param {XML} returnedResponse Raw response returned from the server.
* @param {object} settings Settings for the Ajax request.
* @param {jqXHR} settings.xml jQuery XMLHttpRequest object.
* @param {string} settings.status Status of the request: 'success', 'notmodified', 'nocontent', 'error',
* 'timeout', 'abort', or 'parsererror'.
* @param {object} settings.parsed Parsed response object.
* Callback that's run before an item gets dim'd.
* Allows to cancel the request.
* @callback wpList~dimBefore
* @param {object} settings Settings for the Ajax request.
* @return {object|boolean} Settings for the Ajax request or false to abort.
* Callback that's run after an item got dim'd.
* @callback wpList~dimAfter
* @param {XML} returnedResponse Raw response returned from the server.
* @param {object} settings Settings for the Ajax request.
* @param {jqXHR} settings.xml jQuery XMLHttpRequest object.
* @param {string} settings.status Status of the request: 'success', 'notmodified', 'nocontent', 'error',
* 'timeout', 'abort', or 'parsererror'.
* @param {object} settings.parsed Parsed response object.
* 2. `_ajax_nonce` value in element's href attribute.
* 3. `_ajax_nonce` input field that is a descendant of element.
* 4. `_wpnonce` value in element's href attribute.
* 5. `_wpnonce` input field that is a descendant of element.
* 6. 0 if none can be found.
* @param {jQuery} element Element that triggered the request.
* @param {Object} settings Settings for the Ajax request.
* @return {string|number} Nonce
nonce: function( element, settings ) {
var url = wpAjax.unserialize( element.attr( 'href' ) ),
$element = $( '#' + settings.element );
return settings.nonce || url._ajax_nonce || $element.find( 'input[name="_ajax_nonce"]' ).val() || url._wpnonce || $element.find( 'input[name="_wpnonce"]' ).val() || 0;
* Extract list item data from a DOM element.
* Example 1: data-wp-lists="delete:the-comment-list:comment-{comment_ID}:66cc66:unspam=1"
* Example 2: data-wp-lists="dim:the-comment-list:comment-{comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved"
* Returns an unassociative array with the following data:
* data[0] - Data identifier: 'list', 'add', 'delete', or 'dim'.
* data[1] - ID of the corresponding list. If data[0] is 'list', the type of list ('comment', 'category', etc).
* data[2] - ID of the parent element of all inputs necessary for the request.
* data[3] - Hex color to be used in this request. If data[0] is 'dim', dim class.
* data[4] - Additional arguments in query syntax that are added to the request. Example: 'post_id=1234'.
* If data[0] is 'dim', dim add color.
* data[5] - Only available if data[0] is 'dim', dim delete color.
* data[6] - Only available if data[0] is 'dim', additional arguments in query syntax that are added to the request.
* data[1] - the-comment-list
* data[2] - comment-{comment_ID}
* @param {HTMLElement} element The DOM element.
* @param {string} type The type of data to look for: 'list', 'add', 'delete', or 'dim'.
* @return {Array} Extracted list item data.
parseData: function( element, type ) {
var data = [], wpListsData;
wpListsData = $( element ).data( 'wp-lists' ) || '';
wpListsData = wpListsData.match( new RegExp( type + ':[\\S]+' ) );
data = wpListsData[0].split( ':' );
* Calls a confirm callback to verify the action that is about to be performed.
* @param {HTMLElement} list The DOM element.
* @param {Object} settings Settings for this list.
* @param {string} action The type of action to perform: 'add', 'delete', or 'dim'.
* @return {Object|boolean} Settings if confirmed, false if not.
pre: function( list, settings, action ) {
var $element, backgroundColor, confirmed;
settings = $.extend( {}, this.wpList.settings, {
if ( typeof settings.confirm === 'function' ) {
$element = $( '#' + settings.element );
if ( 'add' !== action ) {
backgroundColor = $element.css( 'backgroundColor' );
$element.css( 'backgroundColor', '#ff9966' );
confirmed = settings.confirm.call( this, list, settings, action, backgroundColor );
if ( 'add' !== action ) {
$element.css( 'backgroundColor', backgroundColor );
* Adds an item to the list via Ajax.
* @param {HTMLElement} element The DOM element.
* @param {Object} settings Settings for this list.
* @return {boolean} Whether the item was added.
ajaxAdd: function( element, settings ) {
data = wpList.parseData( $element, 'add' ),
formValues, formData, parsedResponse, returnedResponse;
settings = settings || {};
settings = wpList.pre.call( list, $element, settings, 'add' );
settings.element = data[2] || $element.prop( 'id' ) || settings.element || null;
settings.addColor = data[3] ? '#' + data[3] : settings.addColor;
if ( ! $element.is( '[id="' + settings.element + '-submit"]' ) ) {
return ! wpList.add.call( list, $element, settings );
if ( ! settings.element ) {
settings.action = 'add-' + settings.what;
settings.nonce = wpList.nonce( $element, settings );
if ( ! wpAjax.validateForm( '#' + settings.element ) ) {
settings.data = $.param( $.extend( {
_ajax_nonce: settings.nonce,
}, wpAjax.unserialize( data[4] || '' ) ) );
formValues = $( '#' + settings.element + ' :input' ).not( '[name="_ajax_nonce"], [name="_wpnonce"], [name="action"]' );
formData = typeof formValues.fieldSerialize === 'function' ? formValues.fieldSerialize() : formValues.serialize();
settings.data += '&' + formData;
if ( typeof settings.addBefore === 'function' ) {
settings = settings.addBefore( settings );
if ( ! settings.data.match( /_ajax_nonce=[a-f0-9]+/ ) ) {
settings.success = function( response ) {
parsedResponse = wpAjax.parseAjaxResponse( response, settings.response, settings.element );
returnedResponse = response;
if ( ! parsedResponse || parsedResponse.errors ) {
if ( true === parsedResponse ) {
$.each( parsedResponse.responses, function() {
wpList.add.call( list, this.data, $.extend( {}, settings, { // this.firstChild.nodevalue
position: this.position || 0,
oldId: this.oldId || null
$( list ).trigger( 'wpListAddEnd', [ settings, list.wpList ] );
wpList.clear.call( list, '#' + settings.element );
settings.complete = function( jqXHR, status ) {
if ( typeof settings.addAfter === 'function' ) {
settings.addAfter( returnedResponse, $.extend( {
* Delete an item in the list via Ajax.
* @param {HTMLElement} element A DOM element containing item data.
* @param {Object} settings Settings for this list.
* @return {boolean} Whether the item was deleted.
ajaxDel: function( element, settings ) {
data = wpList.parseData( $element, 'delete' ),
$eventTarget, parsedResponse, returnedResponse;
settings = settings || {};
settings = wpList.pre.call( list, $element, settings, 'delete' );
settings.element = data[2] || settings.element || null;
settings.delColor = data[3] ? '#' + data[3] : settings.delColor;
if ( ! settings || ! settings.element ) {
settings.action = 'delete-' + settings.what;
settings.nonce = wpList.nonce( $element, settings );
settings.data = $.extend( {
_ajax_nonce: settings.nonce,
id: settings.element.split( '-' ).pop()
}, wpAjax.unserialize( data[4] || '' ) );
if ( typeof settings.delBefore === 'function' ) {
settings = settings.delBefore( settings, list );
if ( ! settings.data._ajax_nonce ) {
$eventTarget = $( '#' + settings.element );
if ( 'none' !== settings.delColor ) {
$eventTarget.css( 'backgroundColor', settings.delColor ).fadeOut( 350, function() {
$( list ).trigger( 'wpListDelEnd', [ settings, list.wpList ] );
$( list ).trigger( 'wpListDelEnd', [ settings, list.wpList ] );
settings.success = function( response ) {
parsedResponse = wpAjax.parseAjaxResponse( response, settings.response, settings.element );
returnedResponse = response;
if ( ! parsedResponse || parsedResponse.errors ) {
$eventTarget.stop().stop().css( 'backgroundColor', '#faa' ).show().queue( function() {
settings.complete = function( jqXHR, status ) {
if ( typeof settings.delAfter === 'function' ) {
$eventTarget.queue( function() {
settings.delAfter( returnedResponse, $.extend( {
* Dim an item in the list via Ajax.
* @param {HTMLElement} element A DOM element containing item data.
* @param {Object} settings Settings for this list.
* @return {boolean} Whether the item was dim'ed.
ajaxDim: function( element, settings ) {
data = wpList.parseData( $element, 'dim' ),
$eventTarget, isClass, color, dimColor, parsedResponse, returnedResponse;
// Prevent hidden links from being clicked by hotkeys.
if ( 'none' === $element.parent().css( 'display' ) ) {