diff --git a/plugins/woocommerce/includes/admin/class-wc-admin-notices.php b/plugins/woocommerce/includes/admin/class-wc-admin-notices.php index 4f57fd287ba..9e7f8e28ac5 100644 --- a/plugins/woocommerce/includes/admin/class-wc-admin-notices.php +++ b/plugins/woocommerce/includes/admin/class-wc-admin-notices.php @@ -130,7 +130,7 @@ class WC_Admin_Notices { * TODO: Change this method in WooCommerce 9.0 so that it checks if the Legacy REST API extension is installed, and if not, it points to the extension URL in the WordPress plugins directory. */ private static function maybe_add_legacy_api_removal_notice() { - if ( 'yes' !== get_option( 'woocommerce_api_enabled' ) ) { + if ( ! self::must_show_legacy_api_removal_notice() ) { return; } @@ -158,11 +158,22 @@ class WC_Admin_Notices { * TODO: Change this method in WooCommerce 9.0 so that the notice gets removed if the Legacy REST API extension is installed and active. */ private static function maybe_remove_legacy_api_removal_notice() { - if ( 'yes' !== get_option( 'woocommerce_api_enabled' ) && self::has_notice( 'legacy_api_removed_in_woo_90' ) ) { + if ( self::has_notice( 'legacy_api_removed_in_woo_90' ) && ! self::must_show_legacy_api_removal_notice() ) { self::remove_notice( 'legacy_api_removed_in_woo_90' ); } } + /** + * Is it needed to display the legacy API removal notice? + * + * TODO: Change or remove this method in WooCommerce 9.0 accordingly, depending on the changes to maybe_add/remove_legacy_api_removal_notice. + * + * @return bool True if the legacy API removal notice must be displayed. + */ + private static function must_show_legacy_api_removal_notice() { + return 'yes' === get_option( 'woocommerce_api_enabled' ) && ! is_plugin_active( 'woocommerce-legacy-rest-api/woocommerce-legacy-rest-api.php' ); + } + // phpcs:enable Generic.Commenting.Todo.TaskFound /** diff --git a/plugins/woocommerce/includes/admin/settings/class-wc-settings-advanced.php b/plugins/woocommerce/includes/admin/settings/class-wc-settings-advanced.php index 4da30370203..d8bb8763209 100644 --- a/plugins/woocommerce/includes/admin/settings/class-wc-settings-advanced.php +++ b/plugins/woocommerce/includes/admin/settings/class-wc-settings-advanced.php @@ -383,6 +383,25 @@ class WC_Settings_Advanced extends WC_Settings_Page { * @return array */ protected function get_settings_for_legacy_api_section() { + $enable_legacy_api_setting = array( + 'title' => __( 'Legacy API', 'woocommerce' ), + 'desc' => __( 'Enable the legacy REST API', 'woocommerce' ), + 'id' => 'woocommerce_api_enabled', + 'type' => 'checkbox', + 'default' => 'no', + ); + + if ( ! is_plugin_active( 'woocommerce-legacy-rest-api/woocommerce-legacy-rest-api.php' ) ) { + $enable_legacy_api_setting['desc_tip'] = sprintf( + // translators: Placeholder is a URL. + __( + '⚠️ ️The Legacy REST API will be removed in WooCommerce 9.0. A separate WooCommerce extension will soon be available to keep it enabled. Learn more about this change', + 'woocommerce' + ), + 'https://developer.woocommerce.com/2023/10/03/the-legacy-rest-api-will-move-to-a-dedicated-extension-in-woocommerce-9-0/' + ); + } + $settings = array( array( @@ -391,21 +410,7 @@ class WC_Settings_Advanced extends WC_Settings_Page { 'desc' => '', 'id' => 'legacy_api_options', ), - array( - 'title' => __( 'Legacy API', 'woocommerce' ), - 'desc' => __( 'Enable the legacy REST API', 'woocommerce' ), - 'id' => 'woocommerce_api_enabled', - 'type' => 'checkbox', - 'default' => 'no', - 'desc_tip' => sprintf( - // translators: Placeholder is a URL. - __( - '⚠️ ️The Legacy REST API will be removed in WooCommerce 9.0. A separate WooCommerce extension will soon be available to keep it enabled. Learn more about this change', - 'woocommerce' - ), - 'https://developer.woocommerce.com/2023/10/03/the-legacy-rest-api-will-move-to-a-dedicated-extension-in-woocommerce-9-0/' - ), - ), + $enable_legacy_api_setting, array( 'type' => 'sectionend', 'id' => 'legacy_api_options',