wordpress icon indicating copy to clipboard operation
wordpress copied to clipboard

Feature Request: Disable/Hide SendGrid stats widget and page

Open Tailzip opened this issue 8 years ago • 3 comments

Hi,

Would it be possible to add an option to disable/hide the stats widget and page? Something like this: define('SENDGRID_DISABLE_STATS', '1');

Thanks!

Tailzip avatar Apr 18 '17 08:04 Tailzip

Hi. Thanks for your suggestion. We'll keep this in mind for future versions.

However as a temporary solution you can disable stats permissions for your API key. This will prevent the stats widget and page from being displayed if you have the latest version of the plugin installed.

sebastianplesciuc avatar Apr 18 '17 09:04 sebastianplesciuc

Thanks for the quick reply and the tip!

For now, I just removed Wordpress actions for this feature. Not 100% reliable since it's tied to plugin's class and functions names, but it works for now :)

/**
 * Remove SendGrid stats widget/page
 * @return void
 */
function remove_sendgrid_stats() {
  $sendgrid_class = 'Sendgrid_Statistics';
  $sendgrid_actions = [
    'wp_dashboard_setup' => 'add_dashboard_widget',
    'admin_menu' => 'add_statistics_menu',
    'admin_enqueue_scripts' => 'add_headers',
    'wp_ajax_sendgrid_get_stats' => 'get_ajax_statistics'
  ];

  if (class_exists($sendgrid_class)) {
    foreach ($sendgrid_actions as $action => $function_name) {
      remove_action($action, [$sendgrid_class, $function_name]);
    }
  }
}
add_action('init', 'remove_sendgrid_stats');

Tailzip avatar Apr 18 '17 10:04 Tailzip

This works, too:

add_action( 'wp_dashboard_setup', 'my_disable_dashboard_widgets', 999 );
function my_disable_dashboard_widgets() {

	global $wp_meta_boxes;

	// SendGrid...
	unset( $wp_meta_boxes['dashboard']['normal']['high']['sendgrid_statistics_widget'] );
}

ghost avatar May 28 '17 23:05 ghost