diff --git a/src/js/_enqueues/admin/common.js b/src/js/_enqueues/admin/common.js
index 358948d306cf6..56e4362acbfda 100644
--- a/src/js/_enqueues/admin/common.js
+++ b/src/js/_enqueues/admin/common.js
@@ -1287,20 +1287,42 @@ $( function() {
$headerEnd = $( '.wp-header-end' ),
type,
dismissible,
+ additionalClasses = '',
+ attributes = '',
+ paragraphWrap = ( data.paragraph_wrap !== undefined ) ? data.paragraph_wrap : true,
$adminNotice;
- delete data.selector;
-
+ // Defaults for the arguments.
+ type = data.type ? data.type : 'info';
dismissible = ( data.dismissible && data.dismissible === true ) ? ' is-dismissible' : '';
- type = ( data.type ) ? data.type : 'info';
+ var message = data.message ? data.message : '';
+
+ // Handle additional classes if any are provided.
+ if ( data.additional_classes && Array.isArray( data.additional_classes ) ) {
+ additionalClasses = ' ' + data.additional_classes.join( ' ' );
+ }
+
+ // Handle additional attributes if any are provided.
+ if ( data.attributes && typeof data.attributes === 'object' ) {
+ Object.keys( data.attributes ).forEach(function( key ) {
+ attributes += ' ' + key + '="' + data.attributes[key] + '"';
+ });
+ }
+
+ // Wrap message in
if paragraph_wrap is true.
+ if ( paragraphWrap ) {
+ message = '
' + message + '
';
+ }
- $adminNotice = '';
+ // Build the admin notice element.
+ $adminNotice = '' + message + '
';
// Check if this admin notice already exists.
if ( ! $notice.length ) {
$notice = $( '#' + data.id );
}
+ // Either replace an existing notice or insert a new one.
if ( $notice.length ) {
$notice.replaceWith( $adminNotice );
} else if ( $headerEnd.length ) {
@@ -1313,7 +1335,8 @@ $( function() {
}
}
- $document.trigger( 'wp-notice-added' );
+ // Trigger a global event after adding the notice.
+ $(document).trigger( 'wp-notice-added' );
};
$( '.bulkactions' ).parents( 'form' ).on( 'submit', function( event ) {
diff --git a/src/js/_enqueues/wp/updates.js b/src/js/_enqueues/wp/updates.js
index aca73fdd4f748..ad48f801d1fca 100644
--- a/src/js/_enqueues/wp/updates.js
+++ b/src/js/_enqueues/wp/updates.js
@@ -251,33 +251,14 @@
*
*/
wp.updates.addAdminNotice = function( data ) {
- var $notice = $( data.selector ),
- $headerEnd = $( '.wp-header-end' ),
- $adminNotice;
+ // Simply delegate to the global addAdminNotice function.
- delete data.selector;
- $adminNotice = wp.updates.adminNotice( data );
+ addAdminNotice( data );
- // Check if this admin notice already exists.
- if ( ! $notice.length ) {
- $notice = $( '#' + data.id );
- }
-
- if ( $notice.length ) {
- $notice.replaceWith( $adminNotice );
- } else if ( $headerEnd.length ) {
- $headerEnd.after( $adminNotice );
- } else {
- if ( 'customize' === pagenow ) {
- $( '.customize-themes-notifications' ).append( $adminNotice );
- } else {
- $( '.wrap' ).find( '> h1' ).after( $adminNotice );
- }
- }
-
- $document.trigger( 'wp-updates-notice-added' );
+ $(document).trigger( 'wp-updates-notice-added' );
};
+
/**
* Handles Ajax requests to WordPress.
*