Skip to content
Snippets Groups Projects
Commit 41e054f4 authored by Erick Hitter's avatar Erick Hitter
Browse files

Introduce singleton to prepare for Block Editor class

parent 458dc748
No related branches found
No related tags found
1 merge request!2Add `core/embed` variation in Block Editor
Pipeline #5148 failed
......@@ -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();
......@@ -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.
*
......
<?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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment