diff --git a/bp-compliments.php b/bp-compliments.php
index d647d75..787e94b 100644
--- a/bp-compliments.php
+++ b/bp-compliments.php
@@ -120,8 +120,37 @@ function bp_compliments_activate() {
dbDelta( $sql );
update_option( 'bp_compliments_version', BP_COMPLIMENTS_VER );
}
+
+ add_option( 'bp_compliments_activation_redirect', 1 );
+}
+
+if ( is_admin() ) {
+ register_activation_hook( __FILE__, 'bp_compliments_activate' );
+ register_deactivation_hook( __FILE__, 'bp_compliments_deactivate' );
+ add_filter( 'geodir_plugins_uninstall_settings', 'bp_compliments_uninstall_settings', 10, 1 );
+ add_action( 'admin_init', 'bp_compliments_activation_redirect' );
+}
+
+/**
+ * Plugin deactivation hook.
+ *
+ * @since 1.0.7
+ */
+function bp_compliments_deactivate() {
+ // Plugin deactivation stuff.
+}
+
+/**
+ * Redirects user to BuddyPress Compliments settings page after plugin activation.
+ *
+ * @since 1.0.7
+ */
+function bp_compliments_activation_redirect() {
+ if ( get_option( 'bp_compliments_activation_redirect', false ) ) {
+ delete_option( 'bp_compliments_activation_redirect' );
+ wp_redirect( admin_url( 'admin.php?page=bp-compliment-settings' ) );
+ }
}
-register_activation_hook( __FILE__, 'bp_compliments_activate' );
/**
* Custom text domain loader.
@@ -160,3 +189,17 @@ function bp_compliments_older_version_notice() {
echo '
' . $older_version_notice . '
';
}
+
+/**
+ * Add the plugin to uninstall settings.
+ *
+ * @since 1.0.7
+ *
+ * @return array $settings the settings array.
+ * @return array The modified settings.
+ */
+function bp_compliments_uninstall_settings($settings) {
+ $settings[] = plugin_basename(dirname(__FILE__));
+
+ return $settings;
+}
diff --git a/change_log.txt b/change_log.txt
index 18734a7..e8945c5 100644
--- a/change_log.txt
+++ b/change_log.txt
@@ -1,6 +1,7 @@
v1.0.7
Send compliment button can be displayed in /members page - ADDED
PHP undefined notices in wordpress admin - FIXED
+Option added to remove plugin data on plugin delete - ADDED
v1.0.6
Notification incorrect from email - FIXED
diff --git a/uninstall.php b/uninstall.php
new file mode 100644
index 0000000..c06d9a0
--- /dev/null
+++ b/uninstall.php
@@ -0,0 +1,70 @@
+hide_errors();
+
+ if ( !defined( 'BP_COMPLIMENTS_VER' ) ) {
+ // Load plugin file.
+ include_once( 'bp-compliments.php' );
+ }
+
+ if ( !( !empty( $bp ) && !empty( $bp->table_prefix ) ) ) {
+ /** This action is documented in bp-compliments.php */
+ $table_prefix = apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix );
+ } else {
+ $table_prefix = $bp->table_prefix;
+ }
+
+ /* Delete all terms & taxonomies. */
+ $taxonomies = array( 'compliment' );
+
+ foreach ( array_unique( array_filter( $taxonomies ) ) as $taxonomy ) {
+ $terms = $wpdb->get_results( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('%s') ORDER BY t.name ASC", $taxonomy ) );
+
+ // Delete terms.
+ if ( $terms ) {
+ foreach ( $terms as $term ) {
+ $wpdb->delete( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => $term->term_taxonomy_id ) );
+ $wpdb->delete( $wpdb->terms, array( 'term_id' => $term->term_id ) );
+
+ delete_option( 'taxonomy_' . $term->term_id );
+ }
+ }
+
+ // Delete taxonomy.
+ $wpdb->delete( $wpdb->term_taxonomy, array( 'taxonomy' => $taxonomy ), array( '%s' ) );
+
+ delete_option( $taxonomy . '_children' );
+ }
+
+ // Delete options
+ delete_option( 'bp_compliment_singular_name' );
+ delete_option( 'bp_compliment_plural_name' );
+ delete_option( 'bp_compliment_slug' );
+ delete_option( 'bp_compliment_can_see_others_comp' );
+ delete_option( 'bp_compliment_member_dir_btn' );
+ delete_option( 'bp_compliment_can_delete' );
+ delete_option( 'bp_compliment_enable_activity' );
+ delete_option( 'bp_compliment_enable_notifications' );
+ delete_option( 'bp_comp_per_page' );
+ delete_option( 'bp_comp_custom_css' );
+ delete_option( 'bp_compliments_version' );
+
+ // Drop table.
+ $wpdb->query( "DROP TABLE IF EXISTS " . $table_prefix . "bp_compliments" );
+}
\ No newline at end of file