Posts.php
8 months ago
Shortcode.php
8 months ago
ShortcodeLoader.php
8 months ago
ViewsCount.php
8 months ago
Shortcode.php
45 lines
| 1 | <?php |
| 2 | namespace WordPressPopularPosts\Shortcode; |
| 3 | |
| 4 | abstract class Shortcode { |
| 5 | |
| 6 | /** |
| 7 | * Shortcode tag (eg. footag) |
| 8 | * |
| 9 | * @since 6.3.0 |
| 10 | * @var string |
| 11 | * @access protected |
| 12 | */ |
| 13 | protected $tag; |
| 14 | |
| 15 | /** |
| 16 | * Initializes shortcode. |
| 17 | * |
| 18 | */ |
| 19 | public function init() |
| 20 | { |
| 21 | $this->register(); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Registers the shortcode |
| 26 | * |
| 27 | * @since 6.3.0 |
| 28 | */ |
| 29 | public function register() : void |
| 30 | { |
| 31 | if ( $this->tag ) { |
| 32 | add_shortcode( $this->tag, [$this, 'handle'] ); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Handles the HTML output of the shortcode. |
| 38 | * |
| 39 | * @since 6.3.0 |
| 40 | * @param array $attributes Array of attributes passed to the shortcode |
| 41 | * @return string $html HTML output |
| 42 | */ |
| 43 | abstract public function handle(array $attributes) : string; |
| 44 | } |
| 45 |