From 2358f022efd84558fcd3719c587aa9f88c6ea80b Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Tue, 6 Oct 2020 08:56:40 -0400 Subject: [PATCH] Declare the note constants on the deprecated class. (https://github.com/woocommerce/woocommerce-admin/pull/5215) * Declare the note constants on the deprecated class. This avoids triggering PHP errors when third party code references the old class constants. * Remove deprecation notices and return the call result * Restore deprecated notices. * Avoid magic strings. * Pass WC_Admin_Note constructor argument to migrated class. * Allow subclasses to access the facade class instance. Co-authored-by: Rebecca Scott --- .../src/DeprecatedClassFacade.php | 6 +++--- .../src/Notes/DeprecatedNotes.php | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/plugins/woocommerce-admin/src/DeprecatedClassFacade.php b/plugins/woocommerce-admin/src/DeprecatedClassFacade.php index 3babaead06c..3772c144b98 100644 --- a/plugins/woocommerce-admin/src/DeprecatedClassFacade.php +++ b/plugins/woocommerce-admin/src/DeprecatedClassFacade.php @@ -30,7 +30,7 @@ class DeprecatedClassFacade { * * @var object */ - private $instance; + protected $instance; /** * Constructor. @@ -50,7 +50,7 @@ class DeprecatedClassFacade { static::$facade_over_classname . '::' . $name, static::$deprecated_in_version ); - call_user_func_array( + return call_user_func_array( array( $this->instance, $name, @@ -70,7 +70,7 @@ class DeprecatedClassFacade { static::$facade_over_classname . '::' . $name, static::$deprecated_in_version ); - call_user_func_array( + return call_user_func_array( array( static::$facade_over_classname, $name, diff --git a/plugins/woocommerce-admin/src/Notes/DeprecatedNotes.php b/plugins/woocommerce-admin/src/Notes/DeprecatedNotes.php index e5dc3513373..1a9cde0ecd3 100644 --- a/plugins/woocommerce-admin/src/Notes/DeprecatedNotes.php +++ b/plugins/woocommerce-admin/src/Notes/DeprecatedNotes.php @@ -16,6 +16,18 @@ use Automattic\WooCommerce\Admin\DeprecatedClassFacade; * WC_Admin_Note (deprecated, use Note instead). */ class WC_Admin_Note extends DeprecatedClassFacade { + // These constants must be redeclared as to not break plugins that use them. + const E_WC_ADMIN_NOTE_ERROR = Note::E_WC_ADMIN_NOTE_ERROR; + const E_WC_ADMIN_NOTE_WARNING = Note::E_WC_ADMIN_NOTE_WARNING; + const E_WC_ADMIN_NOTE_UPDATE = Note::E_WC_ADMIN_NOTE_UPDATE; + const E_WC_ADMIN_NOTE_INFORMATIONAL = Note::E_WC_ADMIN_NOTE_INFORMATIONAL; + const E_WC_ADMIN_NOTE_MARKETING = Note::E_WC_ADMIN_NOTE_MARKETING; + const E_WC_ADMIN_NOTE_SURVEY = Note::E_WC_ADMIN_NOTE_SURVEY; + const E_WC_ADMIN_NOTE_PENDING = Note::E_WC_ADMIN_NOTE_PENDING; + const E_WC_ADMIN_NOTE_UNACTIONED = Note::E_WC_ADMIN_NOTE_UNACTIONED; + const E_WC_ADMIN_NOTE_ACTIONED = Note::E_WC_ADMIN_NOTE_ACTIONED; + const E_WC_ADMIN_NOTE_SNOOZED = Note::E_WC_ADMIN_NOTE_SNOOZED; + /** * The name of the non-deprecated class that this facade covers. * @@ -29,6 +41,15 @@ class WC_Admin_Note extends DeprecatedClassFacade { * @var string */ protected static $deprecated_in_version = '1.6.0'; + + /** + * Note constructor. Loads note data. + * + * @param mixed $data Note data, object, or ID. + */ + public function __construct( $data = '' ) { + $this->instance = new static::$facade_over_classname( $data ); + } } /**