Файловый менеджер - Редактировать - /home/tuudkjt/globeasy/wp-includes/ID3/Notes.zip
Назад
PK e81]���#WM WM Note.phpnu ��� <?php /** * WooCommerce Admin (Dashboard) Notes. * * The WooCommerce admin notes class gets admin notes data from storage and checks validity. */ namespace Automattic\WooCommerce\Admin\Notes; defined( 'ABSPATH' ) || exit; /** * Note class. */ class Note extends \WC_Data { // Note types. 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. const E_WC_ADMIN_NOTE_MARKETING = 'marketing'; // used for adding marketing messages. const E_WC_ADMIN_NOTE_SURVEY = 'survey'; // used for adding survey messages. const E_WC_ADMIN_NOTE_EMAIL = 'email'; // used for adding notes that will be sent by email. // Note status codes. const E_WC_ADMIN_NOTE_PENDING = 'pending'; // the note is pending - hidden but not actioned. 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. const E_WC_ADMIN_NOTE_SNOOZED = 'snoozed'; // the note has been snoozed by a user. const E_WC_ADMIN_NOTE_SENT = 'sent'; // the note has been sent by email to the user. /** * 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 = '' ) { // 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' => '-', 'content_data' => new \stdClass(), 'status' => self::E_WC_ADMIN_NOTE_UNACTIONED, 'source' => 'woocommerce', 'date_created' => '0000-00-00 00:00:00', 'date_reminder' => null, 'is_snoozable' => false, 'actions' => array(), 'layout' => 'plain', 'image' => '', 'is_deleted' => false, 'is_read' => false, ); parent::__construct( $data ); if ( $data instanceof Note ) { $this->set_id( absint( $data->get_id() ) ); } elseif ( is_numeric( $data ) ) { $this->set_id( $data ); } elseif ( is_object( $data ) && ! empty( $data->note_id ) ) { $this->set_id( $data->note_id ); unset( $data->icon ); // Icons are deprecated. $this->set_props( (array) $data ); $this->set_object_read( true ); } else { $this->set_object_read( true ); } $this->data_store = Notes::load_data_store(); if ( $this->get_id() > 0 ) { $this->data_store->read( $this ); } } /** * 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(); } /* |-------------------------------------------------------------------------- | Helpers |-------------------------------------------------------------------------- | | Methods for getting allowed types, statuses. | */ /** * Get deprecated types. * * @return array */ public static function get_deprecated_types() { return array( self::E_WC_ADMIN_NOTE_EMAIL, ); } /** * Get allowed types. * * @return array */ public static function get_allowed_types() { $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, self::E_WC_ADMIN_NOTE_MARKETING, self::E_WC_ADMIN_NOTE_SURVEY, ); return apply_filters( 'woocommerce_note_types', $allowed_types ); } /** * Get allowed statuses. * * @return array */ public static function get_allowed_statuses() { $allowed_statuses = array( self::E_WC_ADMIN_NOTE_PENDING, self::E_WC_ADMIN_NOTE_ACTIONED, self::E_WC_ADMIN_NOTE_UNACTIONED, self::E_WC_ADMIN_NOTE_SNOOZED, self::E_WC_ADMIN_NOTE_SENT, ); return apply_filters( 'woocommerce_note_statuses', $allowed_statuses ); } /* |-------------------------------------------------------------------------- | Getters |-------------------------------------------------------------------------- | | Methods for getting data from the note object. | */ /** * 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 ); } /** * 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 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 object */ 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 ); } /** * 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 ); } /** * 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 ); } /** * Get action by action name on the note. * * @param string $action_name The action name. * @param string $context What the value is for. Valid values are 'view' and 'edit'. * @return object the action. */ public function get_action( $action_name, $context = 'view' ) { $actions = $this->get_prop( 'actions', $context ); $matching_action = null; foreach ( $actions as $i => $action ) { if ( $action->name === $action_name ) { $matching_action =& $actions[ $i ]; break; } } return $matching_action; } /** * Get note layout (the old notes won't have one). * * @param string $context What the value is for. Valid values are 'view' and 'edit'. * @return array */ public function get_layout( $context = 'view' ) { return $this->get_prop( 'layout', $context ); } /** * Get note image (if any). * * @param string $context What the value is for. Valid values are 'view' and 'edit'. * @return array */ public function get_image( $context = 'view' ) { return $this->get_prop( 'image', $context ); } /** * Get deleted status. * * @param string $context What the value is for. Valid values are 'view' and 'edit'. * @return bool */ public function get_is_deleted( $context = 'view' ) { return $this->get_prop( 'is_deleted', $context ); } /** * Get is_read status. * * @param string $context What the value is for. Valid values are 'view' and 'edit'. * @return bool */ public function get_is_read( $context = 'view' ) { return $this->get_prop( 'is_read', $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 ) { // Don't allow empty names. if ( empty( $name ) ) { $this->error( 'admin_note_invalid_data', __( 'The admin note name prop cannot be empty.', 'woocommerce' ) ); } $this->set_prop( 'name', $name ); } /** * Set note type. * * @param string $type Note type. */ public function set_type( $type ) { if ( empty( $type ) ) { $this->error( 'admin_note_invalid_data', __( 'The admin note type prop cannot be empty.', 'woocommerce' ) ); } if ( in_array( $type, self::get_deprecated_types(), true ) ) { $this->error( 'admin_note_invalid_data', __( 'The admin note type prop is deprecated.', 'woocommerce' ) ); } if ( ! in_array( $type, self::get_allowed_types(), true ) ) { $this->error( 'admin_note_invalid_data', sprintf( /* translators: %s: admin note type. */ __( 'The admin note type prop (%s) is not one of the supported types.', 'woocommerce' ), $type ) ); } $this->set_prop( 'type', $type ); } /** * Set note locale. * * @param string $locale Note locale. */ public function set_locale( $locale ) { if ( empty( $locale ) ) { $this->error( 'admin_note_invalid_data', __( 'The admin note locale prop cannot be empty.', 'woocommerce' ) ); } $this->set_prop( 'locale', $locale ); } /** * Set note title. * * @param string $title Note title. */ public function set_title( $title ) { if ( empty( $title ) ) { $this->error( 'admin_note_invalid_data', __( 'The admin note title prop cannot be empty.', 'woocommerce' ) ); } $this->set_prop( 'title', $title ); } /** * Set note icon (Deprecated). * * @param string $icon Note icon. */ public function set_icon( $icon ) { wc_deprecated_function( 'set_icon', '4.3' ); } /** * Set note content. * * @param string $content Note content. */ public function set_content( $content ) { $allowed_html = array( 'br' => array(), 'em' => array(), 'strong' => array(), 'a' => array( 'href' => true, 'rel' => true, 'name' => true, 'target' => true, 'download' => array( 'valueless' => 'y', ), ), 'p' => array(), ); $content = wp_kses( $content, $allowed_html ); if ( empty( $content ) ) { $this->error( 'admin_note_invalid_data', __( 'The admin note content prop cannot be empty.', 'woocommerce' ) ); } $this->set_prop( 'content', $content ); } /** * Set note data for potential re-localization. * * @todo Set a default empty array? https://github.com/woocommerce/woocommerce-admin/pull/1763#pullrequestreview-212442921. * @param object $content_data Note data. */ public function set_content_data( $content_data ) { $allowed_type = false; // Make sure $content_data is stdClass Object or an array. if ( ! ( $content_data instanceof \stdClass ) ) { $this->error( 'admin_note_invalid_data', __( 'The admin note content_data prop must be an instance of stdClass.', 'woocommerce' ) ); } $this->set_prop( 'content_data', $content_data ); } /** * Set note status. * * @param string $status Note status. */ public function set_status( $status ) { if ( empty( $status ) ) { $this->error( 'admin_note_invalid_data', __( 'The admin note status prop cannot be empty.', 'woocommerce' ) ); } if ( ! in_array( $status, self::get_allowed_statuses(), true ) ) { $this->error( 'admin_note_invalid_data', sprintf( /* translators: %s: admin note status property. */ __( 'The admin note status prop (%s) is not one of the supported statuses.', 'woocommerce' ), $status ) ); } $this->set_prop( 'status', $status ); } /** * Set note source. * * @param string $source Note source. */ public function set_source( $source ) { if ( empty( $source ) ) { $this->error( 'admin_note_invalid_data', __( 'The admin note source prop cannot be empty.', 'woocommerce' ) ); } $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 ) { if ( empty( $date ) ) { $this->error( 'admin_note_invalid_data', __( 'The admin note date prop cannot be empty.', 'woocommerce' ) ); } if ( is_string( $date ) && ! is_numeric( $date ) ) { $date = wc_string_to_timestamp( $date ); } $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 ) { if ( is_string( $date ) && ! is_numeric( $date ) ) { $date = wc_string_to_timestamp( $date ); } $this->set_date_prop( 'date_reminder', $date ); } /** * 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 ); } /** * Clear actions from a note. */ public function clear_actions() { $this->set_prop( 'actions', array() ); } /** * Set note layout. * * @param string $layout Note layout. */ public function set_layout( $layout ) { // If we don't receive a layout we will set it by default as "plain". if ( empty( $layout ) ) { $layout = 'plain'; } $valid_layouts = array( 'plain', 'thumbnail' ); if ( in_array( $layout, $valid_layouts, true ) ) { $this->set_prop( 'layout', $layout ); } else { $this->error( 'admin_note_invalid_data', __( 'The admin note layout has a wrong prop value.', 'woocommerce' ) ); } } /** * Set note image. * * @param string $image Note image. */ public function set_image( $image ) { $this->set_prop( 'image', $image ); } /** * Set note deleted status. NULL is not allowed * * @param bool $is_deleted Note deleted status. */ public function set_is_deleted( $is_deleted ) { $this->set_prop( 'is_deleted', $is_deleted ); } /** * Set note is_read status. NULL is not allowed * * @param bool $is_read Note is_read status. */ public function set_is_read( $is_read ) { $this->set_prop( 'is_read', $is_read ); } /** * Add an action to the note * * @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'. * @param boolean $primary Deprecated since version 3.4.0. * @param string $actioned_text The label to display after the note has been actioned but before it is dismissed in the UI. */ public function add_action( $name, $label, $url = '', $status = self::E_WC_ADMIN_NOTE_ACTIONED, $primary = false, $actioned_text = '' ) { $name = wc_clean( $name ); $label = wc_clean( $label ); $query = esc_url_raw( $url ); $status = wc_clean( $status ); $actioned_text = wc_clean( $actioned_text ); if ( empty( $name ) ) { $this->error( 'admin_note_invalid_data', __( 'The admin note action name prop cannot be empty.', 'woocommerce' ) ); } if ( empty( $label ) ) { $this->error( 'admin_note_invalid_data', __( 'The admin note action label prop cannot be empty.', 'woocommerce' ) ); } $action = array( 'name' => $name, 'label' => $label, 'query' => $query, 'status' => $status, 'actioned_text' => $actioned_text, 'nonce_name' => null, 'nonce_action' => null, ); $note_actions = $this->get_prop( 'actions', 'edit' ); $note_actions[] = (object) $action; $this->set_prop( 'actions', $note_actions ); } /** * Set actions on a note. * * @param array $actions Note actions. */ public function set_actions( $actions ) { $this->set_prop( 'actions', $actions ); } /** * Add a nonce to an existing note action. * * @link https://codex.wordpress.org/WordPress_Nonces * * @param string $note_action_name Name of action to add a nonce to. * @param string $nonce_action The nonce action. * @param string $nonce_name The nonce Name. This is used as the parameter name in the resulting URL for the action. * @return void * @throws \Exception If note name cannot be found. */ public function add_nonce_to_action( string $note_action_name, string $nonce_action, string $nonce_name ) { $actions = $this->get_prop( 'actions', 'edit' ); $matching_action = null; foreach ( $actions as $i => $action ) { if ( $action->name === $note_action_name ) { $matching_action =& $actions[ $i ]; } } if ( empty( $matching_action ) ) { throw new \Exception( sprintf( 'Could not find action %s in note %s', $note_action_name, $this->get_name() ) ); } $matching_action->nonce_action = $nonce_action; $matching_action->nonce_name = $nonce_name; $this->set_actions( $actions ); } } PK e81][G%�L7 L7 DeprecatedNotes.phpnu ��� <?php /** * Define deprecated classes to support changing the naming convention of * admin notes. */ namespace Automattic\WooCommerce\Admin\Notes; defined( 'ABSPATH' ) || exit; use Automattic\WooCommerce\Admin\DeprecatedClassFacade; // phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound /** * WC_Admin_Note. * * @deprecated since 4.8.0, use Note */ 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; const E_WC_ADMIN_NOTE_EMAIL = Note::E_WC_ADMIN_NOTE_EMAIL; /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\Notes\Note'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.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 ); } } /** * WC_Admin_Notes. * * @deprecated since 4.8.0, use Notes */ class WC_Admin_Notes extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\Notes\Notes'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Customize_Store_With_Blocks. * * @deprecated since 4.8.0, use CustomizeStoreWithBlocks */ class WC_Admin_Notes_Customize_Store_With_Blocks extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\CustomizeStoreWithBlocks'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Edit_Products_On_The_Move. * * @deprecated since 4.8.0, use EditProductsOnTheMove */ class WC_Admin_Notes_Edit_Products_On_The_Move extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\EditProductsOnTheMove'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_EU_VAT_Number. * * @deprecated since 4.8.0, use EUVATNumber */ class WC_Admin_Notes_EU_VAT_Number extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\EUVATNumber'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Facebook_Marketing_Expert. * * @deprecated since 4.8.0, use FacebookMarketingExpert */ class WC_Admin_Notes_Facebook_Marketing_Expert extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\Notes\FacebookMarketingExpert'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_First_Product. * * @deprecated since 4.8.0, use FirstProduct */ class WC_Admin_Notes_First_Product extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\FirstProduct'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Giving_Feedback_Notes. * * @deprecated since 4.8.0, use GivingFeedbackNotes */ class WC_Admin_Notes_Giving_Feedback_Notes extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\GivingFeedbackNotes'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Install_JP_And_WCS_Plugins. * * @deprecated since 4.8.0, use InstallJPAndWCSPlugins */ class WC_Admin_Notes_Install_JP_And_WCS_Plugins extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\InstallJPAndWCSPlugins'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Launch_Checklist. * * @deprecated since 4.8.0, use LaunchChecklist */ class WC_Admin_Notes_Launch_Checklist extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\LaunchChecklist'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Migrate_From_Shopify. * * @deprecated since 4.8.0, use MigrateFromShopify */ class WC_Admin_Notes_Migrate_From_Shopify extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\MigrateFromShopify'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Mobile_App. * * @deprecated since 4.8.0, use MobileApp */ class WC_Admin_Notes_Mobile_App extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\MobileApp'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_New_Sales_Record. * * @deprecated since 4.8.0, use NewSalesRecord */ class WC_Admin_Notes_New_Sales_Record extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\NewSalesRecord'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Onboarding_Email_Marketing. * * @deprecated since 4.8.0, use OnboardingEmailMarketing */ class WC_Admin_Notes_Onboarding_Email_Marketing extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\Notes\OnboardingEmailMarketing'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Onboarding_Payments. * * @deprecated since 4.8.0, use OnboardingPayments */ class WC_Admin_Notes_Onboarding_Payments extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\OnboardingPayments'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Online_Clothing_Store. * * @deprecated since 4.8.0, use OnlineClothingStore */ class WC_Admin_Notes_Online_Clothing_Store extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\OnlineClothingStore'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Order_Milestones. * * @deprecated since 4.8.0, use OrderMilestones */ class WC_Admin_Notes_Order_Milestones extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\OrderMilestones'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Performance_On_Mobile. * * @deprecated since 4.8.0, use PerformanceOnMobile */ class WC_Admin_Notes_Performance_On_Mobile extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\PerformanceOnMobile'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Personalize_Store. * * @deprecated since 4.8.0, use PersonalizeStore */ class WC_Admin_Notes_Personalize_Store extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\PersonalizeStore'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Real_Time_Order_Alerts. * * @deprecated since 4.8.0, use RealTimeOrderAlerts */ class WC_Admin_Notes_Real_Time_Order_Alerts extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\RealTimeOrderAlerts'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Selling_Online_Courses. * * @deprecated since 4.8.0, use SellingOnlineCourses */ class WC_Admin_Notes_Selling_Online_Courses extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\SellingOnlineCourses'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Tracking_Opt_In. * * @deprecated since 4.8.0, use TrackingOptIn */ class WC_Admin_Notes_Tracking_Opt_In extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\TrackingOptIn'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_Woo_Subscriptions_Notes. * * @deprecated since 4.8.0, use WooSubscriptionsNotes */ class WC_Admin_Notes_Woo_Subscriptions_Notes extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\WooSubscriptionsNotes'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_WooCommerce_Payments. * * @deprecated since 4.8.0, use WooCommercePayments */ class WC_Admin_Notes_WooCommerce_Payments extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\WooCommercePayments'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } /** * WC_Admin_Notes_WooCommerce_Subscriptions. * * @deprecated since 4.8.0, use WooCommerceSubscriptions */ class WC_Admin_Notes_WooCommerce_Subscriptions extends DeprecatedClassFacade { /** * The name of the non-deprecated class that this facade covers. * * @var string */ protected static $facade_over_classname = 'Automattic\WooCommerce\Internal\Admin\Notes\WooCommerceSubscriptions'; /** * The version that this class was deprecated in. * * @var string */ protected static $deprecated_in_version = '4.8.0'; } PK e81]���P�7 �7 Notes.phpnu ��� <?php /** * Handles storage and retrieval of admin notes */ namespace Automattic\WooCommerce\Admin\Notes; use WC_Site_Tracking; if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Admin Notes class. */ class Notes { /** * Hook used for recurring "unsnooze" action. */ const UNSNOOZE_HOOK = 'wc_admin_unsnooze_admin_notes'; /** * Hook appropriate actions. */ public static function init() { add_action( 'admin_init', array( __CLASS__, 'schedule_unsnooze_notes' ) ); add_action( 'admin_init', array( __CLASS__, 'possibly_delete_survey_notes' ) ); add_action( 'update_option_woocommerce_show_marketplace_suggestions', array( __CLASS__, 'possibly_delete_marketing_notes' ), 10, 2 ); add_action( self::UNSNOOZE_HOOK, array( __CLASS__, 'unsnooze_notes' ) ); } /** * Get notes from the database. * * @param string $context Getting notes for what context. Valid values: view, edit. * @param array $args Arguments to pass to the query( e.g. per_page and page). * @return array Array of arrays. */ public static function get_notes( $context = 'edit', $args = array() ) { $data_store = self::load_data_store(); $raw_notes = $data_store->get_notes( $args ); $notes = array(); foreach ( (array) $raw_notes as $raw_note ) { try { $note = new Note( $raw_note ); /** * Filter the note from db. This is used to modify the note before it is returned. * * @since 6.9.0 * @param Note $note The note object from the database. */ $note = apply_filters( 'woocommerce_get_note_from_db', $note ); $note_id = $note->get_id(); $notes[ $note_id ] = $note->get_data(); $notes[ $note_id ]['name'] = $note->get_name( $context ); $notes[ $note_id ]['type'] = $note->get_type( $context ); $notes[ $note_id ]['locale'] = $note->get_locale( $context ); $notes[ $note_id ]['title'] = $note->get_title( $context ); $notes[ $note_id ]['content'] = $note->get_content( $context ); $notes[ $note_id ]['content_data'] = $note->get_content_data( $context ); $notes[ $note_id ]['status'] = $note->get_status( $context ); $notes[ $note_id ]['source'] = $note->get_source( $context ); $notes[ $note_id ]['date_created'] = $note->get_date_created( $context ); $notes[ $note_id ]['date_reminder'] = $note->get_date_reminder( $context ); $notes[ $note_id ]['actions'] = $note->get_actions( $context ); $notes[ $note_id ]['layout'] = $note->get_layout( $context ); $notes[ $note_id ]['image'] = $note->get_image( $context ); $notes[ $note_id ]['is_deleted'] = $note->get_is_deleted( $context ); } catch ( \Exception $e ) { wc_caught_exception( $e, __CLASS__ . '::' . __FUNCTION__, array( $note_id ) ); } } return $notes; } /** * Get admin note using it's ID * * @param int $note_id Note ID. * @return Note|bool */ public static function get_note( $note_id ) { if ( false !== $note_id ) { try { return new Note( $note_id ); } catch ( \Exception $e ) { wc_caught_exception( $e, __CLASS__ . '::' . __FUNCTION__, array( $note_id ) ); return false; } } return false; } /** * Get admin note using its name. * * This is a shortcut for the common pattern of looking up note ids by name and then passing the first id to get_note(). * It will behave unpredictably when more than one note with the given name exists. * * @param string $note_name Note name. * @return Note|bool **/ public static function get_note_by_name( $note_name ) { $data_store = self::load_data_store(); $note_ids = $data_store->get_notes_with_name( $note_name ); if ( empty( $note_ids ) ) { return false; } return self::get_note( $note_ids[0] ); } /** * Get the total number of notes * * @param string $type Comma separated list of note types. * @param string $status Comma separated list of statuses. * @return int */ public static function get_notes_count( $type = array(), $status = array() ) { $data_store = self::load_data_store(); return $data_store->get_notes_count( $type, $status ); } /** * Deletes admin notes with a given name. * * @param string|array $names Name(s) to search for. */ public static function delete_notes_with_name( $names ) { if ( is_string( $names ) ) { $names = array( $names ); } elseif ( ! is_array( $names ) ) { return; } $data_store = self::load_data_store(); foreach ( $names as $name ) { $note_ids = $data_store->get_notes_with_name( $name ); foreach ( (array) $note_ids as $note_id ) { $note = self::get_note( $note_id ); if ( $note ) { $note->delete(); } } } } /** * Update a note. * * @param Note $note The note that will be updated. * @param array $requested_updates a list of requested updates. */ public static function update_note( $note, $requested_updates ) { $note_changed = false; if ( isset( $requested_updates['status'] ) ) { $note->set_status( $requested_updates['status'] ); $note_changed = true; } if ( isset( $requested_updates['date_reminder'] ) ) { $note->set_date_reminder( $requested_updates['date_reminder'] ); $note_changed = true; } if ( isset( $requested_updates['is_deleted'] ) ) { $note->set_is_deleted( $requested_updates['is_deleted'] ); $note_changed = true; } if ( isset( $requested_updates['is_read'] ) ) { $note->set_is_read( $requested_updates['is_read'] ); $note_changed = true; } if ( $note_changed ) { $note->save(); } } /** * Soft delete of a note. * * @param Note $note The note that will be deleted. */ public static function delete_note( $note ) { $note->set_is_deleted( 1 ); $note->save(); } /** * Soft delete of all the admin notes. Returns the deleted items. * * @param array $args Arguments to pass to the query (ex: status). * @return array Array of notes. */ public static function delete_all_notes( $args = array() ) { $data_store = self::load_data_store(); $defaults = array( 'order' => 'desc', 'orderby' => 'date_created', 'per_page' => 25, 'page' => 1, 'type' => array( Note::E_WC_ADMIN_NOTE_INFORMATIONAL, Note::E_WC_ADMIN_NOTE_MARKETING, Note::E_WC_ADMIN_NOTE_WARNING, Note::E_WC_ADMIN_NOTE_SURVEY, ), 'is_deleted' => 0, ); $args = wp_parse_args( $args, $defaults ); // Here we filter for the same params we are using to show the note list in client side. $raw_notes = $data_store->get_notes( $args ); $notes = array(); foreach ( (array) $raw_notes as $raw_note ) { $note = self::get_note( $raw_note->note_id ); if ( $note ) { self::delete_note( $note ); array_push( $notes, $note ); } } return $notes; } /** * Clear note snooze status if the reminder date has been reached. */ public static function unsnooze_notes() { $data_store = self::load_data_store(); $raw_notes = $data_store->get_notes( array( 'status' => array( Note::E_WC_ADMIN_NOTE_SNOOZED ), ) ); $now = new \DateTime(); foreach ( $raw_notes as $raw_note ) { $note = self::get_note( $raw_note->note_id ); if ( false === $note ) { continue; } $date_reminder = $note->get_date_reminder( 'edit' ); if ( $date_reminder < $now ) { $note->set_status( Note::E_WC_ADMIN_NOTE_UNACTIONED ); $note->set_date_reminder( null ); $note->save(); } } } /** * Schedule unsnooze notes event. */ public static function schedule_unsnooze_notes() { if ( ! wp_next_scheduled( self::UNSNOOZE_HOOK ) ) { wp_schedule_event( time() + 5, 'hourly', self::UNSNOOZE_HOOK ); } } /** * Unschedule unsnooze notes event. */ public static function clear_queued_actions() { wp_clear_scheduled_hook( self::UNSNOOZE_HOOK ); } /** * Delete marketing notes if marketing has been opted out. * * @param string $old_value Old value. * @param string $value New value. */ public static function possibly_delete_marketing_notes( $old_value, $value ) { if ( 'no' !== $value ) { return; } $data_store = self::load_data_store(); $note_ids = $data_store->get_note_ids_by_type( Note::E_WC_ADMIN_NOTE_MARKETING ); foreach ( $note_ids as $note_id ) { $note = self::get_note( $note_id ); if ( $note ) { $note->delete(); } } } /** * Delete actioned survey notes. */ public static function possibly_delete_survey_notes() { $data_store = self::load_data_store(); $note_ids = $data_store->get_note_ids_by_type( Note::E_WC_ADMIN_NOTE_SURVEY ); foreach ( $note_ids as $note_id ) { $note = self::get_note( $note_id ); if ( $note && ( $note->get_status() === Note::E_WC_ADMIN_NOTE_ACTIONED ) ) { $note->set_is_deleted( 1 ); $note->save(); } } } /** * Get the status of a given note by name. * * @param string $note_name Name of the note. * @return string|bool The note status. */ public static function get_note_status( $note_name ) { $note = self::get_note_by_name( $note_name ); if ( ! $note ) { return false; } return $note->get_status(); } /** * Get action by id. * * @param Note $note The note that has of the action. * @param int $action_id Action ID. * @return object|bool The found action. */ public static function get_action_by_id( $note, $action_id ) { $actions = $note->get_actions( 'edit' ); $found_action = false; foreach ( $actions as $action ) { if ( $action->id === $action_id ) { $found_action = $action; } } return $found_action; } /** * Trigger note action. * * @param Note $note The note that has the triggered action. * @param object $triggered_action The triggered action. * @return Note|bool */ public static function trigger_note_action( $note, $triggered_action ) { /** * Fires when an admin note action is taken. * * @param string $name The triggered action name. * @param Note $note The corresponding Note. */ do_action( 'woocommerce_note_action', $triggered_action->name, $note ); /** * Fires when an admin note action is taken. * For more specific targeting of note actions. * * @param Note $note The corresponding Note. */ do_action( 'woocommerce_note_action_' . $triggered_action->name, $note ); // Update the note with the status for this action. if ( ! empty( $triggered_action->status ) ) { $note->set_status( $triggered_action->status ); } $note->save(); $event_params = array( 'note_name' => $note->get_name(), 'note_type' => $note->get_type(), 'note_title' => $note->get_title(), 'note_content' => $note->get_content(), 'action_name' => $triggered_action->name, 'action_label' => $triggered_action->label, 'screen' => self::get_screen_name(), ); if ( in_array( $note->get_type(), array( 'error', 'update' ), true ) ) { wc_admin_record_tracks_event( 'store_alert_action', $event_params ); } else { self::record_tracks_event_without_cookies( 'inbox_action_click', $event_params ); } return $note; } /** * Record tracks event for a specific user. * * @param int $user_id The user id we want to record for the event. * @param string $event_name Name of the event to record. * @param array $params The params to send to the event recording. */ public static function record_tracks_event_with_user( $user_id, $event_name, $params ) { // We save the current user id to set it back after the event recording. $current_user_id = get_current_user_id(); wp_set_current_user( $user_id ); self::record_tracks_event_without_cookies( $event_name, $params ); wp_set_current_user( $current_user_id ); } /** * Record tracks event without using cookies. * * @param string $event_name Name of the event to record. * @param array $params The params to send to the event recording. */ private static function record_tracks_event_without_cookies( $event_name, $params ) { // We save the cookie to set it back after the event recording. // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $anon_id = isset( $_COOKIE['tk_ai'] ) ? $_COOKIE['tk_ai'] : null; unset( $_COOKIE['tk_ai'] ); wc_admin_record_tracks_event( $event_name, $params ); if ( isset( $anon_id ) ) { WC_Site_Tracking::set_tracking_cookie( 'tk_ai', $anon_id ); } } /** * Get screen name. * * @return string The screen name. */ public static function get_screen_name() { $screen_name = ''; if ( isset( $_SERVER['HTTP_REFERER'] ) ) { parse_str( wp_parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_QUERY ), $queries ); // phpcs:ignore sanitization ok. } if ( isset( $queries ) ) { $page = isset( $queries['page'] ) ? $queries['page'] : null; $path = isset( $queries['path'] ) ? $queries['path'] : null; $post_type = isset( $queries['post_type'] ) ? $queries['post_type'] : null; $post = isset( $queries['post'] ) ? get_post_type( $queries['post'] ) : null; } if ( isset( $page ) ) { $current_page = 'wc-admin' === $page ? 'home_screen' : $page; $screen_name = isset( $path ) ? substr( str_replace( '/', '_', $path ), 1 ) : $current_page; } elseif ( isset( $post_type ) ) { $screen_name = $post_type; } elseif ( isset( $post ) ) { $screen_name = $post; } return $screen_name; } /** * Loads the data store. * * If the "admin-note" data store is unavailable, attempts to load it * will result in an exception. * This method catches that exception and throws a custom one instead. * * @return \WC_Data_Store The "admin-note" data store. * @throws NotesUnavailableException Throws exception if data store loading fails. */ public static function load_data_store() { try { return \WC_Data_Store::load( 'admin-note' ); } catch ( \Exception $e ) { throw new NotesUnavailableException( 'woocommerce_admin_notes_unavailable', __( 'Notes are unavailable because the "admin-note" data store cannot be loaded.', 'woocommerce' ) ); } } } PK e81]�S�# # NoteTraits.phpnu ��� <?php /** * WC Admin Note Traits * * WC Admin Note Traits class that houses shared functionality across notes. */ namespace Automattic\WooCommerce\Admin\Notes; use Automattic\WooCommerce\Admin\WCAdminHelper; defined( 'ABSPATH' ) || exit; /** * NoteTraits class. */ trait NoteTraits { /** * Test how long WooCommerce Admin has been active. * * @param int $seconds Time in seconds to check. * @return bool Whether or not WooCommerce admin has been active for $seconds. */ private static function wc_admin_active_for( $seconds ) { return WCAdminHelper::is_wc_admin_active_for( $seconds ); } /** * Test if WooCommerce Admin has been active within a pre-defined range. * * @param string $range range available in WC_ADMIN_STORE_AGE_RANGES. * @param int $custom_start custom start in range. * @return bool Whether or not WooCommerce admin has been active within the range. */ private static function is_wc_admin_active_in_date_range( $range, $custom_start = null ) { return WCAdminHelper::is_wc_admin_active_in_date_range( $range, $custom_start ); } /** * Check if the note has been previously added. * * @return bool * @throws NotesUnavailableException Throws exception when notes are unavailable. */ public static function note_exists(): bool { /** * Data store instance. * * @var DataStore $data_store */ $data_store = Notes::load_data_store(); $note_ids = $data_store->get_notes_with_name( self::NOTE_NAME ); return ! empty( $note_ids ); } /** * Checks if a note can and should be added. * * @return bool * @throws NotesUnavailableException Throws exception when notes are unavailable. */ public static function can_be_added(): bool { $note = self::get_note(); if ( ! $note instanceof Note && ! $note instanceof WC_Admin_Note ) { return false; } if ( self::note_exists() ) { return false; } if ( 'no' === get_option( 'woocommerce_show_marketplace_suggestions', 'yes' ) && Note::E_WC_ADMIN_NOTE_MARKETING === $note->get_type() ) { return false; } return true; } /** * Add the note if it passes predefined conditions. * * @return void * @throws NotesUnavailableException Throws exception when notes are unavailable. */ public static function possibly_add_note(): void { $note = self::get_note(); if ( ! self::can_be_added() ) { return; } if ( $note instanceof Note || $note instanceof WC_Admin_Note ) { $note->save(); } } /** * Alias this method for backwards compatibility. * * @return void * @throws NotesUnavailableException Throws exception when notes are unavailable. */ public static function add_note(): void { self::possibly_add_note(); } /** * Should this note exist? (Default implementation is generous. Override as needed.) */ public static function is_applicable() { return true; } /** * Delete this note if it is not applicable, unless has been soft-deleted or actioned already. * * @return void */ public static function delete_if_not_applicable(): void { if ( ! self::is_applicable() ) { /** * Data store instance. * * @var DataStore $data_store */ $data_store = Notes::load_data_store(); $note_ids = $data_store->get_notes_with_name( self::NOTE_NAME ); if ( ! empty( $note_ids ) ) { $note = Notes::get_note( $note_ids[0] ); if ( $note instanceof Note && ! $note->get_is_deleted() && ( Note::E_WC_ADMIN_NOTE_ACTIONED !== $note->get_status() ) ) { self::possibly_delete_note(); } } } } /** * Possibly delete the note, if it exists in the database. Note that this * is a hard delete, for where it doesn't make sense to soft delete or * action the note. * * @return void * @throws NotesUnavailableException Throws exception when notes are unavailable. */ public static function possibly_delete_note(): void { /** * Data store instance. * * @var DataStore $data_store */ $data_store = Notes::load_data_store(); $note_ids = $data_store->get_notes_with_name( self::NOTE_NAME ); foreach ( $note_ids as $note_id ) { $note = Notes::get_note( $note_id ); if ( $note instanceof Note ) { $data_store->delete( $note ); } } } /** * Update the note if it passes predefined conditions. * * @return void * @throws NotesUnavailableException Throws exception when notes are unavailable. */ public static function possibly_update_note(): void { $note_in_db = Notes::get_note_by_name( self::NOTE_NAME ); if ( ! $note_in_db instanceof Note ) { return; } // Backwards compatibility for checking if the note class has a get_note method. /** * Backwards compatibility check. * * @phpstan-ignore-next-line */ if ( ! method_exists( self::class, 'get_note' ) ) { return; } $note = self::get_note(); if ( ! $note instanceof Note && ! $note instanceof WC_Admin_Note ) { return; } $need_save = in_array( true, array( self::update_note_field_if_changed( $note_in_db, $note, 'title' ), self::update_note_field_if_changed( $note_in_db, $note, 'content' ), self::update_note_field_if_changed( $note_in_db, $note, 'content_data' ), self::update_note_field_if_changed( $note_in_db, $note, 'type' ), self::update_note_field_if_changed( $note_in_db, $note, 'locale' ), self::update_note_field_if_changed( $note_in_db, $note, 'source' ), self::update_note_field_if_changed( $note_in_db, $note, 'actions' ), ), true ); if ( $need_save ) { $note_in_db->save(); } } /** * Get if the note has been actioned. * * @return bool * @throws NotesUnavailableException Throws exception when notes are unavailable. */ public static function has_note_been_actioned(): bool { /** * Data store instance. * * @var DataStore $data_store */ $data_store = Notes::load_data_store(); $note_ids = $data_store->get_notes_with_name( self::NOTE_NAME ); if ( ! empty( $note_ids ) ) { $note = Notes::get_note( $note_ids[0] ); if ( $note instanceof Note && Note::E_WC_ADMIN_NOTE_ACTIONED === $note->get_status() ) { return true; } } return false; } /** * Update a note field of note1 if it's different from note2 with getter and setter. * * @param Note|WC_Admin_Note $note1 Note to update. * @param Note|WC_Admin_Note $note2 Note to compare against. * @param string $field_name Field to update. * @return bool True if the field was updated. */ private static function update_note_field_if_changed( $note1, $note2, string $field_name ): bool { // We need to serialize the stdObject to compare it. /** * Getter method for note1. * * @var callable $getter1 */ $getter1 = array( $note1, 'get_' . $field_name ); /** * Getter method for note2. * * @var callable $getter2 */ $getter2 = array( $note2, 'get_' . $field_name ); $note1_field_value = self::possibly_convert_object_to_array( call_user_func( $getter1 ) ); $note2_field_value = self::possibly_convert_object_to_array( call_user_func( $getter2 ) ); if ( 'actions' === $field_name ) { // We need to individually compare the action fields because action object from db is different from action object of note. // For example, action object from db has "id". $diff = array_udiff( (array) $note1_field_value, (array) $note2_field_value, function ( $action1, $action2 ): int { /** * First action object. * * @var object{name?: string, label?: string, query?: string} $action1 */ /** * Second action object. * * @var object{name?: string, label?: string, query?: string} $action2 */ if ( isset( $action1->name, $action2->name, $action1->label, $action2->label, $action1->query, $action2->query ) && $action1->name === $action2->name && $action1->label === $action2->label && $action1->query === $action2->query ) { return 0; } return -1; } ); $need_update = count( $diff ) > 0; } else { $need_update = $note1_field_value !== $note2_field_value; } if ( $need_update ) { /** * Getter method for note2 field. * * @var callable $getter2_again */ $getter2_again = array( $note2, 'get_' . $field_name ); /** * Setter method for note1 field. * * @var callable $setter1 */ $setter1 = array( $note1, 'set_' . $field_name ); // Get note2 field again because it may have been changed during the comparison. call_user_func( $setter1, call_user_func( $getter2_again ) ); return true; } return false; } /** * Convert a value to array if it's a stdClass. * * @param mixed $obj variable to convert. * @return mixed */ private static function possibly_convert_object_to_array( $obj ) { if ( $obj instanceof \stdClass ) { return (array) $obj; } return $obj; } } PK e81]�p�Y9F 9F DataStore.phpnu ��� <?php /** * WC Admin Note Data_Store class file. */ namespace Automattic\WooCommerce\Admin\Notes; defined( 'ABSPATH' ) || exit; /** * WC Admin Note Data Store (Custom Tables) */ class DataStore extends \WC_Data_Store_WP implements \WC_Object_Data_Store_Interface { // Extensions should define their own contexts and use them to avoid applying woocommerce_note_where_clauses when not needed. const WC_ADMIN_NOTE_OPER_GLOBAL = 'global'; /** * Method to create a new note in the database. * * @param Note $note Admin note. */ public function create( &$note ) { $date_created = time(); $note->set_date_created( $date_created ); global $wpdb; $note_to_be_inserted = array( 'name' => $note->get_name(), 'type' => $note->get_type(), 'locale' => $note->get_locale(), 'title' => $note->get_title(), 'content' => $note->get_content(), 'status' => $note->get_status(), 'source' => $note->get_source(), 'is_snoozable' => (int) $note->get_is_snoozable(), 'layout' => $note->get_layout(), 'image' => $note->get_image(), 'is_deleted' => (int) $note->get_is_deleted(), 'is_read' => (int) $note->get_is_read(), ); $note_to_be_inserted['content_data'] = wp_json_encode( $note->get_content_data() ); $note_to_be_inserted['date_created'] = gmdate( 'Y-m-d H:i:s', $date_created ); $note_to_be_inserted['date_reminder'] = null; $wpdb->insert( $wpdb->prefix . 'wc_admin_notes', $note_to_be_inserted ); $note_id = $wpdb->insert_id; $note->set_id( $note_id ); $this->save_actions( $note ); $note->apply_changes(); /** * Fires when an admin note is created. * * @param int $note_id Note ID. */ do_action( 'woocommerce_note_created', $note_id ); } /** * Method to read a note. * * @param Note $note Admin note. * @throws \Exception Throws exception when invalid data is found. */ public function read( &$note ) { global $wpdb; $note->set_defaults(); $note_row = false; $note_id = $note->get_id(); if ( 0 !== $note_id || '0' !== $note_id ) { $note_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wc_admin_notes WHERE note_id = %d LIMIT 1", $note->get_id() ) ); } if ( 0 === $note->get_id() || '0' === $note->get_id() ) { $this->read_actions( $note ); $note->set_object_read( true ); /** * Fires when an admin note is loaded. * * @param int $note_id Note ID. */ do_action( 'woocommerce_note_loaded', $note ); } elseif ( $note_row ) { $note->set_name( $note_row->name ); $note->set_type( $note_row->type ); $note->set_locale( $note_row->locale ); $note->set_title( $note_row->title ); $note->set_content( $note_row->content ); // The default for 'content_value' used to be an array, so there might be rows with invalid data! $content_data = json_decode( $note_row->content_data ); if ( ! $content_data ) { $content_data = new \stdClass(); } elseif ( is_array( $content_data ) ) { $content_data = (object) $content_data; } $note->set_content_data( $content_data ); $note->set_status( $note_row->status ); $note->set_source( $note_row->source ); $note->set_date_created( $note_row->date_created ); $note->set_date_reminder( $note_row->date_reminder ); $note->set_is_snoozable( (bool) $note_row->is_snoozable ); $note->set_is_deleted( (bool) $note_row->is_deleted ); isset( $note_row->is_read ) && $note->set_is_read( (bool) $note_row->is_read ); $note->set_layout( $note_row->layout ); $note->set_image( $note_row->image ); $this->read_actions( $note ); $note->set_object_read( true ); /** * Fires when an admin note is loaded. * * @param int $note_id Note ID. */ do_action( 'woocommerce_note_loaded', $note ); } else { throw new \Exception( __( 'Invalid admin note', 'woocommerce' ) ); } } /** * Updates a note in the database. * * @param Note $note Admin note. */ public function update( &$note ) { global $wpdb; if ( $note->get_id() ) { $date_created = $note->get_date_created(); $date_created_timestamp = $date_created->getTimestamp(); $date_created_to_db = gmdate( 'Y-m-d H:i:s', $date_created_timestamp ); $date_reminder = $note->get_date_reminder(); if ( is_null( $date_reminder ) ) { $date_reminder_to_db = null; } else { $date_reminder_timestamp = $date_reminder->getTimestamp(); $date_reminder_to_db = gmdate( 'Y-m-d H:i:s', $date_reminder_timestamp ); } $wpdb->update( $wpdb->prefix . 'wc_admin_notes', array( 'name' => $note->get_name(), 'type' => $note->get_type(), 'locale' => $note->get_locale(), 'title' => $note->get_title(), 'content' => $note->get_content(), 'content_data' => wp_json_encode( $note->get_content_data() ), 'status' => $note->get_status(), 'source' => $note->get_source(), 'date_created' => $date_created_to_db, 'date_reminder' => $date_reminder_to_db, 'is_snoozable' => (int) $note->get_is_snoozable(), 'layout' => $note->get_layout(), 'image' => $note->get_image(), 'is_deleted' => (int) $note->get_is_deleted(), 'is_read' => (int) $note->get_is_read(), ), array( 'note_id' => $note->get_id() ) ); } $this->save_actions( $note ); $note->apply_changes(); /** * Fires when an admin note is updated. * * @param int $note_id Note ID. */ do_action( 'woocommerce_note_updated', $note->get_id() ); } /** * Deletes a note from the database. * * @param Note $note Admin note. * @param array $args Array of args to pass to the delete method (not used). */ public function delete( &$note, $args = array() ) { $note_id = $note->get_id(); if ( $note_id ) { global $wpdb; $wpdb->delete( $wpdb->prefix . 'wc_admin_notes', array( 'note_id' => $note_id ) ); $wpdb->delete( $wpdb->prefix . 'wc_admin_note_actions', array( 'note_id' => $note_id ) ); $note->set_id( null ); } /** * Fires when an admin note is deleted. * * @param int $note_id Note ID. */ do_action( 'woocommerce_note_deleted', $note_id ); } /** * Read actions from the database. * * @param Note $note Admin note. */ private function read_actions( &$note ) { global $wpdb; $db_actions = $wpdb->get_results( $wpdb->prepare( "SELECT action_id, name, label, query, status, actioned_text, nonce_action, nonce_name FROM {$wpdb->prefix}wc_admin_note_actions WHERE note_id = %d", $note->get_id() ) ); $note_actions = array(); if ( $db_actions ) { foreach ( $db_actions as $action ) { $note_actions[] = (object) array( 'id' => (int) $action->action_id, 'name' => $action->name, 'label' => $action->label, 'query' => $action->query, 'status' => $action->status, 'actioned_text' => $action->actioned_text, 'nonce_action' => $action->nonce_action, 'nonce_name' => $action->nonce_name, ); } } $note->set_actions( $note_actions ); } /** * Save actions to the database. * This function clears old actions, then re-inserts new if any changes are found. * * @param Note $note Note object. * * @return bool|void */ private function save_actions( &$note ) { global $wpdb; $changed_props = array_keys( $note->get_changes() ); if ( ! in_array( 'actions', $changed_props, true ) ) { return false; } // Process action removal. Actions are removed from // the note if they aren't part of the changeset. // See Note::add_action(). $changed_actions = $note->get_actions( 'edit' ); $actions_to_keep = array(); foreach ( $changed_actions as $action ) { if ( ! empty( $action->id ) ) { $actions_to_keep[] = (int) $action->id; } } $clear_actions_query = $wpdb->prepare( "DELETE FROM {$wpdb->prefix}wc_admin_note_actions WHERE note_id = %d", $note->get_id() ); if ( $actions_to_keep ) { $clear_actions_query .= sprintf( ' AND action_id NOT IN (%s)', implode( ',', $actions_to_keep ) ); } $wpdb->query( $clear_actions_query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared // Update/insert the actions in this changeset. foreach ( $changed_actions as $action ) { $action_data = array( 'note_id' => $note->get_id(), 'name' => $action->name, 'label' => $action->label, 'query' => $action->query, 'status' => $action->status, 'actioned_text' => $action->actioned_text, 'nonce_action' => $action->nonce_action, 'nonce_name' => $action->nonce_name, ); $data_format = array( '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', ); if ( ! empty( $action->id ) ) { $action_data['action_id'] = $action->id; $data_format[] = '%d'; } $wpdb->replace( $wpdb->prefix . 'wc_admin_note_actions', $action_data, $data_format ); } // Update actions from DB (to grab new IDs). $this->read_actions( $note ); } /** * Return an ordered list of notes. * * @param array $args Query arguments. * @param string $context Optional argument that the woocommerce_note_where_clauses filter can use to determine whether to apply extra conditions. Extensions should define their own contexts and use them to avoid adding to notes where clauses when not needed. * @return array An array of objects containing a note id. */ public function get_notes( $args = array(), $context = self::WC_ADMIN_NOTE_OPER_GLOBAL ) { global $wpdb; $defaults = array( 'per_page' => get_option( 'posts_per_page' ), 'page' => 1, 'order' => 'DESC', 'orderby' => 'date_created', ); $args = wp_parse_args( $args, $defaults ); $offset = $args['per_page'] * ( $args['page'] - 1 ); $where_clauses = $this->get_notes_where_clauses( $args, $context ); // sanitize order and orderby. $order_by = '`' . str_replace( '`', '', $args['orderby'] ) . '`'; $order_dir = 'asc' === strtolower( $args['order'] ) ? 'ASC' : 'DESC'; $query = $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared "SELECT * FROM {$wpdb->prefix}wc_admin_notes WHERE 1=1{$where_clauses} ORDER BY {$order_by} {$order_dir} LIMIT %d, %d", $offset, $args['per_page'] ); return $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared } /** * Return an ordered list of notes, without paging or applying the 'woocommerce_note_where_clauses' filter. * INTERNAL: This method is not intended to be used by external code, and may change without notice. * * @param array $args Query arguments. * @return array An array of database records. */ public function lookup_notes( $args = array() ) { global $wpdb; $defaults = array( 'order' => 'DESC', 'orderby' => 'date_created', ); $args = wp_parse_args( $args, $defaults ); $where_clauses = $this->args_to_where_clauses( $args ); // sanitize order and orderby. $order_by = '`' . str_replace( '`', '', $args['orderby'] ) . '`'; $order_dir = 'asc' === strtolower( $args['order'] ) ? 'ASC' : 'DESC'; $query = "SELECT * FROM {$wpdb->prefix}wc_admin_notes WHERE 1=1{$where_clauses} ORDER BY {$order_by} {$order_dir}"; return $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared } /** * Return a count of notes. * * @param string $type Comma separated list of note types. * @param string $status Comma separated list of statuses. * @param string $context Optional argument that the woocommerce_note_where_clauses filter can use to determine whether to apply extra conditions. Extensions should define their own contexts and use them to avoid adding to notes where clauses when not needed. * @return string Count of objects with given type, status and context. */ public function get_notes_count( $type = array(), $status = array(), $context = self::WC_ADMIN_NOTE_OPER_GLOBAL ) { global $wpdb; $where_clauses = $this->get_notes_where_clauses( array( 'type' => $type, 'status' => $status, ), $context ); if ( ! empty( $where_clauses ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared return $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}wc_admin_notes WHERE 1=1{$where_clauses}" ); } return $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}wc_admin_notes" ); } /** * Parses the query arguments passed in as arrays and escapes the values. * * @param array $args the query arguments. * @param string $key the key of the specific argument. * @param array|null $allowed_types optional allowed_types if only a specific set is allowed. * @return array the escaped array of argument values. */ private function get_escaped_arguments_array_by_key( $args = array(), $key = '', $allowed_types = null ) { $arg_array = array(); if ( isset( $args[ $key ] ) ) { foreach ( $args[ $key ] as $args_type ) { $args_type = trim( $args_type ); $allowed = is_null( $allowed_types ) || in_array( $args_type, $allowed_types, true ); if ( $allowed ) { $arg_array[] = sprintf( "'%s'", esc_sql( $args_type ) ); } } } return $arg_array; } /** * Return where clauses for getting notes by status and type. For use in both the count and listing queries. * Applies woocommerce_note_where_clauses filter. * * @uses args_to_where_clauses * @param array $args Array of args to pass. * @param string $context Optional argument that the woocommerce_note_where_clauses filter can use to determine whether to apply extra conditions. Extensions should define their own contexts and use them to avoid adding to notes where clauses when not needed. * @return string Where clauses for the query. */ public function get_notes_where_clauses( $args = array(), $context = self::WC_ADMIN_NOTE_OPER_GLOBAL ) { $where_clauses = $this->args_to_where_clauses( $args ); /** * Filter the notes WHERE clause before retrieving the data. * * Allows modification of the notes select criterial. * * @param string $where_clauses The generated WHERE clause. * @param array $args The original arguments for the request. * @param string $context Optional argument that the woocommerce_note_where_clauses filter can use to determine whether to apply extra conditions. Extensions should define their own contexts and use them to avoid adding to notes where clauses when not needed. */ return apply_filters( 'woocommerce_note_where_clauses', $where_clauses, $args, $context ); } /** * Return where clauses for notes queries without applying woocommerce_note_where_clauses filter. * INTERNAL: This method is not intended to be used by external code, and may change without notice. * * @param array $args Array of arguments for query conditionals. * @return string Where clauses. */ protected function args_to_where_clauses( $args = array() ) { $allowed_types = Note::get_allowed_types(); $where_type_array = $this->get_escaped_arguments_array_by_key( $args, 'type', $allowed_types ); $allowed_statuses = Note::get_allowed_statuses(); $where_status_array = $this->get_escaped_arguments_array_by_key( $args, 'status', $allowed_statuses ); $escaped_is_deleted = ''; if ( isset( $args['is_deleted'] ) ) { $escaped_is_deleted = esc_sql( $args['is_deleted'] ); } $where_name_array = $this->get_escaped_arguments_array_by_key( $args, 'name' ); $where_excluded_name_array = $this->get_escaped_arguments_array_by_key( $args, 'excluded_name' ); $where_source_array = $this->get_escaped_arguments_array_by_key( $args, 'source' ); $escaped_where_types = implode( ',', $where_type_array ); $escaped_where_status = implode( ',', $where_status_array ); $escaped_where_names = implode( ',', $where_name_array ); $escaped_where_excluded_names = implode( ',', $where_excluded_name_array ); $escaped_where_source = implode( ',', $where_source_array ); $where_clauses = ''; if ( ! empty( $escaped_where_types ) ) { $where_clauses .= " AND type IN ($escaped_where_types)"; } if ( ! empty( $escaped_where_status ) ) { $where_clauses .= " AND status IN ($escaped_where_status)"; } if ( ! empty( $escaped_where_names ) ) { $where_clauses .= " AND name IN ($escaped_where_names)"; } if ( ! empty( $escaped_where_excluded_names ) ) { $where_clauses .= " AND name NOT IN ($escaped_where_excluded_names)"; } if ( ! empty( $escaped_where_source ) ) { $where_clauses .= " AND source IN ($escaped_where_source)"; } if ( isset( $args['is_read'] ) ) { $where_clauses .= $args['is_read'] ? ' AND is_read = 1' : ' AND is_read = 0'; } $where_clauses .= $escaped_is_deleted ? ' AND is_deleted = 1' : ' AND is_deleted = 0'; return $where_clauses; } /** * Find all the notes with a given name. * * @param string $name Name to search for. * @return array An array of matching note ids. */ public function get_notes_with_name( $name ) { global $wpdb; return $wpdb->get_col( $wpdb->prepare( "SELECT note_id FROM {$wpdb->prefix}wc_admin_notes WHERE name = %s ORDER BY note_id ASC", $name ) ); } /** * Find the ids of all notes with a given type. * * @param string $note_type Type to search for. * @return array An array of matching note ids. */ public function get_note_ids_by_type( $note_type ) { global $wpdb; return $wpdb->get_col( $wpdb->prepare( "SELECT note_id FROM {$wpdb->prefix}wc_admin_notes WHERE type = %s ORDER BY note_id ASC", $note_type ) ); } } PK e81]�I>a a NotesUnavailableException.phpnu ��� <?php /** * WooCommerce Admin Notes Unavailable Exception Class * * Exception class thrown when an attempt to use notes is made but notes are unavailable. */ namespace Automattic\WooCommerce\Admin\Notes; defined( 'ABSPATH' ) || exit; /** * Notes\NotesUnavailableException class. */ class NotesUnavailableException extends \WC_Data_Exception {} PK e81]���#WM WM Note.phpnu ��� PK e81][G%�L7 L7 �M DeprecatedNotes.phpnu ��� PK e81]���P�7 �7 � Notes.phpnu ��� PK e81]�S�# # �� NoteTraits.phpnu ��� PK e81]�p�Y9F 9F Y� DataStore.phpnu ��� PK e81]�I>a a �& NotesUnavailableException.phpnu ��� PK � }(
| ver. 1.6 |
Github
|
.
| PHP 8.1.34 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка