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 <me@becdetat.com>
This commit is contained in:
Jeff Stieler 2020-10-06 08:56:40 -04:00 committed by GitHub
parent 1bdd2ea0e1
commit 2358f022ef
2 changed files with 24 additions and 3 deletions

View File

@ -30,7 +30,7 @@ class DeprecatedClassFacade {
* *
* @var object * @var object
*/ */
private $instance; protected $instance;
/** /**
* Constructor. * Constructor.
@ -50,7 +50,7 @@ class DeprecatedClassFacade {
static::$facade_over_classname . '::' . $name, static::$facade_over_classname . '::' . $name,
static::$deprecated_in_version static::$deprecated_in_version
); );
call_user_func_array( return call_user_func_array(
array( array(
$this->instance, $this->instance,
$name, $name,
@ -70,7 +70,7 @@ class DeprecatedClassFacade {
static::$facade_over_classname . '::' . $name, static::$facade_over_classname . '::' . $name,
static::$deprecated_in_version static::$deprecated_in_version
); );
call_user_func_array( return call_user_func_array(
array( array(
static::$facade_over_classname, static::$facade_over_classname,
$name, $name,

View File

@ -16,6 +16,18 @@ use Automattic\WooCommerce\Admin\DeprecatedClassFacade;
* WC_Admin_Note (deprecated, use Note instead). * WC_Admin_Note (deprecated, use Note instead).
*/ */
class WC_Admin_Note extends DeprecatedClassFacade { 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. * The name of the non-deprecated class that this facade covers.
* *
@ -29,6 +41,15 @@ class WC_Admin_Note extends DeprecatedClassFacade {
* @var string * @var string
*/ */
protected static $deprecated_in_version = '1.6.0'; 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 );
}
} }
/** /**