| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
abstract class Brizy_Shortcode_AbstractShortcode { |
| 5 |
|
| 6 |
const BRIZY_SHORTCODES_PREFIX = 'brizy_'; |
| 7 |
const BRIZY_SHORTCODES_ACTION_PREFIX = 'brizy_shortcode_'; |
| 8 |
const BRIZY_SHORTCODES_FILTER_PREFIX = 'brizy_shortcode_filter_'; |
| 9 |
|
| 10 |
/** |
| 11 |
* Get shortcode name |
| 12 |
* |
| 13 |
* @return string |
| 14 |
*/ |
| 15 |
abstract public function getName(); |
| 16 |
|
| 17 |
/** |
| 18 |
* @param $atts |
| 19 |
* @param null $content |
| 20 |
* |
| 21 |
* @return mixed |
| 22 |
*/ |
| 23 |
abstract public function render( $atts, $content = null ); |
| 24 |
|
| 25 |
/** |
| 26 |
* @param $atts |
| 27 |
* @param null $content |
| 28 |
* |
| 29 |
* @return string |
| 30 |
*/ |
| 31 |
final public function masterRender( $atts, $content = null ) { |
| 32 |
ob_start(); |
| 33 |
|
| 34 |
do_action( $this->getBeforeActionName() ); |
| 35 |
|
| 36 |
echo apply_filters( $this->getFilterName(), $this->render( $atts, $content ) ); |
| 37 |
|
| 38 |
do_action( $this->getAfterActionName() ); |
| 39 |
|
| 40 |
return ob_get_clean(); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Brizy_Shortcode_AbstractShortcode constructor. |
| 45 |
*/ |
| 46 |
public function __construct() { |
| 47 |
add_shortcode( $this->getShortCodeId(), array( $this, 'masterRender' ) ); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* @return string |
| 52 |
*/ |
| 53 |
private function getShortCodeId() { |
| 54 |
return self::BRIZY_SHORTCODES_PREFIX . $this->getName(); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* @return string |
| 59 |
*/ |
| 60 |
private function getBeforeActionName() { |
| 61 |
return self::BRIZY_SHORTCODES_ACTION_PREFIX . 'before_' . $this->getName(); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* @return string |
| 66 |
*/ |
| 67 |
private function getAfterActionName() { |
| 68 |
return self::BRIZY_SHORTCODES_ACTION_PREFIX . 'after_' . $this->getName(); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* @return string |
| 73 |
*/ |
| 74 |
private function getFilterName() { |
| 75 |
return self::BRIZY_SHORTCODES_FILTER_PREFIX . $this->getName(); |
| 76 |
} |
| 77 |
} |