| @@ -1,84 +1,84 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Abstract Class for Shortcodes. | |
| 4 | - * | |
| 5 | - * @author ThimPress | |
| 6 | - * @category Abstract | |
| 7 | - * @package Learnpress/Classes | |
| 8 | - * @version 3.0.0 | |
| 9 | - */ | |
| 10 | - | |
| 11 | -/** | |
| 12 | - * Prevent loading this file directly | |
| 13 | - */ | |
| 14 | -defined( 'ABSPATH' ) || exit(); | |
| 15 | - | |
| 16 | - | |
| 17 | -if ( ! class_exists( 'LP_Abstract_Shortcode' ) ) { | |
| 18 | - | |
| 19 | - /** | |
| 20 | - * Class LP_Abstract_Shortcode | |
| 21 | - */ | |
| 22 | - abstract class LP_Abstract_Shortcode { | |
| 23 | - /** | |
| 24 | - * Shortcode attributes. | |
| 25 | - * | |
| 26 | - * @var array|null | |
| 27 | - */ | |
| 28 | - protected $_atts = null; | |
| 29 | - | |
| 30 | - /** | |
| 31 | - * @var string | |
| 32 | - */ | |
| 33 | - protected $_name = ''; | |
| 34 | - | |
| 35 | - /** | |
| 36 | - * LP_Abstract_Shortcode constructor. | |
| 37 | - * | |
| 38 | - * @param mixed $atts | |
| 39 | - */ | |
| 40 | - public function __construct( $atts = '' ) { | |
| 41 | - $this->_atts = (array) $atts; | |
| 42 | - } | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * Return content of the shortcode. | |
| 46 | - * | |
| 47 | - * @return mixed | |
| 48 | - */ | |
| 49 | - abstract function output(); | |
| 50 | - | |
| 51 | - /** | |
| 52 | - * Get shortcode attributes. | |
| 53 | - * | |
| 54 | - * @return mixed | |
| 55 | - */ | |
| 56 | - public function get_atts() { | |
| 57 | - return apply_filters( 'learn-press/shortcode-' . $this->get_name() . '-atts', $this->_atts ); | |
| 58 | - } | |
| 59 | - | |
| 60 | - /** | |
| 61 | - * Get default name of shortcode (without prefix learn_press_) if it is not set. | |
| 62 | - * | |
| 63 | - * @return mixed|string | |
| 64 | - */ | |
| 65 | - public function get_name() { | |
| 66 | - if ( ! $this->_name ) { | |
| 67 | - if ( preg_match( '~^lp_(.*)_shortcode$~i', get_class( $this ), $m ) ) { | |
| 68 | - $this->_name = preg_replace( '~_~', '-', strtolower( $m[1] ) ); | |
| 69 | - } | |
| 70 | - } | |
| 71 | - | |
| 72 | - return $this->_name; | |
| 73 | - } | |
| 74 | - | |
| 75 | - /** | |
| 76 | - * Convert to string | |
| 77 | - * | |
| 78 | - * @return mixed | |
| 79 | - */ | |
| 80 | - public function __toString() { | |
| 81 | - return $this->output(); | |
| 82 | - } | |
| 83 | - } | |
| 84 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Abstract Class for Shortcodes. | |
| 4 | + * | |
| 5 | + * @author ThimPress | |
| 6 | + * @category Abstract | |
| 7 | + * @package Learnpress/Classes | |
| 8 | + * @version 3.0.0 | |
| 9 | + */ | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * Prevent loading this file directly | |
| 13 | + */ | |
| 14 | +defined( 'ABSPATH' ) || exit(); | |
| 15 | + | |
| 16 | + | |
| 17 | +if ( ! class_exists( 'LP_Abstract_Shortcode' ) ) { | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * Class LP_Abstract_Shortcode | |
| 21 | + */ | |
| 22 | + abstract class LP_Abstract_Shortcode { | |
| 23 | + /** | |
| 24 | + * Shortcode attributes. | |
| 25 | + * | |
| 26 | + * @var array|null | |
| 27 | + */ | |
| 28 | + protected $_atts = null; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * @var string | |
| 32 | + */ | |
| 33 | + protected $_name = ''; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * LP_Abstract_Shortcode constructor. | |
| 37 | + * | |
| 38 | + * @param mixed $atts | |
| 39 | + */ | |
| 40 | + public function __construct( $atts = '' ) { | |
| 41 | + $this->_atts = (array) $atts; | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Return content of the shortcode. | |
| 46 | + * | |
| 47 | + * @return mixed | |
| 48 | + */ | |
| 49 | + abstract function output(); | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * Get shortcode attributes. | |
| 53 | + * | |
| 54 | + * @return mixed | |
| 55 | + */ | |
| 56 | + public function get_atts() { | |
| 57 | + return apply_filters( 'learn-press/shortcode-' . $this->get_name() . '-atts', $this->_atts ); | |
| 58 | + } | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * Get default name of shortcode (without prefix learn_press_) if it is not set. | |
| 62 | + * | |
| 63 | + * @return mixed|string | |
| 64 | + */ | |
| 65 | + public function get_name() { | |
| 66 | + if ( ! $this->_name ) { | |
| 67 | + if ( preg_match( '~^lp_(.*)_shortcode$~i', get_class( $this ), $m ) ) { | |
| 68 | + $this->_name = preg_replace( '~_~', '-', strtolower( $m[1] ) ); | |
| 69 | + } | |
| 70 | + } | |
| 71 | + | |
| 72 | + return $this->_name; | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * Convert to string | |
| 77 | + * | |
| 78 | + * @return mixed | |
| 79 | + */ | |
| 80 | + public function __toString() { | |
| 81 | + return $this->output(); | |
| 82 | + } | |
| 83 | + } | |
| 84 | +} | |