Skip to content

Commit

Permalink
Merge pull request #22 from wp-stream/remove-uninstall
Browse files Browse the repository at this point in the history
Remove uninstall functionality, no longer needed
  • Loading branch information
lukecarbis committed Aug 7, 2014
2 parents 095ecb6 + 86689b7 commit eb10a14
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 135 deletions.
111 changes: 2 additions & 109 deletions classes/class-wp-stream-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ public static function load() {
// Reset Streams settings
add_action( 'wp_ajax_wp_stream_defaults', array( __CLASS__, 'wp_ajax_defaults' ) );

// Uninstall Streams and Deactivate plugin
add_action( 'wp_ajax_wp_stream_uninstall', array( __CLASS__, 'uninstall_plugin' ) );

// Ajax authors list
add_action( 'wp_ajax_wp_stream_filters', array( __CLASS__, 'ajax_filters' ) );

Expand Down Expand Up @@ -308,8 +305,7 @@ public static function admin_enqueue_scripts( $hook ) {
'wp_stream',
array(
'i18n' => array(
'confirm_defaults' => __( 'Are you sure you want to reset all site settings to default? This cannot be undone.', 'stream' ),
'confirm_uninstall' => __( 'Are you sure you want to uninstall and deactivate Stream? This will delete all Stream tables from the database and cannot be undone.', 'stream' ),
'confirm_defaults' => __( 'Are you sure you want to reset all site settings to default? This cannot be undone.', 'stream' ),
),
'gmt_offset' => get_option( 'gmt_offset' ),
'current_screen' => $hook,
Expand Down Expand Up @@ -432,7 +428,6 @@ public static function admin_menu_css() {
*/
public static function plugin_action_links( $links, $file ) {
if ( plugin_basename( WP_STREAM_DIR . 'stream.php' ) === $file ) {

// Don't show links in Network Admin if Stream isn't network enabled
if ( is_network_admin() && is_multisite() && ! is_plugin_active_for_network( WP_STREAM_PLUGIN ) ) {
return $links;
Expand All @@ -443,16 +438,8 @@ public static function plugin_action_links( $links, $file ) {
} else {
$admin_page_url = add_query_arg( array( 'page' => self::SETTINGS_PAGE_SLUG ), admin_url( self::ADMIN_PARENT_PAGE ) );
}
$links[] = sprintf( '<a href="%s">%s</a>', esc_url( $admin_page_url ), esc_html__( 'Settings', 'default' ) );

$url = add_query_arg(
array(
'action' => 'wp_stream_uninstall',
'wp_stream_nonce' => wp_create_nonce( 'stream_nonce' ),
),
admin_url( 'admin-ajax.php' )
);
$links[] = sprintf( '<span id="wp_stream_uninstall" class="delete"><a href="%s">%s</a></span>', esc_url( $url ), esc_html__( 'Uninstall', 'stream' ) );
$links[] = sprintf( '<a href="%s">%s</a>', esc_url( $admin_page_url ), esc_html__( 'Settings', 'default' ) );
}

return $links;
Expand Down Expand Up @@ -539,42 +526,6 @@ public static function get_testimonials() {
return $testimonials;
}

/**
* Register a routine to be called when stream or a stream connector has been updated
* It works by comparing the current version with the version previously stored in the database.
*
* @param string $file A reference to the main plugin file
* @param string $callback The function to run when the hook is called.
* @param string $version The version to which the plugin is updating.
* @return void
*/
public static function register_update_hook( $file, $callback, $version ) {
if ( ! is_admin() ) {
return;
}

$plugin = plugin_basename( $file );

if ( is_plugin_active_for_network( $plugin ) ) {
$current_versions = get_site_option( WP_Stream_Install_WPDB::OPTION_KEY . '_connectors', array() );
$network = true;
} elseif ( is_plugin_active( $plugin ) ) {
$current_versions = get_option( WP_Stream_Install_WPDB::OPTION_KEY . '_connectors', array() );
$network = false;
} else {
return;
}

if ( version_compare( $version, $current_versions[ $plugin ], '>' ) ) {
call_user_func( $callback, $current_versions[ $plugin ], $network );
$current_versions[ $plugin ] = $version;
}

update_site_option( WP_Stream_Install_WPDB::OPTION_KEY . '_registered_connectors', $current_versions );

return;
}

/**
* Render settings page
*
Expand Down Expand Up @@ -841,64 +792,6 @@ private static function reset_stream_settings() {
}
}

/**
* This function is used to uninstall all custom tables and uninstall the plugin
* It will also uninstall custom actions
*/
public static function uninstall_plugin() {
global $wpdb;

check_ajax_referer( 'stream_nonce', 'wp_stream_nonce' );
if ( ! class_exists( WP_Stream_Install_WPDB ) ) {
include WP_STREAM_INC_DIR . '/db/install/wpdb.php';
}

if ( current_user_can( self::SETTINGS_CAP ) ) {
// Prevent stream action from being fired on plugin
remove_action( 'deactivate_plugin', array( 'WP_Stream_Connector_Installer', 'callback' ), null );

// Plugin is being uninstalled from only one of the multisite blogs
if ( is_multisite() && ! is_plugin_active_for_network( WP_STREAM_PLUGIN ) ) {
$blog_id = get_current_blog_id();

delete_option( plugin_basename( WP_STREAM_DIR ) . '_db' );
delete_option( WP_Stream_Install_WPDB::OPTION_KEY );
delete_option( WP_Stream_Settings::OPTION_KEY );
} else {
// Delete database options
if ( is_multisite() ) {
$blogs = wp_get_sites();
foreach ( $blogs as $blog ) {
switch_to_blog( $blog['blog_id'] );
delete_option( plugin_basename( WP_STREAM_DIR ) . '_db' );
delete_option( WP_Stream_Install_WPDB::OPTION_KEY );
delete_option( WP_Stream_Settings::OPTION_KEY );
delete_option( WP_Stream_API::API_KEY_OPTION_KEY );
delete_option( WP_Stream_API::SITE_UUID_OPTION_KEY );
}
restore_current_blog();
}

// Delete database options
delete_site_option( plugin_basename( WP_STREAM_DIR ) . '_db' );
delete_site_option( WP_Stream_Install_WPDB::OPTION_KEY );
delete_site_option( WP_Stream_Settings::OPTION_KEY );
delete_site_option( WP_Stream_Settings::DEFAULTS_OPTION_KEY );
delete_site_option( WP_Stream_Settings::NETWORK_OPTION_KEY );
delete_site_option( WP_Stream_Network::SITES_CONNECTED_OPTION_KEY );
}

// Deactivate the plugin
deactivate_plugins( plugin_basename( WP_STREAM_DIR ) . '/stream.php' );

// Redirect to plugin page
wp_redirect( add_query_arg( array( 'deactivate' => true ), self_admin_url( 'plugins.php' ) ) );
exit;
} else {
wp_die( "You don't have sufficient privileges to do this action." );
}
}

private static function _role_can_view_stream( $role ) {
if ( in_array( $role, WP_Stream_Settings::$options['general_role_access'] ) ) {
return true;
Expand Down
10 changes: 2 additions & 8 deletions stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ private function __construct() {
add_action( 'wp_head', array( $this, 'frontend_indicator' ) );

if ( is_admin() ) {
// Registers a hook that connectors and other plugins can use whenever a stream update happens
add_action( 'admin_init', array( __CLASS__, 'update_activation_hook' ) );

add_action( 'plugins_loaded', array( 'WP_Stream_Admin', 'load' ) );

add_action( 'plugins_loaded', array( 'WP_Stream_Dashboard_Widget', 'load' ) );
Expand Down Expand Up @@ -170,10 +167,6 @@ public static function i18n() {
load_plugin_textdomain( 'stream', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}

static function update_activation_hook() {
WP_Stream_Admin::register_update_hook( dirname( plugin_basename( __FILE__ ) ), array( self::$db, 'install' ), self::VERSION );
}

/**
* Whether the current PHP version meets the minimum requirements
*
Expand Down Expand Up @@ -291,7 +284,8 @@ public static function get_instance() {

if ( WP_Stream::is_valid_php_version() ) {
$GLOBALS['wp_stream'] = WP_Stream::get_instance();
register_activation_hook( __FILE__, array( WP_Stream::$db, 'install' ) );
} else {
WP_Stream::fail_php_version();
}

register_deactivation_hook( __FILE__, array( 'WP_Stream_Admin', 'remove_api_authentication' ) );
6 changes: 0 additions & 6 deletions ui/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ jQuery(function( $ ) {
$( '.toplevel_page_wp_stream [type=search]' ).off( 'mousedown' );
});

$( '#wp_stream_uninstall' ).click(function( e ) {
if ( ! confirm( wp_stream.i18n.confirm_uninstall ) ) {
e.preventDefault();
}
});

// Admin page tabs
var $tabs = $( '.nav-tab-wrapper' ),
$panels = $( '.nav-tab-content table.form-table' ),
Expand Down
12 changes: 0 additions & 12 deletions ui/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,24 +295,12 @@ jQuery(function( $ ) {
});

// Confirmation on some important actions
$( '#wp_stream_general_delete_all_records, #wp_stream_network_general_delete_all_records' ).click(function( e ) {
if ( ! confirm( wp_stream.i18n.confirm_purge ) ) {
e.preventDefault();
}
});

$( '#wp_stream_general_reset_site_settings, #wp_stream_network_general_reset_site_settings' ).click(function( e ) {
if ( ! confirm( wp_stream.i18n.confirm_defaults ) ) {
e.preventDefault();
}
});

$( '#wp_stream_uninstall' ).click(function( e ) {
if ( ! confirm( wp_stream.i18n.confirm_uninstall ) ) {
e.preventDefault();
}
});

// Settings page tabs
var $tabs = $( '.nav-tab-wrapper' ),
$panels = $( '.nav-tab-content table.form-table' ),
Expand Down

0 comments on commit eb10a14

Please sign in to comment.