Last active
September 10, 2018 01:41
-
-
Save timelsass/eac654fbbe67e4c66c515e0aed8cc693 to your computer and use it in GitHub Desktop.
Add a global error notification to the customizer's main panel.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( function( $ ) { | |
'use strict'; | |
wp.customize.bind( 'ready', function () { | |
wp.customize.notifications.add( | |
'wpse313731-custom-notification', | |
new wp.customize.Notification( | |
'wpse313731-custom-notification', { | |
dismissible: true, | |
message: wpse313731.msg, | |
type: 'error' | |
} | |
) | |
); | |
} ); | |
} )( jQuery ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: WPSE313731 Custom Notification | |
* Description: Add a global error notification to the customizer's main panel. | |
* Plugin URI: https://gist.github.com/timelsass/eac654fbbe67e4c66c515e0aed8cc693 | |
* Author: Tim Elsass | |
* Author URI: tim.ph | |
*/ | |
/** | |
* Enqueue CSS and JS for customizer pane. | |
*/ | |
function wpse313731_custom_notification_enqueue_scripts() { | |
$handle = 'wpse313731-custom-notification'; | |
// Register the script. | |
wp_register_script( $handle, plugins_url( "$handle.js", __FILE__ ), array( 'customize-controls' ) ); | |
// Translate the message. | |
$translated_msg = array( | |
'msg' => esc_html( 'This is a custom message being added to the WordPress Customizer.' ), | |
); | |
// Localize script with translated data. | |
wp_localize_script( $handle, 'wpse313731', $translated_msg ); | |
// Enqueue the script. | |
wp_enqueue_script( $handle ); | |
} | |
add_action( 'customize_controls_enqueue_scripts', 'wpse313731_custom_notification_enqueue_scripts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment