Skip to content

Commit

Permalink
Use conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Sep 2, 2024
1 parent ec37fdf commit c4e7548
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 deletions.
3 changes: 2 additions & 1 deletion inc/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use TLA_Media\GTM_Kit\Admin\TemplatesOptionsPage;
use TLA_Media\GTM_Kit\Common\Conditionals\ContactForm7Conditional;
use TLA_Media\GTM_Kit\Common\Conditionals\EasyDigitalDownloadsConditional;
use TLA_Media\GTM_Kit\Common\Conditionals\PremiumConditional;
use TLA_Media\GTM_Kit\Common\Conditionals\WooCommerceConditional;
use TLA_Media\GTM_Kit\Common\RestAPIServer;
use TLA_Media\GTM_Kit\Common\Util;
Expand Down Expand Up @@ -181,7 +182,7 @@ function gtmkit_admin_init(): void {
SetupWizard::register( $options, $util );
GeneralOptionsPage::register( $options, $util );
IntegrationsOptionsPage::register( $options, $util );
if ( ! $util->is_premium() ) {
if ( ! ( new PremiumConditional() )->is_met() ) {
TemplatesOptionsPage::register( $options, $util );
} else {
add_filter( 'plugin_action_links_' . plugin_basename( GTMKIT_FILE ), 'TLA_Media\GTM_Kit\gtmkit_remove_deactivation_link', 11, 1 );
Expand Down
4 changes: 3 additions & 1 deletion src/Admin/IntegrationsOptionsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace TLA_Media\GTM_Kit\Admin;

use TLA_Media\GTM_Kit\Common\Conditionals\PremiumConditional;

/**
* IntegrationsOptionsPage
*/
Expand Down Expand Up @@ -110,7 +112,7 @@ public function localize_script( string $page_slug, string $script_handle ): voi
'currentPage' => $page_slug,
'root' => \esc_url_raw( rest_url() ),
'nonce' => \wp_create_nonce( 'wp_rest' ),
'isPremium' => $this->util->is_premium(),
'isPremium' => ( new PremiumConditional() )->is_met(),
'integrations' => Integrations::get_integrations(),
'dashboardUrl' => \menu_page_url( 'gtmkit_general', false ),
'integrationsUrl' => \menu_page_url( 'gtmkit_integrations', false ),
Expand Down
23 changes: 23 additions & 0 deletions src/Common/Conditionals/PremiumConditional.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* GTM Kit plugin file.
*
* @package GTM Kit
*/

namespace TLA_Media\GTM_Kit\Common\Conditionals;

/**
* Conditional that is only met when WooCommerce is active.
*/
class PremiumConditional implements Conditional {

/**
* Returns `true` when the WooCommerce plugin is installed and activated.
*
* @return bool `true` when the WooCommerce plugin is installed and activated.
*/
public function is_met(): bool {
return \defined( 'GTMKIT_WOO_FILE' );
}
}
9 changes: 0 additions & 9 deletions src/Common/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,4 @@ public function normalize_and_hash_email_address(
}
return $this->normalize_and_hash( $hash_algorithm, $normalized_email, true );
}

/**
* Is premium
*
* @return bool True when is premium.
*/
public function is_premium(): bool {
return \defined( 'GTMKIT_WOO_FILE' );
}
}
1 change: 1 addition & 0 deletions vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\Conditional' => $baseDir . '/src/Common/Conditionals/Conditional.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\ContactForm7Conditional' => $baseDir . '/src/Common/Conditionals/ContactForm7Conditional.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\EasyDigitalDownloadsConditional' => $baseDir . '/src/Common/Conditionals/EasyDigitalDownloadsConditional.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\PremiumConditional' => $baseDir . '/src/Common/Conditionals/PremiumConditional.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\WooCommerceConditional' => $baseDir . '/src/Common/Conditionals/WooCommerceConditional.php',
'TLA_Media\\GTM_Kit\\Common\\RestAPIServer' => $baseDir . '/src/Common/RestAPIServer.php',
'TLA_Media\\GTM_Kit\\Common\\Util' => $baseDir . '/src/Common/Util.php',
Expand Down
1 change: 1 addition & 0 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ComposerStaticInit12fa396dcd6fc263a33fd78c6d8551b8
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\Conditional' => __DIR__ . '/../..' . '/src/Common/Conditionals/Conditional.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\ContactForm7Conditional' => __DIR__ . '/../..' . '/src/Common/Conditionals/ContactForm7Conditional.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\EasyDigitalDownloadsConditional' => __DIR__ . '/../..' . '/src/Common/Conditionals/EasyDigitalDownloadsConditional.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\PremiumConditional' => __DIR__ . '/../..' . '/src/Common/Conditionals/PremiumConditional.php',
'TLA_Media\\GTM_Kit\\Common\\Conditionals\\WooCommerceConditional' => __DIR__ . '/../..' . '/src/Common/Conditionals/WooCommerceConditional.php',
'TLA_Media\\GTM_Kit\\Common\\RestAPIServer' => __DIR__ . '/../..' . '/src/Common/RestAPIServer.php',
'TLA_Media\\GTM_Kit\\Common\\Util' => __DIR__ . '/../..' . '/src/Common/Util.php',
Expand Down
4 changes: 2 additions & 2 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => 'tlamedia/gtm-kit',
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => 'e7e8af8b81c3472d6b3bd90d4dd8e942a5f841df',
'reference' => '2325c9439977b7bce0ef9531f76ff2fea7c7fd79',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'tlamedia/gtm-kit' => array(
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => 'e7e8af8b81c3472d6b3bd90d4dd8e942a5f841df',
'reference' => '2325c9439977b7bce0ef9531f76ff2fea7c7fd79',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down

0 comments on commit c4e7548

Please sign in to comment.