Verified Commit 0378f23f authored by Erick Hitter's avatar Erick Hitter
Browse files

Update remaining classes to use abstract

Also fixes the abstract class to support multiple classes. 🤦
parent 521d6325
......@@ -6,18 +6,18 @@ abstract class Singleton {
/**
* Class instance
*/
private static $__instance = null;
private static $__instances = array();
public static function instance() {
$caller = get_called_class();
if ( ! is_a( self::$__instance, $caller ) ) {
self::$__instance = new $caller();
if ( ! isset( self::$__instances[ $caller ] ) ) {
self::$__instances[ $caller ] = new $caller();
self::$__instance->class_init();
self::$__instances[ $caller ]->class_init();
}
return self::$__instance;
return self::$__instances[ $caller ];
}
protected function __construct() {}
......
......@@ -2,20 +2,7 @@
namespace WP_Cron_Control_Revisited;
class Cron_Options_CPT {
/**
* Class instance
*/
private static $__instance = null;
public static function instance() {
if ( ! is_a( self::$__instance, __CLASS__ ) ) {
self::$__instance = new self;
}
return self::$__instance;
}
class Cron_Options_CPT extends Singleton {
/**
* PLUGIN SETUP
*/
......@@ -29,7 +16,7 @@ class Cron_Options_CPT {
/**
* Register hooks
*/
private function __construct() {
protected function class_init() {
// Data storage
add_action( 'init', array( $this, 'register_post_type' ) );
......
......@@ -2,20 +2,7 @@
namespace WP_Cron_Control_Revisited;
class Internal_Events {
/**
* Class instance
*/
private static $__instance = null;
public static function instance() {
if ( ! is_a( self::$__instance, __CLASS__ ) ) {
self::$__instance = new self;
}
return self::$__instance;
}
class Internal_Events extends Singleton {
/**
* PLUGIN SETUP
*/
......@@ -29,7 +16,7 @@ class Internal_Events {
/**
* Register hooks
*/
private function __construct() {
protected function class_init() {
$this->prepare();
add_action( 'wp_loaded', array( $this, 'schedule_internal_events' ) );
......
......@@ -12,20 +12,7 @@ namespace WP_Cron_Control_Revisited;
require __DIR__ . '/includes/abstract-class-singleton.php';
class Main {
/**
* Class instance
*/
private static $__instance = null;
public static function instance() {
if ( ! is_a( self::$__instance, __CLASS__ ) ) {
self::$__instance = new self;
}
return self::$__instance;
}
class Main extends Singleton {
/**
* PLUGIN SETUP
*/
......@@ -48,7 +35,7 @@ class Main {
/**
* Register hooks
*/
private function __construct() {
protected function class_init() {
// For now, leave WP-CLI alone
if ( defined( 'WP_CLI' ) && WP_CLI ) {
return;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment