Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing GTM container notification #580

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading