disabled-site-header-custom-logo-notification.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @author danielsmithmichigan
  3. * global wp
  4. **/
  5. var blankCanvasDisabledSiteHeaderCustomLogoNotification = ( function( wp ) {
  6. var notification_code = 'BLANK_CANVAS_DISABLED_SITE_HEADER_CUSTOM_LOGO_NOTIFICATION';
  7. var self = {};
  8. wp.customize.bind( 'ready', function() {
  9. self.maybeAddCustomLogoNotification = function() {
  10. // Exit if one of the controls doesn't exist just to be safe.
  11. var showSiteHeaderControl = wp.customize.control('show_site_header')
  12. var customLogoControl = wp.customize.control('custom_logo');
  13. if ( !showSiteHeaderControl || !customLogoControl ) {
  14. return;
  15. }
  16. // Check if the notification has already been added to the custom logo control
  17. var notification_is_present = false;
  18. var all_notifications = customLogoControl.notifications.get() || [];
  19. for (var i = 0; i < all_notifications.length; i++) {
  20. if( 'object' !== typeof all_notifications[i] ) continue;
  21. if( all_notifications[i].code === notification_code ) {
  22. notification_is_present = true;
  23. break;
  24. }
  25. }
  26. // The notification is necessary if show_site_header is not enabled, and a logo has been uploaded
  27. var notification_is_necessary = false === showSiteHeaderControl.setting.get() &&
  28. '' !== customLogoControl.setting.get();
  29. // Add or remove the notification
  30. if ( ! notification_is_present && notification_is_necessary ) {
  31. customLogoControl.notifications.add(
  32. notification_code,
  33. new wp.customize.Notification(
  34. notification_code,
  35. {
  36. message: disabled_site_header_custom_logo_notification_translations.custom_logo_notification_content,
  37. type: 'warning'
  38. }
  39. )
  40. )
  41. } else if ( notification_is_present && ! notification_is_necessary ) {
  42. customLogoControl.notifications.remove( notification_code );
  43. }
  44. };
  45. wp.customize('custom_logo', function(setting) {
  46. setting.bind(function(value) {
  47. self.maybeAddCustomLogoNotification();
  48. });
  49. });
  50. wp.customize('show_site_header', function(setting) {
  51. setting.bind(function(value) {
  52. self.maybeAddCustomLogoNotification();
  53. });
  54. });
  55. self.maybeAddCustomLogoNotification();
  56. });
  57. return self;
  58. } )( wp );