diff --git a/src/App/Core/Plugin.php b/src/App/Core/Plugin.php index 4074ca4..1bd9bc6 100644 --- a/src/App/Core/Plugin.php +++ b/src/App/Core/Plugin.php @@ -122,17 +122,7 @@ function ( $actions, $plugin_file, $plugin_data, $context ) { 4 ); - $customEvents = new ScheduledEvent( - 'execute_env_app_events', - function(): void { - $this->handle_events(); - - do_action( 'env_app_events' ); - - // error_log('Custom App event executed at ' . current_time('mysql')); - }, - 'hourly' - ); + $this->add_core_app_events(); } public static function init(): self @@ -204,26 +194,46 @@ public function app_env_admin_bar_menu( $admin_bar ): void ); } - protected function handle_events(): ?bool + protected function add_core_app_events(): void + { + $app_events = new ScheduledEvent( + 'core_app_events', + function(): void { + $this->auto_activate_elementor(); + + do_action( 'env_app_events' ); + + // error_log('Custom App event executed at ' . current_time('mysql')); + }, + 'hourly' + ); + + $app_events->add_app_event(); + } + + protected function auto_activate_elementor(): ?bool { // auto activate elementor. - $activation = env( 'ELEMENTOR_AUTO_ACTIVATION' ); + $auto_activation = env( 'ELEMENTOR_AUTO_ACTIVATION' ); + + if ( ! $auto_activation || false === $auto_activation ) { + return null; + } - if ( $activation && true === $activation ) { - $elementor = new Elementor( env( 'ELEMENTOR_PRO_LICENSE' ) ); + $elementor = new Elementor( env( 'ELEMENTOR_PRO_LICENSE' ) ); - $license_status = $elementor->get_status(); + $license_status = $elementor->get_status(); - if ( 'valid' === $license_status && get_option( '_elementor_pro_license_data' ) ) { - return null; - } - // attemp to activate it. - $elementor->activate(); + if ( 'valid' === $license_status && get_option( '_elementor_pro_license_data' ) ) { + return false; + } - return true; + // activate it. + if ( $elementor->activate() ) { + return true; } - return null; + return false; } protected function security_headers(): void diff --git a/tests/Unit/EncryptionTest.php b/tests/Unit/EncryptionTest.php index 8a30369..e41440c 100644 --- a/tests/Unit/EncryptionTest.php +++ b/tests/Unit/EncryptionTest.php @@ -4,8 +4,8 @@ use Defuse\Crypto\Crypto; use PHPUnit\Framework\TestCase; -use Urisoft\Filesystem; use Urisoft\Encryption; +use Urisoft\Filesystem; /** * @internal @@ -99,19 +99,19 @@ public function test_file_encryption(): void $this->assertEquals($fileContents, $decryptedfile); } - public function test_encrypted_value(): void + public function test_encrypted_value(): void { $secret_data = 'this is my secret license data'; - $_ENV['MY_SUPER_SECRET_VALUE'] = $secret_data; + $_ENV['MY_SUPER_SECRET_VALUE'] = $secret_data; - // passing true will encrypt env() data. - $encrypted_value = env('MY_SUPER_SECRET_VALUE', true ); + // passing true will encrypt env() data. + $encrypted_value = env('MY_SUPER_SECRET_VALUE', true ); - $this->assertNotEmpty( $encrypted_value ); + $this->assertNotEmpty( $encrypted_value ); - $decrypted = $this->encryption->decrypt( $encrypted_value ); + $decrypted = $this->encryption->decrypt( $encrypted_value ); - $this->assertEquals( $decrypted, $secret_data ); + $this->assertEquals( $decrypted, $secret_data ); } }