Add notices about the removal of the Legacy API in WooCommerce 9.0
- A permanent notice in Settings - Advanced - Legacy API - A dismissable admin notice only if the Legacy API is enabled (disappears if it gets disabled)
This commit is contained in:
parent
de1fe1bf96
commit
1f0e952314
|
@ -7,6 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Automattic\Jetpack\Constants;
|
use Automattic\Jetpack\Constants;
|
||||||
|
use Automattic\WooCommerce\Internal\Traits\AccessiblePrivateMethods;
|
||||||
use Automattic\WooCommerce\Internal\Utilities\Users;
|
use Automattic\WooCommerce\Internal\Utilities\Users;
|
||||||
|
|
||||||
defined( 'ABSPATH' ) || exit;
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
@ -16,6 +17,8 @@ defined( 'ABSPATH' ) || exit;
|
||||||
*/
|
*/
|
||||||
class WC_Admin_Notices {
|
class WC_Admin_Notices {
|
||||||
|
|
||||||
|
use AccessiblePrivateMethods;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores notices.
|
* Stores notices.
|
||||||
*
|
*
|
||||||
|
@ -53,6 +56,7 @@ class WC_Admin_Notices {
|
||||||
add_action( 'woocommerce_installed', array( __CLASS__, 'reset_admin_notices' ) );
|
add_action( 'woocommerce_installed', array( __CLASS__, 'reset_admin_notices' ) );
|
||||||
add_action( 'wp_loaded', array( __CLASS__, 'add_redirect_download_method_notice' ) );
|
add_action( 'wp_loaded', array( __CLASS__, 'add_redirect_download_method_notice' ) );
|
||||||
add_action( 'admin_init', array( __CLASS__, 'hide_notices' ), 20 );
|
add_action( 'admin_init', array( __CLASS__, 'hide_notices' ), 20 );
|
||||||
|
self::add_action( 'admin_init', array( __CLASS__, 'maybe_remove_legacy_api_removal_notice' ), 20 );
|
||||||
|
|
||||||
// @TODO: This prevents Action Scheduler async jobs from storing empty list of notices during WC installation.
|
// @TODO: This prevents Action Scheduler async jobs from storing empty list of notices during WC installation.
|
||||||
// That could lead to OBW not starting and 'Run setup wizard' notice not appearing in WP admin, which we want
|
// That could lead to OBW not starting and 'Run setup wizard' notice not appearing in WP admin, which we want
|
||||||
|
@ -115,6 +119,46 @@ class WC_Admin_Notices {
|
||||||
self::add_notice( 'template_files' );
|
self::add_notice( 'template_files' );
|
||||||
self::add_min_version_notice();
|
self::add_min_version_notice();
|
||||||
self::add_maxmind_missing_license_key_notice();
|
self::add_maxmind_missing_license_key_notice();
|
||||||
|
self::maybe_add_legacy_api_removal_notice();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an admin notice about the removal of the Legacy REST API if the said API is enabled.
|
||||||
|
*
|
||||||
|
* TODO: Remove this method in WooCommerce 9.0.
|
||||||
|
*/
|
||||||
|
private static function maybe_add_legacy_api_removal_notice() {
|
||||||
|
if ( 'yes' !== get_option( 'woocommerce_api_enabled' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::add_custom_notice(
|
||||||
|
'legacy_api_removed_in_woo_90',
|
||||||
|
sprintf(
|
||||||
|
'%s%s',
|
||||||
|
sprintf(
|
||||||
|
'<h4>%s</h4>',
|
||||||
|
esc_html__( 'WooCommerce Legacy API to be removed soon', 'woocommerce' )
|
||||||
|
),
|
||||||
|
sprintf(
|
||||||
|
// translators: Placeholders are URLs.
|
||||||
|
wpautop( wp_kses_data( __( 'The WooCommerce Legacy REST API, <a href="%1$s">currently enabled in this site</a>, will be removed in WooCommerce 9.0. A separate WooCommerce extension will be available to re-enable it. <b><a target=”_blank” href="%2$s">Learn more about this change</a></b>', 'woocommerce' ) ) ),
|
||||||
|
admin_url( 'admin.php?page=wc-settings&tab=advanced§ion=legacy_api' ),
|
||||||
|
'https://developer.woocommerce.com/2023/10/03/the-legacy-rest-api-will-move-to-a-dedicated-extension-in-woocommerce-9-0/'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove the admin notice about the removal of the Legacy REST API if the said API is disabled.
|
||||||
|
*
|
||||||
|
* TODO: Remove this method in WooCommerce 9.0.
|
||||||
|
*/
|
||||||
|
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' ) ) {
|
||||||
|
self::remove_notice( 'legacy_api_removed_in_woo_90' );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -424,7 +468,7 @@ class WC_Admin_Notices {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notice about WordPress and PHP minimum requirements.
|
* Notice about WordPress and PHP minimum requirements.
|
||||||
*
|
*
|
||||||
* @deprecated 8.2.0 WordPress and PHP minimum requirements notices are no longer shown.
|
* @deprecated 8.2.0 WordPress and PHP minimum requirements notices are no longer shown.
|
||||||
*
|
*
|
||||||
* @since 3.6.5
|
* @since 3.6.5
|
||||||
|
|
|
@ -392,11 +392,19 @@ class WC_Settings_Advanced extends WC_Settings_Page {
|
||||||
'id' => 'legacy_api_options',
|
'id' => 'legacy_api_options',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'title' => __( 'Legacy API', 'woocommerce' ),
|
'title' => __( 'Legacy API', 'woocommerce' ),
|
||||||
'desc' => __( 'Enable the legacy REST API', 'woocommerce' ),
|
'desc' => __( 'Enable the legacy REST API', 'woocommerce' ),
|
||||||
'id' => 'woocommerce_api_enabled',
|
'id' => 'woocommerce_api_enabled',
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
'default' => 'no',
|
'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 be available to re-enable it. <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',
|
||||||
|
|
Loading…
Reference in New Issue