From 0530c90b51aab15d24e05529fe3f4dd99fec9704 Mon Sep 17 00:00:00 2001
From: Grzegorz Rola <grola@seostudio.pl>
Date: Fri, 12 Oct 2018 17:04:39 +0200
Subject: [PATCH] Attributes

---
 src/WPDesk/Notice/Notice.php                  | 19 ++++++++++++++++---
 .../Notice/PermanentDismissibleNotice.php     |  6 +++---
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/WPDesk/Notice/Notice.php b/src/WPDesk/Notice/Notice.php
index 57c774d..1fcc627 100644
--- a/src/WPDesk/Notice/Notice.php
+++ b/src/WPDesk/Notice/Notice.php
@@ -64,13 +64,20 @@ class Notice
      * @param string $noticeType Notice type.
      * @param bool $dismissible Is dismissible.
      * @param int $priority Notice priority.
-     */
-    public function __construct($noticeContent, $noticeType = 'info', $dismissible = false, $priority = 10)
-    {
+     * @param array $attributes Attributes.
+     */
+    public function __construct(
+        $noticeContent,
+        $noticeType = 'info',
+        $dismissible = false,
+        $priority = 10,
+        $attributes = array()
+    ) {
         $this->noticeContent = $noticeContent;
         $this->noticeType    = $noticeType;
         $this->dismissible   = $dismissible;
         $this->priority      = $priority;
+        $this->attributes    = $attributes;
         $this->addAction();
     }
 
@@ -176,6 +183,9 @@ class Notice
         if ($this->dismissible) {
             $notice_class .= ' is-dismissible';
         }
+        if (isset($this->attributes['class'])) {
+            $notice_class .= $this->attributes['class'];
+        }
         return $notice_class;
     }
 
@@ -187,6 +197,9 @@ class Notice
     protected function getAttributesAsString()
     {
         $attribute_string = sprintf('class="%1$s"', esc_attr($this->getNoticeClass()));
+        foreach ($this->attributes as $attribute_name => $attribute_value) {
+            $attribute_string .= sprintf(' %1$s="%2$s"', esc_html($attribute_name), esc_attr($attribute_value));
+        }
         return $attribute_string;
     }
 
diff --git a/src/WPDesk/Notice/PermanentDismissibleNotice.php b/src/WPDesk/Notice/PermanentDismissibleNotice.php
index ea31b5a..00d0336 100644
--- a/src/WPDesk/Notice/PermanentDismissibleNotice.php
+++ b/src/WPDesk/Notice/PermanentDismissibleNotice.php
@@ -31,11 +31,11 @@ class PermanentDismissibleNotice extends Notice
      * @param string $noticeType Notice type.
      * @param string $noticeName Notice dismiss option name.
      * @param int    $priority Priority
+     * @param array $attributes Attributes.
      */
-
-    public function __construct($noticeContent, $noticeType, $noticeName, $priority = 10)
+    public function __construct($noticeContent, $noticeType, $noticeName, $priority = 10, $attributes = array())
     {
-        parent::__construct($noticeContent, $noticeType, true, $priority);
+        parent::__construct($noticeContent, $noticeType, true, $priority, $attributes);
         $this->noticeName = $noticeName;
         $this->noticeDismissOptionName = static::OPTION_NAME_PREFIX . $noticeName;
         if (self::OPTION_VALUE_DISMISSED === get_option($this->noticeDismissOptionName, '')) {
-- 
GitLab