PluginProbe ʕ •ᴥ•ʔ
Advanced Import / 1.3.2
Advanced Import v1.3.2
trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 2.0.0
advanced-import / admin / class-reset.php
advanced-import / admin Last commit date
class-advanced-import-admin.php 5 years ago class-elementor-import.php 5 years ago class-reset.php 5 years ago index.php 5 years ago
class-reset.php
207 lines
1 <?php
2
3 /**
4 * Reset WordPress
5 *
6 * @link https://addonspress.com/
7 * @since 1.0.0
8 *
9 * @package Advanced_Import
10 * @subpackage Advanced_Import/admin
11 */
12
13 /**
14 * The admin-specific functionality of the plugin.
15 * Reset WordPress
16 *
17 * @package Advanced_Import
18 * @subpackage Advanced_Import/admin
19 * @author Addons Press <addonspress.com>
20 */
21 class Advanced_Import_Reset_WordPress {
22
23 /**
24 * Initialize the class and set its properties.
25 *
26 * @since 1.0.0
27 */
28 public function __construct() {}
29
30 /**
31 * Main Advanced_Import_Reset_WordPress Instance
32 * Initialize the class and set its properties.
33 *
34 * @since 1.0.0
35 * @return object $instance Advanced_Import_Reset_WordPress Instance
36 */
37 public static function instance() {
38
39 // Store the instance locally to avoid private static replication
40 static $instance = null;
41
42 // Only run these methods if they haven't been ran previously
43 if ( null === $instance ) {
44 $instance = new Advanced_Import_Reset_WordPress();
45
46 }
47
48 // Always return the instance
49 return $instance;
50 }
51
52 /**
53 * Hide a notice if the GET variable is set.
54 */
55 public function hide_reset_notice() {
56 if ( isset( $_GET['advanced-import-hide-notice'] ) && isset( $_GET['_advanced_import_notice_nonce'] ) ) {
57 /*Security*/
58 if ( ! wp_verify_nonce( $_GET['_advanced_import_notice_nonce'], 'advanced_import_hide_notice_nonce' ) ) {
59 wp_die( __( 'Action failed. Please refresh the page and retry.', 'advanced-import' ) );
60 }
61
62 if ( ! current_user_can( 'manage_options' ) ) {
63 wp_die( __( 'Cheatin&#8217; huh?', 'advanced-import' ) );
64 }
65
66 $hide_notice = sanitize_text_field( $_GET['advanced-import-hide-notice'] );
67
68 if ( ! empty( $hide_notice ) && 'reset_notice' == $hide_notice ) {
69 update_option( 'advanced_import_reset_notice', 1 );
70 }
71 }
72 }
73
74 /**
75 * Reset actions when a reset button is clicked.
76 */
77 public function reset_wizard_actions() {
78 global $wpdb, $current_user;
79
80 if ( ! empty( $_GET['ai_reset_wordpress'] ) && ! empty( $_GET['ai_reset_wordpress_nonce'] ) ) {
81 /*Security*/
82 if ( ! wp_verify_nonce( wp_unslash( $_GET['ai_reset_wordpress_nonce'] ), 'ai_reset_wordpress' ) ) { // WPCS: input var ok, sanitization ok.
83 wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'advanced-import' ) );
84 }
85 if ( ! current_user_can( 'manage_options' ) ) {
86 wp_die( esc_html__( 'No permission to reset WordPress', 'advanced-import' ) );
87 }
88
89 require_once ABSPATH . '/wp-admin/includes/upgrade.php';
90
91 $template = get_option( 'template' );
92 $blogname = get_option( 'blogname' );
93 $admin_email = get_option( 'admin_email' );
94 $blog_public = get_option( 'blog_public' );
95
96 $current_url = advanced_import_current_url();
97
98 if ( 'admin' != $current_user->user_login ) {
99 $user = get_user_by( 'login', 'admin' );
100 }
101
102 if ( empty( $user->user_level ) || $user->user_level < 10 ) {
103 $user = $current_user;
104 }
105
106 // Drop tables.
107 $drop_tables = $wpdb->get_col( sprintf( "SHOW TABLES LIKE '%s%%'", str_replace( '_', '\_', $wpdb->prefix ) ) );
108 foreach ( $drop_tables as $table ) {
109 $wpdb->query( "DROP TABLE IF EXISTS $table" );
110 }
111
112 // Installs the site.
113 $result = wp_install( $blogname, $user->user_login, $user->user_email, $blog_public );
114
115 // Updates the user password with a old one.
116 $wpdb->update(
117 $wpdb->users,
118 array(
119 'user_pass' => $user->user_pass,
120 'user_activation_key' => '',
121 ),
122 array( 'ID' => $result['user_id'] )
123 );
124
125 // Set up the Password change nag.
126 $default_password_nag = get_user_option( 'default_password_nag', $result['user_id'] );
127 if ( $default_password_nag ) {
128 update_user_option( $result['user_id'], 'default_password_nag', false, true );
129 }
130
131 // Switch current theme.
132 $current_theme = wp_get_theme( $template );
133 if ( $current_theme->exists() ) {
134 switch_theme( $template );
135 }
136
137 // Activate required plugins.
138 $required_plugins = (array) apply_filters( 'advanced_import_' . $template . '_required_plugins', array() );
139 if ( is_array( $required_plugins ) ) {
140 if ( ! in_array( plugin_basename( ADVANCED_IMPORT_PATH . '/advanced-import.php' ), $required_plugins ) ) {
141 $required_plugins = array_merge( $required_plugins, array( ADVANCED_IMPORT_PATH . '/advanced-import.php' ) );
142 }
143 activate_plugins( $required_plugins, '', is_network_admin(), true );
144 }
145
146 // Update the cookies.
147 wp_clear_auth_cookie();
148 wp_set_auth_cookie( $result['user_id'] );
149
150 // Redirect to demo importer page to display reset success notice.
151 wp_safe_redirect( $current_url . '&reset=true&from=ai-reset-wp' );
152 exit();
153 }
154 }
155
156 /**
157 * Reset wizard notice.
158 */
159 public function reset_wizard_notice() {
160
161 $screen = get_current_screen();
162 if ( ! in_array( $screen->base, advanced_import_admin()->hook_suffix ) ) {
163 return;
164 }
165 $current_url = advanced_import_current_url();
166 $reset_url = wp_nonce_url(
167 add_query_arg( 'ai_reset_wordpress', 'true', $current_url ),
168 'ai_reset_wordpress',
169 'ai_reset_wordpress_nonce'
170 );
171
172 $demo_notice_dismiss = get_option( 'advanced_import_reset_notice' );
173
174 // Output reset wizard notice.
175 if ( ! $demo_notice_dismiss ) {
176 ?>
177 <div id="message" class="updated ai-import-message">
178 <p><?php _e( '<strong>WordPress Reset</strong> &#8211; If no important data on your site. You can reset the WordPress back to default again!', 'advanced-import' ); ?></p>
179 <p class="submit"><a href="<?php echo esc_url( $reset_url ); ?>" class="button button-primary ai-wp-reset"><?php esc_html_e( 'Run the Reset Wizard', 'advanced-import' ); ?></a> <a class="button-secondary skip" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'advanced-import-hide-notice', 'reset_notice', $current_url ), 'advanced_import_hide_notice_nonce', '_advanced_import_notice_nonce' ) ); ?>"><?php esc_attr_e( 'Hide this notice', 'advanced-import' ); ?></a></p>
180 </div>
181 <?php
182 } elseif ( isset( $_GET['reset'] ) && 'true' === $_GET['reset'] ) {
183 $user = get_user_by( 'id', 1 );
184 ?>
185 <div id="message" class="notice notice-info is-dismissible">
186 <p><?php printf( __( 'WordPress has been reset back to defaults. The user <strong>"%1$s"</strong> was recreated with its previous password.', 'advanced-import' ), $user->user_login ); ?></p>
187 </div>
188 <?php
189 }
190 }
191
192
193 }
194
195 /**
196 * Begins execution of the plugin.
197 *
198 * Since everything within the plugin is registered via hooks,
199 * then kicking off the plugin from this point in the file does
200 * not affect the page life cycle.
201 *
202 * @since 1.0.0
203 */
204 function advanced_import_reset_wordpress() {
205 return Advanced_Import_Reset_WordPress::instance();
206 }
207