| @@ 15-97 (lines=83) @@ | ||
| 12 | * |
|
| 13 | * @since 1.0.0 |
|
| 14 | */ |
|
| 15 | final class WordPoints_Module_APIs extends WordPoints_Container_Static { |
|
| 16 | ||
| 17 | /** |
|
| 18 | * @since 1.0.0 |
|
| 19 | */ |
|
| 20 | protected static $instance; |
|
| 21 | ||
| 22 | /** |
|
| 23 | * Initialize the container. |
|
| 24 | * |
|
| 25 | * This function must be called before the container can be used. |
|
| 26 | * |
|
| 27 | * @since 1.0.0 |
|
| 28 | * |
|
| 29 | * @return bool True if the container was initialized, false if it was already. |
|
| 30 | */ |
|
| 31 | public static function init() { |
|
| 32 | ||
| 33 | if ( ! isset( self::$instance ) ) { |
|
| 34 | ||
| 35 | self::$instance = new self; |
|
| 36 | ||
| 37 | self::register_apis(); |
|
| 38 | ||
| 39 | return true; |
|
| 40 | } |
|
| 41 | ||
| 42 | return false; |
|
| 43 | } |
|
| 44 | ||
| 45 | /** |
|
| 46 | * @since 1.0.0 |
|
| 47 | * |
|
| 48 | * @see WordPoints_Container::_add() |
|
| 49 | */ |
|
| 50 | public static function register( $slug, $item, $class = null ) { |
|
| 51 | return self::$instance->_add( $slug, $item, $class ); |
|
| 52 | } |
|
| 53 | ||
| 54 | /** |
|
| 55 | * @since 1.0.0 |
|
| 56 | * |
|
| 57 | * @see WordPoints_Container::_remove() |
|
| 58 | */ |
|
| 59 | public static function deregister( $slug ) { |
|
| 60 | return self::$instance->_remove( $slug ); |
|
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * @since 1.0.0 |
|
| 65 | * |
|
| 66 | * @see WordPoints_Container::_contains() |
|
| 67 | */ |
|
| 68 | public static function is_registered( $slug ) { |
|
| 69 | return self::$instance->_contains( $slug ); |
|
| 70 | } |
|
| 71 | ||
| 72 | /** |
|
| 73 | * @since 1.0.0 |
|
| 74 | * |
|
| 75 | * @see WordPoints_Container::_get() |
|
| 76 | * |
|
| 77 | * @return WordPoints_Module_API[]|WordPoints_Module_API |
|
| 78 | */ |
|
| 79 | public static function get( $slug = null ) { |
|
| 80 | return self::$instance->_get( $slug ); |
|
| 81 | } |
|
| 82 | ||
| 83 | /** |
|
| 84 | * Call the action to register all of the installed APIs. |
|
| 85 | * |
|
| 86 | * @since 1.0.0 |
|
| 87 | */ |
|
| 88 | private static function register_apis() { |
|
| 89 | ||
| 90 | /** |
|
| 91 | * Register the available module APIs. |
|
| 92 | * |
|
| 93 | * @since 1.0.0 |
|
| 94 | */ |
|
| 95 | do_action( 'wordpoints_register_module_apis' ); |
|
| 96 | } |
|
| 97 | } |
|
| 98 | add_action( 'admin_init', 'WordPoints_Module_APIs::init' ); |
|
| 99 | ||
| 100 | /** |
|
| @@ 20-89 (lines=70) @@ | ||
| 17 | * |
|
| 18 | * @see WordPoints_Module_Channel The object used to represent each channel. |
|
| 19 | */ |
|
| 20 | final class WordPoints_Module_Channels extends WordPoints_Container_Static { |
|
| 21 | ||
| 22 | /** |
|
| 23 | * @since 1.0.0 |
|
| 24 | */ |
|
| 25 | protected static $instance; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * @since 1.0.0 |
|
| 29 | */ |
|
| 30 | protected $item_class = 'WordPoints_Module_Channel'; |
|
| 31 | ||
| 32 | /** |
|
| 33 | * Initialize the container. |
|
| 34 | * |
|
| 35 | * This function must be called before the container can be used. |
|
| 36 | * |
|
| 37 | * @since 1.0.0 |
|
| 38 | * |
|
| 39 | * @return bool True if the container was initialized, false if it was already. |
|
| 40 | */ |
|
| 41 | public static function init() { |
|
| 42 | ||
| 43 | if ( ! isset( self::$instance ) ) { |
|
| 44 | ||
| 45 | self::$instance = new self; |
|
| 46 | return true; |
|
| 47 | } |
|
| 48 | ||
| 49 | return false; |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * @since 1.0.0 |
|
| 54 | * |
|
| 55 | * @see WordPoints_Container::_add() |
|
| 56 | */ |
|
| 57 | public static function register( $slug, $item, $class = null ) { |
|
| 58 | return self::$instance->_add( $slug, $item, $class ); |
|
| 59 | } |
|
| 60 | ||
| 61 | /** |
|
| 62 | * @since 1.0.0 |
|
| 63 | * |
|
| 64 | * @see WordPoints_Container::_remove() |
|
| 65 | */ |
|
| 66 | public static function deregister( $slug ) { |
|
| 67 | return self::$instance->_remove( $slug ); |
|
| 68 | } |
|
| 69 | ||
| 70 | /** |
|
| 71 | * @since 1.0.0 |
|
| 72 | * |
|
| 73 | * @see WordPoints_Container::_contains() |
|
| 74 | */ |
|
| 75 | public static function is_registered( $slug ) { |
|
| 76 | return self::$instance->_contains( $slug ); |
|
| 77 | } |
|
| 78 | ||
| 79 | /** |
|
| 80 | * @since 1.0.0 |
|
| 81 | * |
|
| 82 | * @see WordPoints_Container::_get() |
|
| 83 | * |
|
| 84 | * @return WordPoints_Module_Channel[]|WordPoints_Module_Channel |
|
| 85 | */ |
|
| 86 | public static function get( $slug = null ) { |
|
| 87 | return self::$instance->_get( $slug ); |
|
| 88 | } |
|
| 89 | } |
|
| 90 | WordPoints_Module_Channels::init(); |
|
| 91 | ||
| 92 | /** |
|