Skip to content

Commit

Permalink
Add Event Inspector deactivation suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Oct 5, 2024
1 parent d55a595 commit 43dbfc0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 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' => '6c0a99b8aca06ca33c76');
<?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');
12 changes: 6 additions & 6 deletions assets/admin/settings.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Admin/AdminAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function set_notification_status(): void {
wp_send_json_error( (object) $notifications_handler->get_notifications_array() );
}
} else {
wp_send_json_error( 'The notification was not found.' );
wp_send_json_error( (object) $notifications_handler->get_notifications_array() ); // The notification was not found.
}
} else {
wp_send_json_error( 'Invalid input.' );
Expand Down
45 changes: 45 additions & 0 deletions src/Admin/Suggestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public static function register( NotificationsHandler $notifications_handler, Pl
add_action( 'admin_init', [ $page, 'suggest_seo_plugin' ] );
add_action( 'admin_init', [ $page, 'detect_conflicting_plugins' ] );
add_action( 'admin_init', [ $page, 'suggest_grandfathered_wishlist' ] );
add_action( 'admin_init', [ $page, 'suggest_inspector_deactivation' ] );
}

/**
Expand All @@ -100,6 +101,26 @@ public function suggest_auto_update(): void {
$this->notifications_handler->add_notification( $notification );
}

/**
* Suggest event inspector deactivation.
*
* @return void
*/
public function suggest_inspector_deactivation(): void {

$notification_id = 'gtmkit-event-inspector';

if ( $this->options->get( 'general', 'event_inspector' ) === false || ( defined( 'WP_ENVIRONMENT_TYPE' ) && WP_ENVIRONMENT_TYPE === 'xlocal' ) ) {
$this->notifications_handler->remove_notification_by_id( $notification_id );
return;
}

if ( $this->options->get( 'general', 'event_inspector' ) === true ) {
$notification = $this->get_suggest_inspector_deactivation_notification( $notification_id );
$this->notifications_handler->add_notification( $notification );
}
}

/**
* Suggest GTM Kit Woo Add-On.
*
Expand Down Expand Up @@ -386,6 +407,30 @@ protected function get_suggest_auto_update_notification( string $notification_id
);
}

/**
* Build suggestion of inspector deactivation notification.
*
* @param string $notification_id The id of the notification to be created.
*
* @return Notification The notification containing the suggested plugin.
*/
protected function get_suggest_inspector_deactivation_notification( string $notification_id ): Notification {

$message = __( 'The event inspector is active and visible to all users. You should not keep it active longer than necessary.', '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,
__( 'Event Inspector:', 'gtm-kit' ),
Notification::PROBLEM
);
}

/**
* New notification.
*
Expand Down

0 comments on commit 43dbfc0

Please sign in to comment.