| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if ( ! class_exists( 'MywpShortcodeAbstractModule' ) ) : |
| 8 |
|
| 9 |
abstract class MywpShortcodeAbstractModule { |
| 10 |
|
| 11 |
private static $instance; |
| 12 |
|
| 13 |
protected static $id; |
| 14 |
|
| 15 |
private function __construct() {} |
| 16 |
|
| 17 |
public static function get_instance() { |
| 18 |
|
| 19 |
$class = get_called_class(); |
| 20 |
|
| 21 |
if ( !isset( self::$instance[ $class ] ) ) { |
| 22 |
|
| 23 |
self::$instance[ $class ] = new static(); |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
return self::$instance[ $class ]; |
| 28 |
|
| 29 |
} |
| 30 |
|
| 31 |
private function __clone() {} |
| 32 |
|
| 33 |
private function __wakeup() {} |
| 34 |
|
| 35 |
public static function init() { |
| 36 |
|
| 37 |
$class = get_called_class(); |
| 38 |
|
| 39 |
if( empty( static::$id ) ) { |
| 40 |
|
| 41 |
$called_text = sprintf( 'class %s' , $class ); |
| 42 |
|
| 43 |
MywpHelper::error_require_message( '"static protected $id"' , $called_text ); |
| 44 |
|
| 45 |
return false; |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
add_filter( 'mywp_shortcode' , array( $class , 'mywp_shortcode' ) ); |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
public static function mywp_shortcode( $shortcodes ) { |
| 54 |
|
| 55 |
$class = get_called_class(); |
| 56 |
|
| 57 |
$shortcodes[ static::$id ] = array( $class , 'do_shortcode' ); |
| 58 |
|
| 59 |
return $shortcodes; |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
public static function do_shortcode( $atts , $content = false , $tag ) { |
| 64 |
|
| 65 |
return $content; |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
endif; |
| 72 |
|