diff --git a/bootstrap.php b/bootstrap.php index f14f799b6..10a99a5c7 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -3,6 +3,9 @@ use NewfoldLabs\WP\Module\Onboarding\Application; use function NewfoldLabs\WP\ModuleLoader\register; use NewfoldLabs\WP\Module\Onboarding\ModuleController; +use NewfoldLabs\WP\Module\Onboarding\Compatibility\Scan; +use NewfoldLabs\WP\Module\Onboarding\Compatibility\Safe_Mode; +use NewfoldLabs\WP\Module\Onboarding\Compatibility\Status; /** * Register Onboarding with Newfold Module Loader @@ -33,6 +36,14 @@ function nfd_wp_module_onboarding_register() { if ( ! defined( 'NFD_ONBOARDING_BUILD_URL' && defined( 'NFD_ONBOARDING_VERSION' ) ) ) { define( 'NFD_ONBOARDING_BUILD_URL', $container->plugin()->url . '/vendor/newfold-labs/wp-module-onboarding/build/' . NFD_ONBOARDING_VERSION ); } + + if ( 'compatible' !== Status::get() ) { + $compatibility_scan = new Scan(); + Status::set( $compatibility_scan ); + if ( 'compatible' !== $compatibility_scan->result ) { + return new Safe_Mode( $compatibility_scan ); + } + } // Instantiate Onboarding Module Application new Application( $container ); }, diff --git a/includes/Application.php b/includes/Application.php index 2c59a50b3..9a98be82c 100644 --- a/includes/Application.php +++ b/includes/Application.php @@ -1,6 +1,7 @@ scan = $scan; + \add_action( 'admin_menu', array( $this, 'core_update_page' ) ); + + // Cleanup and Redirect to Onboarding once core has updated successfully. See wp-admin/includes/update-core.php + \add_action( '_core_updated_successfully', array( self::class, 'handle_redirect' ) ); + + // Cleanup and Redirect to Onboarding once core has updated successfully via manual DB upgrade. See wp-admin/upgrade.php + \add_action( 'load-about.php', array( self::class, 'handle_redirect' ) ); + + } + + /** + * Display WP core update page when in safe mode. + */ + public function core_update_page() { + \add_submenu_page( + null, + \__( 'Onboarding', 'wp-module-onboarding' ), + \__( 'Onboarding', 'wp-module-onboarding' ), + Permissions::ADMIN, + WP_Admin::$slug, + array( $this, 'render' ), + 100 + ); + } + + /** + * Render WP core update page. + */ + public function render() { + // Get the Onboarding request URL. + $request_url = \remove_query_arg( '_wp_http_referer' ); + // Set the post core update redirect URL transient. + \set_transient( Options::get_option_name( 'core_update_referrer' ), $request_url, 259200 ); + ?> + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+
+

+

+

+ scan->data['wp_version'], + $this->scan->config['min_wp'] + ) + ) + ?> +

+
+
+
+
+ +

+ + + + +

+
+
+

+
+
+ + + + '6.1', + ); + + /** + * Environment data. + * + * @var array + */ + public $data = array( + 'wp_version' => '', + ); + + /** + * Active Configuration. + * + * @var array + */ + public $config = array(); + + /** + * Test statuses. + * + * @var array + */ + public $test_statuses = array( + 'compatible', + 'unsupported-wp', + ); + + /** + * Result of the compatibility scan. + * + * @var string + */ + public $result = ''; + + /** + * Scan constructor. + * + * @param array $config Config data. + */ + public function __construct( $config = array() ) { + $this->setup( $config ); + // Fetch Relevant Data + $this->fetch(); + // Evaluate Using Configuration & Data + $this->evaluate(); + + return array( + 'status' => $this->result, + 'data' => $this->data, + ); + } + + /** + * Register configuration. + * + * @param array $config Config data. + */ + protected function setup( $config ) { + $this->config = array_merge( $this->default_config, $config ); + } + + /** + * Set up environment data to be checked. + */ + protected function fetch() { + global $wp_version; + + $this->data = array_merge( + $this->data, + array( + 'wp_version' => $wp_version, + ) + ); + + $previous = Status::get(); + if ( ! empty( $previous ) && is_array( $previous ) ) { + $this->data['previous_result'] = $previous; + } + } + + /** + * Run the compatibility check. + */ + protected function evaluate() { + + $this->result = 'scan-initiated'; + + if ( version_compare( $this->data['wp_version'], $this->config['min_wp'], '<' ) ) { + $this->result = 'unsupported-wp'; + } + + if ( 'scan-initiated' === $this->result ) { + $this->result = 'compatible'; + } + + } + +} diff --git a/includes/Compatibility/Status.php b/includes/Compatibility/Status.php new file mode 100644 index 000000000..e43a453f5 --- /dev/null +++ b/includes/Compatibility/Status.php @@ -0,0 +1,64 @@ +result; + $data['timestamp'] = \current_time( 'mysql' ); + } + + \update_option( Options::get_option_name( 'compatibility_results' ), $data ); + + return false; + } + + /** + * Reset/Delete the stored scan results + */ + public static function reset() { + \delete_option( Options::get_option_name( 'compatibility_results' ) ); + } + +} diff --git a/includes/Data/Options.php b/includes/Data/Options.php index d8ccdb2ee..7ce77ce63 100644 --- a/includes/Data/Options.php +++ b/includes/Data/Options.php @@ -50,6 +50,8 @@ final class Options { 'theme_settings' => 'theme_settings', 'flow_preset' => 'flow_preset', 'wpseo_social' => 'wpseo_social', + 'compatibility_results' => 'compatibility_results', + 'core_update_referrer' => 'core_update_referrer', ); /**