diff --git a/eth-embed-anchor-fm.php b/eth-embed-anchor-fm.php index 89de486694b5dcff420244f8fceb5b279f0bb01d..7f072d81864754b8b602fd1c3612255fdcb97cfb 100644 --- a/eth-embed-anchor-fm.php +++ b/eth-embed-anchor-fm.php @@ -45,5 +45,7 @@ add_action( 'plugins_loaded', __NAMESPACE__ . '\action_plugins_loaded' ); /** * Load plugin classes. */ +require_once __DIR__ . '/inc/trait-singleton.php'; require_once __DIR__ . '/inc/class-plugin.php'; + Plugin::get_instance(); diff --git a/inc/class-plugin.php b/inc/class-plugin.php index ef8c6d6548d6ed47e7b7747af9934468b09e8329..b93025664bd4f053d6a6a0aeac0fe0d4cc7e266f 100644 --- a/inc/class-plugin.php +++ b/inc/class-plugin.php @@ -11,6 +11,8 @@ namespace ETH_Embed_Anchor_FM; * Class Plugin. */ class Plugin { + use Singleton; + /** * Regex pattern to match URL to be oEmbedded. * @@ -39,34 +41,6 @@ class Plugin { */ private const SHORTCODE_TAG = 'eth_anchor_fm'; - /** - * Singleton. - * - * @var Plugin - */ - private static $_instance = null; - - /** - * Implement singleton. - * - * @return Plugin - */ - public static function get_instance(): Plugin { - if ( ! is_a( self::$_instance, __CLASS__ ) ) { - self::$_instance = new self(); - self::$_instance->_setup(); - } - - return self::$_instance; - } - - /** - * Silence is golden! - */ - private function __construct() { - // Add nothing here. - } - /** * Register hooks. * diff --git a/inc/trait-singleton.php b/inc/trait-singleton.php new file mode 100644 index 0000000000000000000000000000000000000000..23a9cdec13073cfc52bf885e90b44e2249623f45 --- /dev/null +++ b/inc/trait-singleton.php @@ -0,0 +1,48 @@ +<?php +/** + * Singleton trait. + * + * @package ETH_Embed_Anchor_FM + */ + +namespace ETH_Embed_Anchor_FM; + +/** + * Trait Singleton. + */ +trait Singleton { + /** + * Singleton. + * + * @var self + */ + private static $_instance = null; + + /** + * Implement singleton. + * + * @return self + */ + public static function get_instance(): self { + if ( ! is_a( self::$_instance, __CLASS__ ) ) { + self::$_instance = new self(); + self::$_instance->_setup(); + } + + return self::$_instance; + } + + /** + * Silence is golden! + */ + private function __construct() { + // Add nothing here. + } + + /** + * Register hooks. + * + * @return void + */ + abstract function _setup(): void; +}