Skip to content

Commit

Permalink
Add debug log notification
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Oct 6, 2024
1 parent 506e493 commit 3c5ce82
Show file tree
Hide file tree
Showing 3 changed files with 59 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' => '062cd7eeb93a06324224');
<?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' => '233f90bb639538fc2ca4');
6 changes: 3 additions & 3 deletions assets/admin/settings.js

Large diffs are not rendered by default.

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

/**
Expand Down Expand Up @@ -143,6 +144,27 @@ public function suggest_container_injection(): void {
$this->notifications_handler->add_notification( $notification );
}

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

$notification_id = 'gtmkit-log-active';

$console_log = $this->options->get( 'general', 'console_log' );
$debug_og = $this->options->get( 'general', 'debug_log' );

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

$notification = $this->get_suggest_log_deactivation_notification( $notification_id, $console_log, $debug_og );
$this->notifications_handler->add_notification( $notification );
}

/**
* Suggest GTM Kit Woo Add-On.
*
Expand Down Expand Up @@ -488,6 +510,39 @@ protected function get_suggest_container_injection_notification( string $notific
);
}

/**
* Build suggestion of container injection notification.
*
* @param string $notification_id The id of the notification to be created.
* @param bool $console_log Console log activation status.
* @param bool $debug_log Debug log activation status.
*
* @return Notification The notification containing the suggested plugin.
*/
protected function get_suggest_log_deactivation_notification( string $notification_id, bool $console_log, bool $debug_log ): Notification {

$message = __( 'Debug logging should not be active in production environments longer than necessary as it affects performance.', 'gtm-kit' );

if ( $console_log ) {
$message .= ' ' . __( 'The browser console log is active.', 'gtm-kit' );
}

if ( $debug_log ) {
$message .= ' ' . __( 'The debug log for "purchase" events is active.', 'gtm-kit' );
}

$url = $this->util->get_admin_page_url() . 'general#/misc';
$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,
__( 'Logging and debugging:', 'gtm-kit' ),
);
}

/**
* New notification.
*
Expand Down

0 comments on commit 3c5ce82

Please sign in to comment.