Skip to content

Commit

Permalink
Add missing GTM container notification
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Oct 6, 2024
1 parent cf39a89 commit 506e493
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
2 changes: 1 addition & 1 deletion assets/admin/settings.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-primitives'), 'version' => 'eefd7386e2472739e9b3');
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-primitives'), 'version' => '062cd7eeb93a06324224');
2 changes: 1 addition & 1 deletion assets/admin/settings.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/admin/wizard.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => 'acf6e4eaedadb01491fd');
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'react-jsx-runtime', 'wp-api-fetch', 'wp-components', 'wp-element', 'wp-i18n'), 'version' => '83d9f86fcf59c086290d');
2 changes: 1 addition & 1 deletion assets/admin/wizard.js

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions src/Admin/Suggestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static function register( NotificationsHandler $notifications_handler, Pl
add_action( 'admin_init', [ $page, 'detect_conflicting_plugins' ] );
add_action( 'admin_init', [ $page, 'suggest_grandfathered_wishlist' ] );
add_action( 'admin_init', [ $page, 'suggest_inspector_deactivation' ] );
add_action( 'admin_init', [ $page, 'suggest_container_injection' ] );
}

/**
Expand Down Expand Up @@ -121,6 +122,27 @@ public function suggest_inspector_deactivation(): void {
}
}

/**
* Suggest container injection
*
* @return void
*/
public function suggest_container_injection(): void {

$notification_id = 'gtmkit-container-injection';

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

if ( ( $container_active && $gtm_id ) || ( defined( 'WP_ENVIRONMENT_TYPE' ) && WP_ENVIRONMENT_TYPE === 'local' ) ) {
$this->notifications_handler->remove_notification_by_id( $notification_id );
return;
}

$notification = $this->get_suggest_container_injection_notification( $notification_id, $container_active, $gtm_id );
$this->notifications_handler->add_notification( $notification );
}

/**
* Suggest GTM Kit Woo Add-On.
*
Expand Down Expand Up @@ -431,6 +453,41 @@ protected function get_suggest_inspector_deactivation_notification( string $noti
);
}


/**
* Build suggestion of container injection notification.
*
* @param string $notification_id The id of the notification to be created.
* @param bool $container_active The container activation status.
* @param string $gtm_id The GTM Container ID.
*
* @return Notification The notification containing the suggested plugin.
*/
protected function get_suggest_container_injection_notification( string $notification_id, bool $container_active, string $gtm_id ): Notification {

$message = __( 'The Google Tag Manager container is not injected.', 'gtm-kit' );

if ( ! $container_active ) {
$message .= ' ' . __( 'The "Inject Container Code" option is not enabled.', 'gtm-kit' );
}

if ( ! $gtm_id ) {
$message .= ' ' . __( 'The "GTM Container ID" value is empty.', 'gtm-kit' );
}

$url = $this->util->get_admin_page_url() . 'general#/container';
$message .= ' <a href="' . $url . '" class="gtmkit-text-color-primary gtmkit hover:gtmkit-underline gtmkit-font-bold">';
$message .= __( 'Go to settings', 'gtm-kit' );
$message .= '</a>';

return $this->new_notification(
$notification_id,
$message,
__( 'GTM Container Injection:', 'gtm-kit' ),
Notification::PROBLEM
);
}

/**
* New notification.
*
Expand Down

0 comments on commit 506e493

Please sign in to comment.