WP_Customize_Manager::prepare_setting_validity_for_js() WordPress Method

The WP_Customize_Manager::prepare_setting_validity_for_js() method is used to prepare a setting's validity for JavaScript. This is done by checking the setting's capabilities and mapping the setting to the proper Customizer component. If the setting is invalid, an error is returned.

WP_Customize_Manager::prepare_setting_validity_for_js( true|WP_Error $validity ) #

Prepares setting validity for exporting to the client (JS).


Description

Converts WP_Error instance into array suitable for passing into the wp.customize.Notification JS model.


Top ↑

Parameters

$validity

(true|WP_Error)(Required)Setting validity.


Top ↑

Return

(true|array) If $validity was a WP_Error, the error codes will be array-mapped to their respective message and data to pass into the wp.customize.Notification JS model.


Top ↑

Source

File: wp-includes/class-wp-customize-manager.php

	public function prepare_setting_validity_for_js( $validity ) {
		if ( is_wp_error( $validity ) ) {
			$notification = array();
			foreach ( $validity->errors as $error_code => $error_messages ) {
				$notification[ $error_code ] = array(
					'message' => implode( ' ', $error_messages ),
					'data'    => $validity->get_error_data( $error_code ),
				);
			}
			return $notification;
		} else {
			return true;
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
4.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More