-
Notifications
You must be signed in to change notification settings - Fork 30
feat: improvements to onboarding flow #1295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -73,6 +73,7 @@ public function registerAdminMenu() { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Method to register the setup wizard page. | ||||||||||||||||||||||
| * | ||||||||||||||||||||||
|
|
@@ -168,7 +169,7 @@ public function dismissWizard( $redirect_to_dashboard = true ) { | |||||||||||||||||||||
| */ | ||||||||||||||||||||||
| public function visualizer_wizard_step_process() { | ||||||||||||||||||||||
| check_ajax_referer( VISUALIZER_ABSPATH, 'security' ); | ||||||||||||||||||||||
| $step = ! empty( $_POST['step'] ) ? filter_input( INPUT_POST, 'step', FILTER_SANITIZE_STRING ) : 1; | ||||||||||||||||||||||
| $step = ! empty( $_POST['step'] ) ? sanitize_text_field( wp_unslash( $_POST['step'] ) ) : 1; | ||||||||||||||||||||||
| switch ( $step ) { | ||||||||||||||||||||||
| case 'step_2': | ||||||||||||||||||||||
| $this->setup_wizard_import_chart(); | ||||||||||||||||||||||
|
|
@@ -193,7 +194,7 @@ public function visualizer_wizard_step_process() { | |||||||||||||||||||||
| */ | ||||||||||||||||||||||
| private function setup_wizard_import_chart() { | ||||||||||||||||||||||
| // phpcs:ignore WordPress.Security.NonceVerification.Missing | ||||||||||||||||||||||
| $chart_type = ! empty( $_POST['chart_type'] ) ? filter_input( INPUT_POST, 'chart_type', FILTER_SANITIZE_STRING ) : ''; | ||||||||||||||||||||||
| $chart_type = ! empty( $_POST['chart_type'] ) ? sanitize_text_field( wp_unslash( $_POST['chart_type'] ) ) : ''; | ||||||||||||||||||||||
| $chart_status = Visualizer_Module_Admin::checkChartStatus( $chart_type ); | ||||||||||||||||||||||
| if ( ! $chart_status ) { | ||||||||||||||||||||||
| wp_send_json( | ||||||||||||||||||||||
|
|
@@ -386,7 +387,8 @@ private function setup_wizard_import_chart() { | |||||||||||||||||||||
| ); | ||||||||||||||||||||||
| $this->update_wizard_data( $wizard_data, false ); | ||||||||||||||||||||||
| $response = array( | ||||||||||||||||||||||
| 'success' => 1, | ||||||||||||||||||||||
| 'success' => 1, | ||||||||||||||||||||||
| 'chart_id' => $chart_id, | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| wp_send_json( $response ); | ||||||||||||||||||||||
|
|
@@ -416,7 +418,7 @@ private function update_wizard_data( $data = array(), $merge_option = true ) { | |||||||||||||||||||||
| private function setup_wizard_create_draft_page( $return_page_id = false ) { | ||||||||||||||||||||||
| $add_basic_shortcode = ! empty( $_POST['add_basic_shortcode'] ) ? sanitize_text_field( wp_unslash( $_POST['add_basic_shortcode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing | ||||||||||||||||||||||
| $add_basic_shortcode = 'true' === $add_basic_shortcode ? true : false; | ||||||||||||||||||||||
| $basic_shortcode = ! empty( $_POST['basic_shortcode'] ) ? filter_input( INPUT_POST, 'basic_shortcode', FILTER_SANITIZE_STRING ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing | ||||||||||||||||||||||
| $basic_shortcode = ! empty( $_POST['basic_shortcode'] ) ? sanitize_text_field( wp_unslash( $_POST['basic_shortcode'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if ( ! $add_basic_shortcode ) { | ||||||||||||||||||||||
| wp_send_json( | ||||||||||||||||||||||
|
|
@@ -476,7 +478,7 @@ private function setup_wizard_create_draft_page( $return_page_id = false ) { | |||||||||||||||||||||
| */ | ||||||||||||||||||||||
| private function setup_wizard_install_plugin() { | ||||||||||||||||||||||
| // phpcs:ignore WordPress.Security.NonceVerification.Missing | ||||||||||||||||||||||
| $slug = ! empty( $_POST['slug'] ) ? filter_input( INPUT_POST, 'slug', FILTER_SANITIZE_STRING ) : ''; | ||||||||||||||||||||||
| $slug = ! empty( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : ''; | ||||||||||||||||||||||
| if ( empty( $slug ) ) { | ||||||||||||||||||||||
| wp_send_json( | ||||||||||||||||||||||
| array( | ||||||||||||||||||||||
|
|
@@ -496,8 +498,10 @@ private function setup_wizard_install_plugin() { | |||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if ( ! empty( $slug ) ) { | ||||||||||||||||||||||
| $wizard_data = get_option( self::OPTION_NAME, array() ); | ||||||||||||||||||||||
| require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; | ||||||||||||||||||||||
| include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; | ||||||||||||||||||||||
| require_once ABSPATH . 'wp-admin/includes/plugin.php'; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| $api = plugins_api( | ||||||||||||||||||||||
| 'plugin_information', | ||||||||||||||||||||||
|
|
@@ -559,11 +563,33 @@ private function setup_wizard_install_plugin() { | |||||||||||||||||||||
| wp_send_json( $status ); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| activate_plugin( 'optimole-wp/optimole-wp.php' ); | ||||||||||||||||||||||
| delete_transient( 'optml_fresh_install' ); | ||||||||||||||||||||||
| // Update wizard data. | ||||||||||||||||||||||
| $wizard_data['enable_perfomance'] = true; | ||||||||||||||||||||||
| $this->update_wizard_data( $wizard_data ); | ||||||||||||||||||||||
| $installed_plugins = get_plugins( '/' . sanitize_key( wp_unslash( $slug ) ) ); | ||||||||||||||||||||||
| if ( ! empty( $installed_plugins ) ) { | ||||||||||||||||||||||
| $plugin_files = array_keys( $installed_plugins ); | ||||||||||||||||||||||
| $plugin_file = sanitize_key( wp_unslash( $slug ) ) . '/' . $plugin_files[0]; | ||||||||||||||||||||||
| activate_plugin( $plugin_file ); | ||||||||||||||||||||||
|
||||||||||||||||||||||
| activate_plugin( $plugin_file ); | |
| $activation_result = activate_plugin( $plugin_file ); | |
| if ( is_wp_error( $activation_result ) ) { | |
| wp_send_json( | |
| array( | |
| 'status' => 0, | |
| 'message' => $activation_result->get_error_message(), | |
| ) | |
| ); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plugin file detection uses
get_plugins()+array_keys()[0]to pick the first plugin file in the folder. This relies on ordering and may activate the wrong file if the folder contains multiple plugin-header files. Since this wizard only installs known slugs, consider mapping slug → expected main plugin file (e.g.optimole-wp/optimole-wp.php,otter-blocks/otter-blocks.php,wp-cloudflare-page-cache/wp-cloudflare-super-page-cache.php) and activate that explicitly (or otherwise deterministically choose the correct file).