Skip to content
Snippets Groups Projects
Select Git revision
  • 0fd87964dcabc6241659163bf0d284cd95720d62
  • master default protected
  • bugfix/vendor-excluded
  • feature/phpcs-editorconfig
  • 1.3.2
  • 1.3.1
  • 1.3.0
  • 1.2.8
  • 1.2.7
  • 1.2.6
  • 1.2.5
  • 1.2.4
  • 1.2.3
  • 1.2.2
  • 1.2.1
  • 1.2.0
  • 1.1.0
  • 1.1.0-beta1
  • 1.0.1
  • 1.0.0
  • 1.0.0-beta8
  • 1.0.0-beta7
  • 1.0.0-beta6
  • 1.0.0-beta5
24 results

ruleset.xml

Blame
  • PermanentDismissibleNotice.php 1.56 KiB
    <?php
    
    namespace WPDesk\Notice;
    
    /**
     * Class 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 $noticeType Notice type.
         * @param string $noticeName Notice dismiss option name.
         * @param int    $priority Priority
         */
    
        public function __construct($noticeContent, $noticeType, $noticeName, $priority = 10)
        {
            parent::__construct($noticeContent, $noticeType, true, $priority);
            $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));
            return $attributesAsString;
        }
    
    }