Don't show the notices if the dedicated extension is already active.

This commit is contained in:
Nestor Soriano 2023-10-05 09:48:19 +02:00
parent 0533ad40af
commit 10d6366ff1
No known key found for this signature in database
GPG Key ID: 08110F3518C12CAD
2 changed files with 33 additions and 17 deletions

View File

@ -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. * 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() { 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; 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. * 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() { 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' ); 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 // phpcs:enable Generic.Commenting.Todo.TaskFound
/** /**

View File

@ -383,6 +383,25 @@ class WC_Settings_Advanced extends WC_Settings_Page {
* @return array * @return array
*/ */
protected function get_settings_for_legacy_api_section() { 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.
__(
'⚠️ <b>The Legacy REST API will be removed in WooCommerce 9.0.</b> A separate WooCommerce extension will soon be available to keep it enabled. <b><a target=”_blank” href="%s">Learn more about this change</a></b>',
'woocommerce'
),
'https://developer.woocommerce.com/2023/10/03/the-legacy-rest-api-will-move-to-a-dedicated-extension-in-woocommerce-9-0/'
);
}
$settings = $settings =
array( array(
array( array(
@ -391,21 +410,7 @@ class WC_Settings_Advanced extends WC_Settings_Page {
'desc' => '', 'desc' => '',
'id' => 'legacy_api_options', 'id' => 'legacy_api_options',
), ),
array( $enable_legacy_api_setting,
'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.
__(
'⚠️ <b>The Legacy REST API will be removed in WooCommerce 9.0.</b> A separate WooCommerce extension will soon be available to keep it enabled. <b><a target=”_blank” href="%s">Learn more about this change</a></b>',
'woocommerce'
),
'https://developer.woocommerce.com/2023/10/03/the-legacy-rest-api-will-move-to-a-dedicated-extension-in-woocommerce-9-0/'
),
),
array( array(
'type' => 'sectionend', 'type' => 'sectionend',
'id' => 'legacy_api_options', 'id' => 'legacy_api_options',