set_user( $args[0] ); if ( is_wp_error( $ret ) ) { WP_CLI::error( $ret->get_error_message() ); } WP_CLI::line( 'Running as user ' . $ret->user_login . '…' ); $blog_id = Helper::get_wpcom_site_id(); Instant_Search::instance( $blog_id )->auto_config_search(); WP_CLI::success( 'Auto config success!' ); } catch ( \Exception $e ) { WP_CLI::error( $e->getMessage() ); } } /** * Set current user by ID or login * * @param string|int $user User ID or login. */ protected function set_user( $user ) { $get_user_by = 'login'; if ( filter_var( $user, FILTER_VALIDATE_INT ) > 0 ) { $get_user_by = 'ID'; } $user_info = get_user_by( $get_user_by, (string) $user ); if ( ! $user_info ) { return new WP_Error( 'user_not_found', "Could not find user '${user}' by ${get_user_by}." ); } return wp_set_current_user( $user_info->ID ); } }