diff --git a/assets/js/gutenberg.js b/assets/js/gutenberg.js index b5cd10acd056b076eefda9f9fdfa24defaff6e88..578034736b1742d0d28986c425a20537956f952e 100644 --- a/assets/js/gutenberg.js +++ b/assets/js/gutenberg.js @@ -1,5 +1,5 @@ jQuery( document ).ready(function() { - jQuery('.wpdesk').each(function( index ) { + jQuery('.wpdesk-notice-gutenberg').each(function( index ) { var classList = jQuery(this).attr('class').split(/\s+/); var type = ''; jQuery.each(classList, function(index, item) { diff --git a/src/WPDesk/Notice/Notice.php b/src/WPDesk/Notice/Notice.php index 9b3785696ae4b9aa87cf65dd83e388edfdf6985d..436c01f2e0aea2db1c9a4ad5b3ee2a6430d8c893 100644 --- a/src/WPDesk/Notice/Notice.php +++ b/src/WPDesk/Notice/Notice.php @@ -58,6 +58,12 @@ class Notice */ protected $attributes = array(); + /** + * Show notice in gutenberg editor. + * + * @var bool + */ + protected $showInGutenberg = false; /** * WPDesk_Flexible_Shipping_Notice constructor. @@ -67,19 +73,22 @@ class Notice * @param bool $dismissible Is dismissible. * @param int $priority Notice priority. * @param array $attributes Attributes. + * @param bool $showInGutenberg Show notice in gutenberg editor. */ public function __construct( $noticeContent, $noticeType = 'info', $dismissible = false, $priority = 10, - $attributes = array() + $attributes = array(), + $showInGutenberg = false ) { - $this->noticeContent = $noticeContent; - $this->noticeType = $noticeType; - $this->dismissible = $dismissible; - $this->priority = $priority; - $this->attributes = $attributes; + $this->noticeContent = $noticeContent; + $this->noticeType = $noticeType; + $this->dismissible = $dismissible; + $this->priority = $priority; + $this->attributes = $attributes; + $this->showInGutenberg = $showInGutenberg; $this->addAction(); } @@ -225,9 +234,9 @@ class Notice protected function getNoticeClass() { if ('updated' === $this->noticeType) { - $notice_class = 'wpdesk notice ' . $this->noticeType; + $notice_class = 'notice ' . $this->noticeType; } else { - $notice_class = 'wpdesk notice notice-' . $this->noticeType; + $notice_class = 'notice notice-' . $this->noticeType; } if ($this->dismissible) { $notice_class .= ' is-dismissible'; @@ -235,6 +244,9 @@ class Notice if (isset($this->attributes['class'])) { $notice_class .= ' ' . $this->attributes['class']; } + if ($this->showInGutenberg) { + $notice_class .= 'wpdesk-notice-gutenberg'; + } return $notice_class; } diff --git a/src/WPDesk/Notice/PermanentDismissibleNotice.php b/src/WPDesk/Notice/PermanentDismissibleNotice.php index 210176f9e8620401e9995c6bace4c8a1f89e2f36..741b4c4e008da0431fd638a46639d3c1c4ae8700 100644 --- a/src/WPDesk/Notice/PermanentDismissibleNotice.php +++ b/src/WPDesk/Notice/PermanentDismissibleNotice.php @@ -30,17 +30,19 @@ class PermanentDismissibleNotice extends Notice * @param string $noticeContent Notice content. * @param string $noticeName Notice dismiss option name. * @param string $noticeType Notice type. - * @param int $priority Priority + * @param int $priority Priority * @param array $attributes Attributes. + * @param bool $showInGutenberg Show notice in gutenberg editor. */ public function __construct( $noticeContent, $noticeName, $noticeType = 'info', $priority = 10, - $attributes = array() + $attributes = array(), + $showInGutenberg = false ) { - parent::__construct($noticeContent, $noticeType, true, $priority, $attributes); + parent::__construct($noticeContent, $noticeType, true, $priority, $attributes, $showInGutenberg); $this->noticeName = $noticeName; $this->noticeDismissOptionName = static::OPTION_NAME_PREFIX . $noticeName; if (self::OPTION_VALUE_DISMISSED === get_option($this->noticeDismissOptionName, '')) {