Skip to content

Commit

Permalink
Scripts were not enqueued if the container was inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Mar 5, 2024
1 parent b10643b commit ba8e282
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions inc/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function gtmkit_load_text_domain(): void {
function gtmkit_frontend_init(): void {
$options = new Options();
$rest_api_server = new RestAPIServer();
$util = new Util( $rest_api_server );
$util = new Util( $options, $rest_api_server );

( new AdminAPI( $options, $util ) )->rest_init();

Expand Down Expand Up @@ -140,7 +140,7 @@ function gtmkit_admin_init(): void {

$options = new Options();
$rest_api_server = new RestAPIServer();
$util = new Util( $rest_api_server );
$util = new Util( $options, $rest_api_server );

Analytics::register( $options, $util );
MetaBox::register( $options );
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Find out about what's new in our [our release post](https://gtmkit.com/gtm-kit-1
#### Enhancements:

#### Bugfixes:
* Scripts were not enqueued if the container was inactive.

#### Other:
* Tested up to WooCommerce 8.7.
Expand Down
19 changes: 17 additions & 2 deletions src/Common/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@
namespace TLA_Media\GTM_Kit\Common;

use TLA_Media\GTM_Kit\Integration\WooCommerce;
use TLA_Media\GTM_Kit\Options;

/**
* Class for common utilities.
*/
final class Util {

/**
* Instance of Options
*
* @var Options
*/
public $options;

/**
* Instance of RestAPIServer
*
Expand All @@ -38,11 +46,13 @@ final class Util {
/**
* Constructor.
*
* @param Options $options Instance of Options.
* @param RestAPIServer $rest_api_server Instance of RestAPIServer.
* @param string $path The plugin path.
* @param string $url The plugin URL.
*/
public function __construct( RestAPIServer $rest_api_server, string $path = GTMKIT_PATH, string $url = GTMKIT_URL ) {
public function __construct( Options $options, RestAPIServer $rest_api_server, string $path = GTMKIT_PATH, string $url = GTMKIT_URL ) {
$this->options = $options;
$this->rest_api_server = $rest_api_server;
$this->asset_path = $path . 'assets/';
$this->asset_url = $url . 'assets/';
Expand Down Expand Up @@ -294,7 +304,12 @@ public function enqueue_script( string $handle, string $script, bool $has_asset_
}

$deps[] = 'gtmkit';
$deps[] = 'gtmkit-container';

$container_active = ( $this->options->get( 'general', 'container_active' ) && apply_filters( 'gtmkit_container_active', true ) );

if ( $container_active ) {
$deps[] = 'gtmkit-container';
}

\wp_enqueue_script( $handle, $this->asset_url . $script, $deps, $ver, $args );
}
Expand Down
2 changes: 1 addition & 1 deletion src/Integration/ContactForm7.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function instance(): ?ContactForm7 {
if ( is_null( self::$instance ) ) {
$options = new Options();
$rest_api_server = new RestAPIServer();
$util = new Util( $rest_api_server );
$util = new Util( $options, $rest_api_server );
self::$instance = new self( $options, $util );
}

Expand Down
2 changes: 1 addition & 1 deletion src/Integration/EasyDigitalDownloads.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function instance(): ?EasyDigitalDownloads {
if ( is_null( self::$instance ) ) {
$options = new Options();
$rest_api_server = new RestAPIServer();
$util = new Util( $rest_api_server );
$util = new Util( $options, $rest_api_server );
self::$instance = new self( $options, $util );
}

Expand Down
2 changes: 1 addition & 1 deletion src/Integration/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function instance(): ?WooCommerce {
if ( is_null( self::$instance ) ) {
$options = new Options();
$rest_api_server = new RestAPIServer();
$util = new Util( $rest_api_server );
$util = new Util( $options, $rest_api_server );
self::$instance = new self( $options, $util );
}

Expand Down

0 comments on commit ba8e282

Please sign in to comment.