Skip to content

Commit

Permalink
Merge pull request #56 from Automattic/update/reset-via-cli
Browse files Browse the repository at this point in the history
Remove jpo_reset=1 in favor of CLI command
  • Loading branch information
ebinnion authored Sep 26, 2017
2 parents 86cf1fd + 2a311ec commit 3aef972
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 56 deletions.
19 changes: 1 addition & 18 deletions class.jetpack-onboarding-end-points.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,7 @@ static function normalize_installed_theme($theme) {
static function reset_data() {
check_ajax_referer( self::AJAX_NONCE, 'nonce' );

delete_option( self::STEP_STATUS_KEY );
delete_option( self::STARTED_KEY );
delete_option( self::CONTACTPAGE_ID_KEY );
jpo_reset();

wp_send_json_success( 'deleted' );
}
Expand Down Expand Up @@ -408,21 +406,6 @@ static function hide_dashboard_widget() {
update_option( self::HIDE_FOR_ALL_USERS_OPTION, 1 );
}

static function show_dashboard_widget() {
delete_option( self::HIDE_FOR_ALL_USERS_OPTION );

$setting = get_user_option( get_current_user_id(), "metaboxhidden_dashboard" );

if ( ! $setting || ! is_array( $setting ) ) {
$setting = array();
}

if ( in_array( Jetpack_Onboarding_WelcomePanel::DASHBOARD_WIDGET_ID, $setting ) ) {
$setting = array_diff( $setting, array( Jetpack_Onboarding_WelcomePanel::DASHBOARD_WIDGET_ID ) );
update_user_option( get_current_user_id(), "metaboxhidden_dashboard", $setting, true );
}
}

static function step_view() {
check_ajax_referer( self::AJAX_NONCE, 'nonce' );
do_action('jpo_step_viewed', $_REQUEST['step']);
Expand Down
34 changes: 0 additions & 34 deletions class.jetpack-onboarding-welcome-panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ static function check_for_widget_visibility( $check, $object_id, $meta_key, $met
}

static function add_dashboard_widgets() {
self::reset_data_if_necessary();

if ( get_option( Jetpack_Onboarding_EndPoints::HIDE_FOR_ALL_USERS_OPTION ) ) {
return;
}
Expand Down Expand Up @@ -67,38 +65,6 @@ static function add_wizard_assets() {
wp_enqueue_style( 'ie8' );
}

static function reset_data_if_necessary() {
//reset data
if ( isset( $_GET['jpo_reset'] ) ) {
delete_option( Jetpack_Onboarding_EndPoints::STEP_STATUS_KEY );
delete_option( Jetpack_Onboarding_EndPoints::FIRSTRUN_KEY );
delete_option( Jetpack_Onboarding_EndPoints::STARTED_KEY );
Jetpack_Onboarding_EndPoints::show_dashboard_widget();
delete_option( Jetpack_Onboarding_EndPoints::CONTACTPAGE_ID_KEY );
delete_option( Jetpack_Onboarding_EndPoints::HIDE_FOR_ALL_USERS_OPTION );

delete_option( 'jetpack_blog_token' );
delete_option( 'jetpack_id' );

//also reset JP data
delete_option( 'jetpack_options' );

// Delete all non-compact options
delete_option( 'jetpack_register' );
delete_option( 'jetpack_activated' );
delete_option( 'jetpack_active_modules' );
delete_option( 'jetpack_do_activate' );

// Delete all legacy options
delete_option( 'jetpack_was_activated' );
delete_option( 'jetpack_auto_installed' );
delete_transient( 'jetpack_register' );

wp_redirect(remove_query_arg('jpo_reset'));
die();
}
}

static function render_widget() {
if ( false === get_option( Jetpack_Onboarding_EndPoints::FIRSTRUN_KEY, false ) ) {
update_option( Jetpack_Onboarding_EndPoints::FIRSTRUN_KEY, true );
Expand Down
49 changes: 45 additions & 4 deletions jetpack-onboarding.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,62 @@
* Version: 1.7.1
*/

require_once( plugin_dir_path( __FILE__ ) . 'class.jetpack-onboarding-end-points.php' );
require_once( plugin_dir_path( __FILE__ ) . 'class.jetpack-onboarding-welcome-panel.php' );

defined( 'JETPACK_ONBOARDING_BASE_DIR' ) or define( 'JETPACK_ONBOARDING_BASE_DIR', dirname( __FILE__ ) );
defined( 'JETPACK_ONBOARDING_BASE_URL' ) or define( 'JETPACK_ONBOARDING_BASE_URL', plugin_dir_url( __FILE__ ) );
defined( 'JETPACK_STEP_AUTO_REDIRECT' ) or define( 'JETPACK_STEP_AUTO_REDIRECT', true );
defined( 'JETPACK_STEP_AUTO_REDIRECT_SRC' ) or define( 'JETPACK_STEP_AUTO_REDIRECT_SRC', 'custom_src' );
defined( 'JETPACK_ONBOARDING_VENDOR_CODE' ) or define( 'JETPACK_ONBOARDING_VENDOR_CODE', 'unknown' );
defined( 'JETPACK_ONBOARDING_PRODUCT_CODE' ) or define( 'JETPACK_ONBOARDING_PRODUCT_CODE', 'unknown' );

register_uninstall_hook( __FILE__, 'jpo_reset' );

function jpo_start() {
if ( is_admin() && current_user_can( 'administrator' ) ) {
require_once( plugin_dir_path( __FILE__ ) . 'class.jetpack-onboarding-end-points.php' );
require_once( plugin_dir_path( __FILE__ ) . 'class.jetpack-onboarding-welcome-panel.php' );

Jetpack_Onboarding_EndPoints::init();
Jetpack_Onboarding_WelcomePanel::init();
}
}

add_action( 'init', 'jpo_start' );

function jpo_reset() {
delete_option( Jetpack_Onboarding_EndPoints::STEP_STATUS_KEY );
delete_option( Jetpack_Onboarding_EndPoints::FIRSTRUN_KEY );
delete_option( Jetpack_Onboarding_EndPoints::STARTED_KEY );
delete_option( Jetpack_Onboarding_EndPoints::CONTACTPAGE_ID_KEY );
delete_option( Jetpack_Onboarding_EndPoints::HIDE_FOR_ALL_USERS_OPTION );
delete_option( Jetpack_Onboarding_EndPoints::SITE_TYPE );

// If we have a current user, reset JPO for only the current user.
// Otherwise, reset for all admins.
$users = array();
if ( get_current_user_id() ) {
$users[] = get_current_user_id();
} else {
$users_query = get_users( array(
'role' => 'administrator',
'fields' => array( 'id' ) )
);

$users = wp_list_pluck( $users_query, 'id' );
}

foreach ( $users as $user_id ) {
$setting = get_user_option( 'metaboxhidden_dashboard', $user_id );

if ( ! $setting || ! is_array( $setting ) ) {
$setting = array();
}

if ( in_array( Jetpack_Onboarding_WelcomePanel::DASHBOARD_WIDGET_ID, $setting ) ) {
$setting = array_diff( $setting, array( Jetpack_Onboarding_WelcomePanel::DASHBOARD_WIDGET_ID ) );
update_user_option( $user_id, "metaboxhidden_dashboard", $setting, true );
}
}
}

if ( defined( 'WP_CLI' ) && WP_CLI ) {
WP_CLI::add_command( 'jpo reset', 'jpo_reset' );
}

0 comments on commit 3aef972

Please sign in to comment.