diff --git a/includes/wccom-site/class-wc-wccom-site-installer-requirements-check.php b/includes/wccom-site/class-wc-wccom-site-installer-requirements-check.php new file mode 100644 index 00000000000..7fd04bcdda7 --- /dev/null +++ b/includes/wccom-site/class-wc-wccom-site-installer-requirements-check.php @@ -0,0 +1,60 @@ + 400 ) ); + } + + return true; + } + + /** + * Validates if WP CRON is enabled. + * + * @since 3.8.0 + * @return bool + */ + private static function met_wp_cron_requirement() { + return ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ); + } + + /** + * Validates if `WP_CONTENT_DIR` is writable. + * + * @since 3.8.0 + * @return bool + */ + private static function met_filesystem_requirement() { + return is_writable( WP_CONTENT_DIR ); + } +} diff --git a/includes/wccom-site/class-wc-wccom-site.php b/includes/wccom-site/class-wc-wccom-site.php index aef1d20700e..de45a52fbc1 100644 --- a/includes/wccom-site/class-wc-wccom-site.php +++ b/includes/wccom-site/class-wc-wccom-site.php @@ -36,6 +36,7 @@ class WC_WCCOM_Site { protected static function includes() { require_once WC_ABSPATH . 'includes/admin/helper/class-wc-helper.php'; require_once WC_ABSPATH . 'includes/wccom-site/class-wc-wccom-site-installer.php'; + require_once WC_ABSPATH . 'includes/wccom-site/class-wc-wccom-site-installer-requirements-check.php'; } /** diff --git a/includes/wccom-site/rest-api/endpoints/class-wc-rest-wccom-site-installer-controller.php b/includes/wccom-site/rest-api/endpoints/class-wc-rest-wccom-site-installer-controller.php index daab2ee9ba7..19481219d75 100644 --- a/includes/wccom-site/rest-api/endpoints/class-wc-rest-wccom-site-installer-controller.php +++ b/includes/wccom-site/rest-api/endpoints/class-wc-rest-wccom-site-installer-controller.php @@ -84,6 +84,11 @@ class WC_REST_WCCOM_Site_Installer_Controller extends WC_REST_Controller { * @return bool|WP_Error */ public function get_install_state( $request ) { + $requirements_met = WC_WCCOM_Site_Installer_Requirements_Check::met_requirements(); + if ( is_wp_error( $requirements_met ) ) { + return $requirements_met; + } + return rest_ensure_response( WC_WCCOM_Site_Installer::get_state() ); } @@ -95,6 +100,11 @@ class WC_REST_WCCOM_Site_Installer_Controller extends WC_REST_Controller { * @return bool|WP_Error */ public function install( $request ) { + $requirements_met = WC_WCCOM_Site_Installer_Requirements_Check::met_requirements(); + if ( is_wp_error( $requirements_met ) ) { + return $requirements_met; + } + if ( empty( $request['products'] ) ) { return new WP_Error( 'missing_products', __( 'Missing products in request body.', 'woocommerce' ), array( 'status' => 400 ) ); }