From 648c4cef6f008e33d63ae8f91ef65069bfaed508 Mon Sep 17 00:00:00 2001 From: Django Doucet Date: Sat, 1 Feb 2020 01:40:49 -0500 Subject: [PATCH] Unregister authorized widgets if tokens empty Delete widget options on uninstall --- fediembedi.php | 12 +++++++++--- uninstall.php | 19 ++++++++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/fediembedi.php b/fediembedi.php index d7c59a0..356b6ee 100644 --- a/fediembedi.php +++ b/fediembedi.php @@ -132,15 +132,21 @@ class FediConfig */ public function fediembedi_widget() { //Mastodon - include(plugin_dir_path(__FILE__) . 'fediembedi-mastodon-widget.php' );// + include(plugin_dir_path(__FILE__) . 'fediembedi-mastodon-widget.php' ); register_widget( 'FediEmbedi_Mastodon' ); + if(empty(get_option('fediembedi-mastodon-token'))){ + unregister_widget( 'FediEmbedi_Mastodon' ); + } //Pixelfed - include(plugin_dir_path(__FILE__) . 'fediembedi-pixelfed-widget.php' );// + include(plugin_dir_path(__FILE__) . 'fediembedi-pixelfed-widget.php' ); register_widget( 'FediEmbedi_Pixelfed' ); + if(empty(get_option('fediembedi-pixelfed-token'))){ + unregister_widget( 'FediEmbedi_Pixelfed' ); + } //PeerTube - include(plugin_dir_path(__FILE__) . 'fediembedi-peertube-widget.php' );// + include(plugin_dir_path(__FILE__) . 'fediembedi-peertube-widget.php' ); register_widget( 'FediEmbedi_PeerTube' ); } diff --git a/uninstall.php b/uninstall.php index 020c0cd..da735c1 100644 --- a/uninstall.php +++ b/uninstall.php @@ -3,9 +3,26 @@ if (!defined('WP_UNINSTALL_PLUGIN')) { die; } +delete_option( 'fediembedi-notice' ); + +//original options < 0.8.0 delete_option( 'fediembedi-client-id' ); delete_option( 'fediembedi-client-secret' ); delete_option( 'fediembedi-token' ); delete_option( 'fediembedi-instance' ); delete_option( 'fediembedi-instance-info' ); -delete_option( 'fediembedi-notice' ); +delete_option( 'fediembedi-instance-type' ); + +//pixelfed +delete_option('fediembedi-pixelfed-client-id'); +delete_option('fediembedi-pixelfed-client-secret'); +delete_option('fediembedi-pixelfed-token'); +delete_option('fediembedi-pixelfed-instance'); +delete_option('fediembedi-pixelfed-token'); + +//mastodon +delete_option('fediembedi-mastodon-client-id'); +delete_option('fediembedi-mastodon-client-secret'); +delete_option('fediembedi-mastodon-token'); +delete_option('fediembedi-mastodon-instance'); +delete_option('fediembedi-mastodon-token');