Skip to content

Commit

Permalink
Add standardised conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Aug 30, 2024
1 parent bc5a603 commit cea9041
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 7 deletions.
9 changes: 6 additions & 3 deletions inc/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
use TLA_Media\GTM_Kit\Admin\NotificationsHandler;
use TLA_Media\GTM_Kit\Admin\SetupWizard;
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\WoocommerceConditional;
use TLA_Media\GTM_Kit\Common\RestAPIServer;
use TLA_Media\GTM_Kit\Common\Util;
use TLA_Media\GTM_Kit\Frontend\BasicDatalayerData;
Expand Down Expand Up @@ -129,13 +132,13 @@ function gtmkit_frontend_init(): void {
BasicDatalayerData::register( $options );
UserData::register( $options );

if ( $options->get( 'integrations', 'woocommerce_integration' ) && function_exists( 'WC' ) ) {
if ( $options->get( 'integrations', 'woocommerce_integration' ) && ( new WoocommerceConditional() )->is_met() ) {
WooCommerce::register( $options, $util );
}
if ( $options->get( 'integrations', 'cf7_integration' ) && class_exists( 'WPCF7' ) ) {
if ( $options->get( 'integrations', 'cf7_integration' ) && ( new ContactForm7Conditional() )->is_met() ) {
ContactForm7::register( $options, $util );
}
if ( $options->get( 'integrations', 'edd_integration' ) && class_exists( 'EDD_Requirements_Check' ) ) {
if ( $options->get( 'integrations', 'edd_integration' ) && ( new EasyDigitalDownloadsConditional() )->is_met() ) {
EasyDigitalDownloads::register( $options, $util );
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/Common/Conditionals/Conditional.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* GTM Kit plugin file.
*
* @package GTM Kit
*/

namespace TLA_Media\GTM_Kit\Common\Conditionals;

/**
* Conditional interface.
*/
interface Conditional {

/**
* Returns whether this conditional is met.
*
* @return bool Whether the conditional is met.
*/
public function is_met(): bool;
}
23 changes: 23 additions & 0 deletions src/Common/Conditionals/ContactForm7Conditional.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 Easy Digital Downloads is active.
*/
class ContactForm7Conditional implements Conditional {

/**
* Returns `true` when the Contact Form 7 plugin is installed and activated.
*
* @return bool `true` when the Contact Form 7 plugin is installed and activated.
*/
public function is_met(): bool {
return \class_exists( 'CF7' );
}
}
23 changes: 23 additions & 0 deletions src/Common/Conditionals/EasyDigitalDownloadsConditional.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 Easy Digital Downloads is active.
*/
class EasyDigitalDownloadsConditional implements Conditional {

/**
* Returns `true` when the Easy Digital Downloads plugin is installed and activated.
*
* @return bool `true` when the Easy Digital Downloads plugin is installed and activated.
*/
public function is_met(): bool {
return \class_exists( 'Easy_Digital_Downloads' );
}
}
23 changes: 23 additions & 0 deletions src/Common/Conditionals/WoocommerceConditional.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 WoocommerceConditional 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 \function_exists( 'WC' );
}
}
5 changes: 4 additions & 1 deletion vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
'TLA_Media\\GTM_Kit\\Admin\\AdminAPI' => $baseDir . '/src/Admin/AdminAPI.php',
'TLA_Media\\GTM_Kit\\Admin\\Analytics' => $baseDir . '/src/Admin/Analytics.php',
'TLA_Media\\GTM_Kit\\Admin\\AssetsTrait' => $baseDir . '/src/Admin/AssetsTrait.php',
'TLA_Media\\GTM_Kit\\Admin\\Check' => $baseDir . '/src/Admin/Check.php',
'TLA_Media\\GTM_Kit\\Admin\\GeneralOptionsPage' => $baseDir . '/src/Admin/GeneralOptionsPage.php',
'TLA_Media\\GTM_Kit\\Admin\\HelpOptionsPage' => $baseDir . '/src/Admin/HelpOptionsPage.php',
'TLA_Media\\GTM_Kit\\Admin\\Integrations' => $baseDir . '/src/Admin/Integrations.php',
Expand All @@ -21,6 +20,10 @@
'TLA_Media\\GTM_Kit\\Admin\\NotificationsHandler' => $baseDir . '/src/Admin/NotificationsHandler.php',
'TLA_Media\\GTM_Kit\\Admin\\SetupWizard' => $baseDir . '/src/Admin/SetupWizard.php',
'TLA_Media\\GTM_Kit\\Admin\\TemplatesOptionsPage' => $baseDir . '/src/Admin/TemplatesOptionsPage.php',
'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\\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',
'TLA_Media\\GTM_Kit\\Frontend\\BasicDatalayerData' => $baseDir . '/src/Frontend/BasicDatalayerData.php',
Expand Down
5 changes: 4 additions & 1 deletion vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class ComposerStaticInit12fa396dcd6fc263a33fd78c6d8551b8
'TLA_Media\\GTM_Kit\\Admin\\AdminAPI' => __DIR__ . '/../..' . '/src/Admin/AdminAPI.php',
'TLA_Media\\GTM_Kit\\Admin\\Analytics' => __DIR__ . '/../..' . '/src/Admin/Analytics.php',
'TLA_Media\\GTM_Kit\\Admin\\AssetsTrait' => __DIR__ . '/../..' . '/src/Admin/AssetsTrait.php',
'TLA_Media\\GTM_Kit\\Admin\\Check' => __DIR__ . '/../..' . '/src/Admin/Check.php',
'TLA_Media\\GTM_Kit\\Admin\\GeneralOptionsPage' => __DIR__ . '/../..' . '/src/Admin/GeneralOptionsPage.php',
'TLA_Media\\GTM_Kit\\Admin\\HelpOptionsPage' => __DIR__ . '/../..' . '/src/Admin/HelpOptionsPage.php',
'TLA_Media\\GTM_Kit\\Admin\\Integrations' => __DIR__ . '/../..' . '/src/Admin/Integrations.php',
Expand All @@ -36,6 +35,10 @@ class ComposerStaticInit12fa396dcd6fc263a33fd78c6d8551b8
'TLA_Media\\GTM_Kit\\Admin\\NotificationsHandler' => __DIR__ . '/../..' . '/src/Admin/NotificationsHandler.php',
'TLA_Media\\GTM_Kit\\Admin\\SetupWizard' => __DIR__ . '/../..' . '/src/Admin/SetupWizard.php',
'TLA_Media\\GTM_Kit\\Admin\\TemplatesOptionsPage' => __DIR__ . '/../..' . '/src/Admin/TemplatesOptionsPage.php',
'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\\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',
'TLA_Media\\GTM_Kit\\Frontend\\BasicDatalayerData' => __DIR__ . '/../..' . '/src/Frontend/BasicDatalayerData.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' => '9872766de93b13886fed8aeb86dd95b5affc21a1',
'reference' => '73df48d7704e2d9ef8e7bb375cccfc5e1bdeea52',
'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' => '9872766de93b13886fed8aeb86dd95b5affc21a1',
'reference' => '73df48d7704e2d9ef8e7bb375cccfc5e1bdeea52',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down

0 comments on commit cea9041

Please sign in to comment.