class-button.php
1 year ago
class-insert-button.php
1 year ago
class-premium-button.php
1 year ago
class-preview-button.php
1 year ago
class-button.php
61 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SuperbAddons\Components\Buttons; |
| 4 | |
| 5 | defined('ABSPATH') || exit(); |
| 6 | |
| 7 | class Button |
| 8 | { |
| 9 | private $type; |
| 10 | private $text; |
| 11 | private $icon; |
| 12 | private $url; |
| 13 | private $class; |
| 14 | private $target; |
| 15 | private $id; |
| 16 | |
| 17 | public function __construct($type = ButtonType::Primary, $icon = ButtonIcon::ExternalLink, $options = array()) |
| 18 | { |
| 19 | |
| 20 | $this->text = isset($options['text']) ? $options['text'] : ''; |
| 21 | $this->url = isset($options['url']) ? $options['url'] : ''; |
| 22 | $this->id = isset($options['id']) ? $options['id'] : ''; |
| 23 | $this->class = isset($options['class']) ? $options['class'] : ''; |
| 24 | $this->target = isset($options['target']) ? $options['target'] : ''; |
| 25 | $this->type = $type; |
| 26 | $this->icon = $icon; |
| 27 | |
| 28 | $this->Render(); |
| 29 | } |
| 30 | |
| 31 | private function Render() |
| 32 | { |
| 33 | ?> |
| 34 | <a id="<?= esc_attr($this->id); ?>" <?= !empty($this->url) ? 'href="' . esc_url($this->url) . '"' : ''; ?> <?= !empty($this->target) ? 'target="' . esc_attr($this->target) . '"' : ''; ?>class="superb-addons-template-library-button superb-addons-template-library-button-<?= esc_attr($this->type); ?> <?= esc_attr($this->class); ?>"> |
| 35 | <?php if (!empty($this->text)) { |
| 36 | echo esc_html($this->text); |
| 37 | } |
| 38 | |
| 39 | if (!empty($this->icon)) : ?> |
| 40 | <img src="<?= SUPERBADDONS_ASSETS_PATH . "/img/" . esc_attr($this->icon); ?>" /> |
| 41 | <?php endif; ?> |
| 42 | </a> |
| 43 | <?php |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | class ButtonType |
| 48 | { |
| 49 | const Primary = 'primary'; |
| 50 | const Secondary = 'secondary'; |
| 51 | const Success = 'success'; |
| 52 | const Danger = 'danger'; |
| 53 | } |
| 54 | |
| 55 | class ButtonIcon |
| 56 | { |
| 57 | const Insert = 'plus-circle.svg'; |
| 58 | const Preview = 'preview.svg'; |
| 59 | const ExternalLink = 'external-link.svg'; |
| 60 | } |
| 61 |