WP_Customize_Manager::prepare_setting_validity_for_js()
Prepares setting validity for exporting to the client (JS).
Converts WP_Error instance into array suitable for passing into the wp.customize.Notification JS model.
Method of the class: WP_Customize_Manager{}
No Hooks.
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.
Usage
$WP_Customize_Manager = new WP_Customize_Manager(); $WP_Customize_Manager->prepare_setting_validity_for_js( $validity );
- $validity(true|WP_Error) (required)
- Setting validity.
Changelog
Since 4.6.0 | Introduced. |
WP_Customize_Manager::prepare_setting_validity_for_js() WP Customize Manager::prepare setting validity for js code WP 6.5.2
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; } }