2018-09-21 23:44:04 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WooCommerce Admin (Dashboard) Notes.
|
|
|
|
*
|
|
|
|
* The WooCommerce admin notes class gets admin notes data from storage and checks validity.
|
|
|
|
*
|
2018-09-26 23:35:01 +00:00
|
|
|
* @package WooCommerce Admin/Classes
|
2018-09-21 23:44:04 +00:00
|
|
|
*/
|
2018-09-26 23:35:01 +00:00
|
|
|
|
2019-07-31 19:47:32 +00:00
|
|
|
namespace Automattic\WooCommerce\Admin\Notes;
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
|
2018-09-26 23:35:01 +00:00
|
|
|
/**
|
|
|
|
* WC_Admin_Note class.
|
|
|
|
*/
|
2019-07-31 19:47:32 +00:00
|
|
|
class WC_Admin_Note extends \WC_Data {
|
2018-09-21 23:44:04 +00:00
|
|
|
|
2018-09-26 23:35:01 +00:00
|
|
|
// Note types.
|
2018-09-26 23:38:50 +00:00
|
|
|
const E_WC_ADMIN_NOTE_ERROR = 'error'; // used for presenting error conditions.
|
|
|
|
const E_WC_ADMIN_NOTE_WARNING = 'warning'; // used for presenting warning conditions.
|
|
|
|
const E_WC_ADMIN_NOTE_UPDATE = 'update'; // i.e. used when a new version is available.
|
|
|
|
const E_WC_ADMIN_NOTE_INFORMATIONAL = 'info'; // used for presenting informational messages.
|
2018-09-21 23:44:04 +00:00
|
|
|
|
2018-09-26 23:35:01 +00:00
|
|
|
// Note status codes.
|
2018-09-26 23:38:50 +00:00
|
|
|
const E_WC_ADMIN_NOTE_UNACTIONED = 'unactioned'; // the note has not yet been actioned by a user.
|
|
|
|
const E_WC_ADMIN_NOTE_ACTIONED = 'actioned'; // the note has had its action completed by a user.
|
2019-03-18 20:41:35 +00:00
|
|
|
const E_WC_ADMIN_NOTE_SNOOZED = 'snoozed'; // the note has been snoozed by a user.
|
2018-09-25 00:09:39 +00:00
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
/**
|
|
|
|
* This is the name of this object type.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $object_type = 'admin-note';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cache group.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $cache_group = 'admin-note';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Note constructor. Loads note data.
|
|
|
|
*
|
|
|
|
* @param mixed $data Note data, object, or ID.
|
|
|
|
*/
|
|
|
|
public function __construct( $data = '' ) {
|
2019-03-20 22:03:14 +00:00
|
|
|
// Set default data here to allow `content_data` to be an object.
|
|
|
|
$this->data = array(
|
|
|
|
'name' => '-',
|
|
|
|
'type' => self::E_WC_ADMIN_NOTE_INFORMATIONAL,
|
|
|
|
'locale' => 'en_US',
|
|
|
|
'title' => '-',
|
|
|
|
'content' => '-',
|
|
|
|
'icon' => 'info',
|
2019-07-31 19:47:32 +00:00
|
|
|
'content_data' => new \stdClass(),
|
2019-03-20 22:03:14 +00:00
|
|
|
'status' => self::E_WC_ADMIN_NOTE_UNACTIONED,
|
|
|
|
'source' => 'woocommerce',
|
|
|
|
'date_created' => '0000-00-00 00:00:00',
|
|
|
|
'date_reminder' => '',
|
|
|
|
'is_snoozable' => false,
|
|
|
|
'actions' => array(),
|
|
|
|
);
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
parent::__construct( $data );
|
|
|
|
|
|
|
|
if ( $data instanceof WC_Admin_Note ) {
|
|
|
|
$this->set_id( absint( $data->get_id() ) );
|
2018-10-10 23:46:08 +00:00
|
|
|
} elseif ( is_numeric( $data ) ) {
|
2018-09-21 23:44:04 +00:00
|
|
|
$this->set_id( $data );
|
|
|
|
} elseif ( is_object( $data ) && ! empty( $data->note_id ) ) {
|
|
|
|
$this->set_id( $data->note_id );
|
|
|
|
$this->set_props( (array) $data );
|
|
|
|
$this->set_object_read( true );
|
|
|
|
} else {
|
|
|
|
$this->set_object_read( true );
|
|
|
|
}
|
|
|
|
|
2019-07-31 19:47:32 +00:00
|
|
|
$this->data_store = \WC_Data_Store::load( 'admin-note' );
|
2018-09-21 23:44:04 +00:00
|
|
|
if ( $this->get_id() > 0 ) {
|
|
|
|
$this->data_store->read( $this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-24 17:13:05 +00:00
|
|
|
/**
|
|
|
|
* Merge changes with data and clear.
|
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
public function apply_changes() {
|
|
|
|
$this->data = array_replace_recursive( $this->data, $this->changes ); // @codingStandardsIgnoreLine
|
|
|
|
|
|
|
|
// Note actions need to be replaced wholesale.
|
|
|
|
// Merging arrays doesn't allow for deleting note actions.
|
|
|
|
if ( isset( $this->changes['actions'] ) ) {
|
|
|
|
$this->data['actions'] = $this->changes['actions'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->changes = array();
|
|
|
|
}
|
|
|
|
|
2018-09-25 23:55:03 +00:00
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Helpers
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
| Methods for getting allowed types, statuses.
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get allowed types.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-09-27 17:48:25 +00:00
|
|
|
public static function get_allowed_types() {
|
2018-09-25 23:55:03 +00:00
|
|
|
$allowed_types = array(
|
|
|
|
self::E_WC_ADMIN_NOTE_ERROR,
|
|
|
|
self::E_WC_ADMIN_NOTE_WARNING,
|
|
|
|
self::E_WC_ADMIN_NOTE_UPDATE,
|
|
|
|
self::E_WC_ADMIN_NOTE_INFORMATIONAL,
|
|
|
|
);
|
|
|
|
|
2019-12-05 23:06:11 +00:00
|
|
|
return apply_filters( 'woocommerce_note_types', $allowed_types );
|
2018-09-25 23:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get allowed statuses.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-09-27 17:48:25 +00:00
|
|
|
public static function get_allowed_statuses() {
|
2018-09-25 23:55:03 +00:00
|
|
|
$allowed_statuses = array(
|
|
|
|
self::E_WC_ADMIN_NOTE_ACTIONED,
|
|
|
|
self::E_WC_ADMIN_NOTE_UNACTIONED,
|
2019-03-18 20:41:35 +00:00
|
|
|
self::E_WC_ADMIN_NOTE_SNOOZED,
|
2018-09-25 23:55:03 +00:00
|
|
|
);
|
|
|
|
|
2019-12-05 23:06:11 +00:00
|
|
|
return apply_filters( 'woocommerce_note_statuses', $allowed_statuses );
|
2018-09-25 23:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Getters
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
| Methods for getting data from the note object.
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2020-04-22 16:05:11 +00:00
|
|
|
/**
|
|
|
|
* Returns all data for this object.
|
|
|
|
*
|
|
|
|
* Override \WC_Data::get_data() to avoid errantly including meta data
|
|
|
|
* from ID collisions with the posts table.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_data() {
|
|
|
|
return array_merge( array( 'id' => $this->get_id() ), $this->data );
|
|
|
|
}
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
/**
|
|
|
|
* Get note name.
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_name( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'name', $context );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get note type.
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_type( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'type', $context );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get note locale.
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_locale( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'locale', $context );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get note title.
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_title( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'title', $context );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get note content.
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_content( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'content', $context );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get note icon (Gridicon).
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_icon( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'icon', $context );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get note content data (i.e. values that would be needed for re-localization)
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_content_data( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'content_data', $context );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get note status.
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_status( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'status', $context );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get note source.
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_source( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'source', $context );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get date note was created.
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
|
|
|
* @return WC_DateTime|NULL object if the date is set or null if there is no date.
|
|
|
|
*/
|
|
|
|
public function get_date_created( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'date_created', $context );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get date on which user should be reminded of the note (if any).
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
|
|
|
* @return WC_DateTime|NULL object if the date is set or null if there is no date.
|
|
|
|
*/
|
|
|
|
public function get_date_reminder( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'date_reminder', $context );
|
|
|
|
}
|
|
|
|
|
2019-03-16 00:43:06 +00:00
|
|
|
/**
|
|
|
|
* Get note snoozability.
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
|
|
|
* @return bool Whether or not the note can be snoozed.
|
|
|
|
*/
|
|
|
|
public function get_is_snoozable( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'is_snoozable', $context );
|
|
|
|
}
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
/**
|
|
|
|
* Get actions on the note (if any).
|
|
|
|
*
|
|
|
|
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_actions( $context = 'view' ) {
|
|
|
|
return $this->get_prop( 'actions', $context );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
| Setters
|
|
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
| Methods for setting note data. These should not update anything in the
|
|
|
|
| database itself and should only change what is stored in the class
|
|
|
|
| object.
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set note name.
|
|
|
|
*
|
|
|
|
* @param string $name Note name.
|
|
|
|
*/
|
|
|
|
public function set_name( $name ) {
|
2018-09-26 23:35:01 +00:00
|
|
|
// Don't allow empty names.
|
2018-09-25 00:09:39 +00:00
|
|
|
if ( empty( $name ) ) {
|
2019-03-13 17:14:02 +00:00
|
|
|
$this->error( 'admin_note_invalid_data', __( 'The admin note name prop cannot be empty.', 'woocommerce-admin' ) );
|
2018-09-25 00:09:39 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
$this->set_prop( 'name', $name );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set note type.
|
|
|
|
*
|
|
|
|
* @param string $type Note type.
|
|
|
|
*/
|
|
|
|
public function set_type( $type ) {
|
2018-09-25 00:09:39 +00:00
|
|
|
if ( empty( $type ) ) {
|
2019-03-13 17:14:02 +00:00
|
|
|
$this->error( 'admin_note_invalid_data', __( 'The admin note type prop cannot be empty.', 'woocommerce-admin' ) );
|
2018-09-25 00:09:39 +00:00
|
|
|
}
|
|
|
|
|
2018-10-12 20:04:23 +00:00
|
|
|
if ( ! in_array( $type, self::get_allowed_types(), true ) ) {
|
2018-09-25 00:09:39 +00:00
|
|
|
$this->error(
|
|
|
|
'admin_note_invalid_data',
|
|
|
|
sprintf(
|
2018-09-26 23:35:01 +00:00
|
|
|
/* translators: %s: admin note type. */
|
2019-03-13 17:14:02 +00:00
|
|
|
__( 'The admin note type prop (%s) is not one of the supported types.', 'woocommerce-admin' ),
|
2018-09-25 00:09:39 +00:00
|
|
|
$type
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
$this->set_prop( 'type', $type );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set note locale.
|
|
|
|
*
|
|
|
|
* @param string $locale Note locale.
|
|
|
|
*/
|
|
|
|
public function set_locale( $locale ) {
|
2018-09-25 00:09:39 +00:00
|
|
|
if ( empty( $locale ) ) {
|
2019-03-13 17:14:02 +00:00
|
|
|
$this->error( 'admin_note_invalid_data', __( 'The admin note locale prop cannot be empty.', 'woocommerce-admin' ) );
|
2018-09-25 00:09:39 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
$this->set_prop( 'locale', $locale );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set note title.
|
|
|
|
*
|
|
|
|
* @param string $title Note title.
|
|
|
|
*/
|
|
|
|
public function set_title( $title ) {
|
2018-09-25 00:09:39 +00:00
|
|
|
if ( empty( $title ) ) {
|
2019-03-13 17:14:02 +00:00
|
|
|
$this->error( 'admin_note_invalid_data', __( 'The admin note title prop cannot be empty.', 'woocommerce-admin' ) );
|
2018-09-25 00:09:39 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
$this->set_prop( 'title', $title );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set note content.
|
|
|
|
*
|
|
|
|
* @param string $content Note content.
|
|
|
|
*/
|
|
|
|
public function set_content( $content ) {
|
2018-09-26 17:38:25 +00:00
|
|
|
$allowed_html = array(
|
2018-09-26 23:35:01 +00:00
|
|
|
'br' => array(),
|
|
|
|
'em' => array(),
|
2018-09-26 17:38:25 +00:00
|
|
|
'strong' => array(),
|
2019-05-21 19:34:33 +00:00
|
|
|
'a' => array(
|
|
|
|
'href' => true,
|
|
|
|
'rel' => true,
|
|
|
|
'name' => true,
|
|
|
|
'target' => true,
|
|
|
|
'download' => array(
|
|
|
|
'valueless' => 'y',
|
|
|
|
),
|
|
|
|
),
|
2019-05-29 22:28:37 +00:00
|
|
|
'p' => array(),
|
2018-09-26 17:38:25 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$content = wp_kses( $content, $allowed_html );
|
|
|
|
|
2018-09-25 00:09:39 +00:00
|
|
|
if ( empty( $content ) ) {
|
2019-03-13 17:14:02 +00:00
|
|
|
$this->error( 'admin_note_invalid_data', __( 'The admin note content prop cannot be empty.', 'woocommerce-admin' ) );
|
2018-09-25 00:09:39 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
$this->set_prop( 'content', $content );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set note icon (Gridicon).
|
|
|
|
*
|
|
|
|
* @param string $icon Note icon.
|
|
|
|
*/
|
|
|
|
public function set_icon( $icon ) {
|
2018-09-25 00:09:39 +00:00
|
|
|
if ( empty( $icon ) ) {
|
2019-03-13 17:14:02 +00:00
|
|
|
$this->error( 'admin_note_invalid_data', __( 'The admin note icon prop cannot be empty.', 'woocommerce-admin' ) );
|
2018-09-25 00:09:39 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
$this->set_prop( 'icon', $icon );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set note data for potential re-localization.
|
|
|
|
*
|
2019-03-13 17:14:02 +00:00
|
|
|
* @todo Set a default empty array? https://github.com/woocommerce/woocommerce-admin/pull/1763#pullrequestreview-212442921.
|
2018-09-26 23:35:01 +00:00
|
|
|
* @param object $content_data Note data.
|
2018-09-21 23:44:04 +00:00
|
|
|
*/
|
|
|
|
public function set_content_data( $content_data ) {
|
2018-09-25 00:09:39 +00:00
|
|
|
$allowed_type = false;
|
|
|
|
|
2018-09-26 23:35:01 +00:00
|
|
|
// Make sure $content_data is stdClass Object or an array.
|
2019-07-31 19:47:32 +00:00
|
|
|
if ( ! ( $content_data instanceof \stdClass ) ) {
|
2019-03-13 17:14:02 +00:00
|
|
|
$this->error( 'admin_note_invalid_data', __( 'The admin note content_data prop must be an instance of stdClass.', 'woocommerce-admin' ) );
|
2018-09-21 23:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->set_prop( 'content_data', $content_data );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set note status.
|
|
|
|
*
|
|
|
|
* @param string $status Note status.
|
|
|
|
*/
|
|
|
|
public function set_status( $status ) {
|
2018-09-25 00:09:39 +00:00
|
|
|
if ( empty( $status ) ) {
|
2019-03-13 17:14:02 +00:00
|
|
|
$this->error( 'admin_note_invalid_data', __( 'The admin note status prop cannot be empty.', 'woocommerce-admin' ) );
|
2018-09-25 00:09:39 +00:00
|
|
|
}
|
|
|
|
|
2018-10-12 20:04:23 +00:00
|
|
|
if ( ! in_array( $status, self::get_allowed_statuses(), true ) ) {
|
2018-09-25 00:09:39 +00:00
|
|
|
$this->error(
|
|
|
|
'admin_note_invalid_data',
|
|
|
|
sprintf(
|
2018-09-26 23:35:01 +00:00
|
|
|
/* translators: %s: admin note status property. */
|
2019-03-13 17:14:02 +00:00
|
|
|
__( 'The admin note status prop (%s) is not one of the supported statuses.', 'woocommerce-admin' ),
|
2018-09-25 00:09:39 +00:00
|
|
|
$status
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
$this->set_prop( 'status', $status );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set note source.
|
|
|
|
*
|
|
|
|
* @param string $source Note source.
|
|
|
|
*/
|
|
|
|
public function set_source( $source ) {
|
2018-09-25 00:09:39 +00:00
|
|
|
if ( empty( $source ) ) {
|
2019-03-13 17:14:02 +00:00
|
|
|
$this->error( 'admin_note_invalid_data', __( 'The admin note source prop cannot be empty.', 'woocommerce-admin' ) );
|
2018-09-25 00:09:39 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
$this->set_prop( 'source', $source );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set date note was created. NULL is not allowed
|
|
|
|
*
|
|
|
|
* @param string|integer $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed.
|
|
|
|
*/
|
|
|
|
public function set_date_created( $date ) {
|
2018-09-25 00:09:39 +00:00
|
|
|
if ( empty( $date ) ) {
|
2019-03-13 17:14:02 +00:00
|
|
|
$this->error( 'admin_note_invalid_data', __( 'The admin note date prop cannot be empty.', 'woocommerce-admin' ) );
|
2018-09-25 00:09:39 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
$this->set_date_prop( 'date_created', $date );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set date admin should be reminded of note. NULL IS allowed
|
|
|
|
*
|
|
|
|
* @param string|integer|null $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if there is no date.
|
|
|
|
*/
|
|
|
|
public function set_date_reminder( $date ) {
|
|
|
|
$this->set_date_prop( 'date_reminder', $date );
|
|
|
|
}
|
|
|
|
|
2019-03-16 00:43:06 +00:00
|
|
|
/**
|
|
|
|
* Set note snoozability.
|
|
|
|
*
|
|
|
|
* @param bool $is_snoozable Whether or not the note can be snoozed.
|
|
|
|
*/
|
|
|
|
public function set_is_snoozable( $is_snoozable ) {
|
|
|
|
return $this->set_prop( 'is_snoozable', $is_snoozable );
|
|
|
|
}
|
|
|
|
|
2018-10-26 22:07:59 +00:00
|
|
|
/**
|
|
|
|
* Clear actions from a note.
|
|
|
|
*/
|
|
|
|
public function clear_actions() {
|
|
|
|
$this->set_prop( 'actions', array() );
|
|
|
|
}
|
|
|
|
|
2018-09-21 23:44:04 +00:00
|
|
|
/**
|
|
|
|
* Add an action to the note
|
2018-09-26 23:35:01 +00:00
|
|
|
*
|
2019-05-24 17:05:12 +00:00
|
|
|
* @param string $name Action name (not presented to user).
|
|
|
|
* @param string $label Action label (presented as button label).
|
|
|
|
* @param string $url Action URL, if navigation needed. Optional.
|
|
|
|
* @param string $status Status to transition parent Note to upon click. Defaults to 'actioned'.
|
2019-05-21 19:01:55 +00:00
|
|
|
* @param boolean $primary Whether or not this is the primary action. Defaults to false.
|
|
|
|
*/
|
2019-05-24 17:05:12 +00:00
|
|
|
public function add_action( $name, $label, $url = '', $status = self::E_WC_ADMIN_NOTE_ACTIONED, $primary = false ) {
|
2019-05-21 19:01:55 +00:00
|
|
|
$name = wc_clean( $name );
|
|
|
|
$label = wc_clean( $label );
|
2019-05-24 17:05:12 +00:00
|
|
|
$query = esc_url_raw( $url );
|
2019-05-21 19:01:55 +00:00
|
|
|
$status = wc_clean( $status );
|
|
|
|
$primary = (bool) $primary;
|
2018-09-26 17:38:25 +00:00
|
|
|
|
|
|
|
if ( empty( $name ) ) {
|
2019-03-13 17:14:02 +00:00
|
|
|
$this->error( 'admin_note_invalid_data', __( 'The admin note action name prop cannot be empty.', 'woocommerce-admin' ) );
|
2018-09-26 17:38:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( empty( $label ) ) {
|
2019-03-13 17:14:02 +00:00
|
|
|
$this->error( 'admin_note_invalid_data', __( 'The admin note action label prop cannot be empty.', 'woocommerce-admin' ) );
|
2018-09-26 17:38:25 +00:00
|
|
|
}
|
2018-09-25 00:09:39 +00:00
|
|
|
|
2018-09-26 17:38:25 +00:00
|
|
|
$action = array(
|
2019-05-21 19:01:55 +00:00
|
|
|
'name' => $name,
|
|
|
|
'label' => $label,
|
|
|
|
'query' => $query,
|
|
|
|
'status' => $status,
|
|
|
|
'primary' => $primary,
|
2018-09-26 17:38:25 +00:00
|
|
|
);
|
|
|
|
|
2018-09-26 23:35:01 +00:00
|
|
|
$note_actions = $this->get_prop( 'actions', 'edit' );
|
2018-09-26 17:38:25 +00:00
|
|
|
$note_actions[] = (object) $action;
|
|
|
|
$this->set_prop( 'actions', $note_actions );
|
2018-09-21 23:44:04 +00:00
|
|
|
}
|
2019-05-24 19:20:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set actions on a note.
|
|
|
|
*
|
|
|
|
* @param array $actions Note actions.
|
|
|
|
*/
|
|
|
|
public function set_actions( $actions ) {
|
|
|
|
$this->set_prop( 'actions', $actions );
|
|
|
|
}
|
2018-09-21 23:44:04 +00:00
|
|
|
}
|