Skip to content

Commit

Permalink
Merge pull request #28 from kprajapatii/master
Browse files Browse the repository at this point in the history
Option added to remove plugin data on plugin delete - ADDED
  • Loading branch information
NomadDevs authored Oct 28, 2016
2 parents 946fd21 + 95d672b commit 6b0dc1b
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 1 deletion.
45 changes: 44 additions & 1 deletion bp-compliments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -160,3 +189,17 @@ function bp_compliments_older_version_notice() {

echo '<div class="error"><p>' . $older_version_notice . '</p></div>';
}

/**
* 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;
}
1 change: 1 addition & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
70 changes: 70 additions & 0 deletions uninstall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Uninstall BuddyPress Compliments
*
* Uninstalling BuddyPress Compliments deletes tables and plugin options.
*
* @package BuddyPress_Compliments
* @since 1.0.7
*/

// Exit if accessed directly.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}

global $wpdb, $bp;

if ( get_option( 'geodir_un_buddypress-compliments' ) ) {
$wpdb->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" );
}

0 comments on commit 6b0dc1b

Please sign in to comment.