Skip to content

Instantly share code, notes, and snippets.

@timelsass
Last active September 10, 2018 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timelsass/eac654fbbe67e4c66c515e0aed8cc693 to your computer and use it in GitHub Desktop.
Save timelsass/eac654fbbe67e4c66c515e0aed8cc693 to your computer and use it in GitHub Desktop.
Add a global error notification to the customizer's main panel.
( 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 );
<?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