From 59853fbd2746a07c89ed731cc4f9455fc539d5a2 Mon Sep 17 00:00:00 2001 From: Micah Wood Date: Thu, 25 Jan 2024 09:45:54 -0500 Subject: [PATCH] Simplify method --- includes/ComingSoon.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/includes/ComingSoon.php b/includes/ComingSoon.php index d06f58e..0566c51 100644 --- a/includes/ComingSoon.php +++ b/includes/ComingSoon.php @@ -130,18 +130,19 @@ public function on_update_mm_coming_soon( $old_value, $value ) { * @return void */ public function conditionally_trigger_coming_soon_action_hooks( bool $isEnabled ) { + + if ( ! did_action( 'init' ) ) { + add_action( 'init', function () use ( $isEnabled ) { + $this->conditionally_trigger_coming_soon_action_hooks( $isEnabled ); + }, 99 ); + + return; + } + if ( $isEnabled ) { - if ( did_action( 'init' ) ) { - $this->trigger_enabled_action_hook(); - } else { - add_action( 'init', array( $this, 'trigger_enabled_action_hook' ), 99 ); - } + $this->trigger_enabled_action_hook(); } else { - if ( did_action( 'init' ) ) { - $this->trigger_disabled_action_hook(); - } else { - add_action( 'init', array( $this, 'trigger_disabled_action_hook' ), 99 ); - } + $this->trigger_disabled_action_hook(); } }