Skip to content
Snippets Groups Projects
Select Git revision
  • d7c257e6e8a85f6c83946a703ae0dccb5fe60516
  • master default protected
  • bugfix/wordpress-review
  • fix/duplicate
  • bugfix/get_current_screen_fail
  • feature/dismiss-nonce
  • replace-dodgy-path
  • bugfix/notice-not-show
  • devel
  • 3.3.0
  • 3.2.5
  • 3.2.4
  • 3.2.3
  • 3.2.2
  • 3.2.1
  • 3.2.0
  • 3.2.0-beta7
  • 3.2.0-beta6
  • 3.2.0-beta5
  • 3.2.0-beta4
  • 3.2.0-beta3
  • 3.2.0-beta2
  • 3.2.0-beta1
  • 3.1.4
  • 3.1.4-beta1
  • 3.1.3
  • 3.1.1
  • 3.1
  • 3.0
29 results

PermanentDismissibleNotice.php

Blame
  • PermanentDismissibleNotice.php 1.96 KiB
    <?php
    
    namespace WPDesk\Notice;
    
    /**
     * Class PermanentDismissibleNotice
     *
     * WordPress admin dismissible notice.
     * @package WPDesk\Notice
     */
    class PermanentDismissibleNotice extends Notice
    {
    
        const OPTION_NAME_PREFIX = 'wpdesk_notice_dismiss_';
        const OPTION_VALUE_DISMISSED = '1';
    
        /**
         * @var string
         */
        private $noticeName;
    
        /**
         * @var string
         */
        private $noticeDismissOptionName;
    
        /**
         * WPDesk_Flexible_Shipping_Notice constructor.
         *
         * @param string $noticeContent Notice content.
         * @param string $noticeName Notice dismiss option name.
         * @param string $noticeType Notice type.
         * @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(),
            $showInGutenberg = false
        ) {
            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, '')) {
                $this->removeAction();
            }
        }
    
        /**
         * Undo dismiss notice.
         */
        public function undoDismiss()
        {
            delete_option($this->noticeDismissOptionName);
            $this->addAction();
        }
    
        /**
         * Get attributes as string.
         *
         * @return string
         */
        protected function getAttributesAsString()
        {
            $attributesAsString = parent::getAttributesAsString();
            $attributesAsString .= sprintf(' data-notice-name="%1$s"', esc_attr($this->noticeName));
            $attributesAsString .= sprintf(' id="wpdesk-notice-%1$s"', esc_attr($this->noticeName));
            return $attributesAsString;
        }
    
    }