PHPCS all the things
This commit is contained in:
parent
677c205ad2
commit
cb7a5b3607
|
@ -4,20 +4,25 @@
|
||||||
*
|
*
|
||||||
* The WooCommerce admin notes class gets admin notes data from storage and checks validity.
|
* The WooCommerce admin notes class gets admin notes data from storage and checks validity.
|
||||||
*
|
*
|
||||||
|
* @package WooCommerce Admin/Classes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined( 'ABSPATH' ) || exit;
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WC_Admin_Note class.
|
||||||
|
*/
|
||||||
class WC_Admin_Note extends WC_Data {
|
class WC_Admin_Note extends WC_Data {
|
||||||
|
|
||||||
// Note types
|
// Note types.
|
||||||
const E_WC_ADMIN_NOTE_ERROR = 'error';
|
const E_WC_ADMIN_NOTE_ERROR = 'error';
|
||||||
const E_WC_ADMIN_NOTE_WARNING = 'warning';
|
const E_WC_ADMIN_NOTE_WARNING = 'warning';
|
||||||
const E_WC_ADMIN_NOTE_UPDATE = 'update'; // i.e. a new version is available
|
const E_WC_ADMIN_NOTE_UPDATE = 'update'; // i.e. a new version is available.
|
||||||
const E_WC_ADMIN_NOTE_INFORMATIONAL = 'info';
|
const E_WC_ADMIN_NOTE_INFORMATIONAL = 'info';
|
||||||
|
|
||||||
// Note status codes
|
// Note status codes.
|
||||||
const E_WC_ADMIN_NOTE_UNACTIONED = 'unactioned';
|
const E_WC_ADMIN_NOTE_UNACTIONED = 'unactioned';
|
||||||
const E_WC_ADMIN_NOTE_ACTIONED = 'actioned';
|
const E_WC_ADMIN_NOTE_ACTIONED = 'actioned';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the name of this object type.
|
* This is the name of this object type.
|
||||||
|
@ -265,7 +270,7 @@ class WC_Admin_Note extends WC_Data {
|
||||||
* @param string $name Note name.
|
* @param string $name Note name.
|
||||||
*/
|
*/
|
||||||
public function set_name( $name ) {
|
public function set_name( $name ) {
|
||||||
// Don't allow empty names
|
// Don't allow empty names.
|
||||||
if ( empty( $name ) ) {
|
if ( empty( $name ) ) {
|
||||||
$this->error( 'admin_note_invalid_data', __( 'The admin note name prop cannot be empty.', 'woocommerce' ) );
|
$this->error( 'admin_note_invalid_data', __( 'The admin note name prop cannot be empty.', 'woocommerce' ) );
|
||||||
}
|
}
|
||||||
|
@ -287,6 +292,7 @@ class WC_Admin_Note extends WC_Data {
|
||||||
$this->error(
|
$this->error(
|
||||||
'admin_note_invalid_data',
|
'admin_note_invalid_data',
|
||||||
sprintf(
|
sprintf(
|
||||||
|
/* translators: %s: admin note type. */
|
||||||
__( 'The admin note type prop (%s) is not one of the supported types.', 'woocommerce' ),
|
__( 'The admin note type prop (%s) is not one of the supported types.', 'woocommerce' ),
|
||||||
$type
|
$type
|
||||||
)
|
)
|
||||||
|
@ -329,8 +335,8 @@ class WC_Admin_Note extends WC_Data {
|
||||||
*/
|
*/
|
||||||
public function set_content( $content ) {
|
public function set_content( $content ) {
|
||||||
$allowed_html = array(
|
$allowed_html = array(
|
||||||
'br' => array(),
|
'br' => array(),
|
||||||
'em' => array(),
|
'em' => array(),
|
||||||
'strong' => array(),
|
'strong' => array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -359,12 +365,12 @@ class WC_Admin_Note extends WC_Data {
|
||||||
/**
|
/**
|
||||||
* Set note data for potential re-localization.
|
* Set note data for potential re-localization.
|
||||||
*
|
*
|
||||||
* @param object $data Note data.
|
* @param object $content_data Note data.
|
||||||
*/
|
*/
|
||||||
public function set_content_data( $content_data ) {
|
public function set_content_data( $content_data ) {
|
||||||
$allowed_type = false;
|
$allowed_type = false;
|
||||||
|
|
||||||
// Make sure $content_data is stdClass Object or an array
|
// Make sure $content_data is stdClass Object or an array.
|
||||||
if ( ! ( $content_data instanceof stdClass ) ) {
|
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->error( 'admin_note_invalid_data', __( 'The admin note content_data prop must be an instance of stdClass.', 'woocommerce' ) );
|
||||||
}
|
}
|
||||||
|
@ -386,6 +392,7 @@ class WC_Admin_Note extends WC_Data {
|
||||||
$this->error(
|
$this->error(
|
||||||
'admin_note_invalid_data',
|
'admin_note_invalid_data',
|
||||||
sprintf(
|
sprintf(
|
||||||
|
/* translators: %s: admin note status property. */
|
||||||
__( 'The admin note status prop (%s) is not one of the supported statuses.', 'woocommerce' ),
|
__( 'The admin note status prop (%s) is not one of the supported statuses.', 'woocommerce' ),
|
||||||
$status
|
$status
|
||||||
)
|
)
|
||||||
|
@ -432,9 +439,13 @@ class WC_Admin_Note extends WC_Data {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an action to the note
|
* Add an action to the note
|
||||||
|
*
|
||||||
|
* @param string $name Label name (not presented to user).
|
||||||
|
* @param string $label Note label (e.g. presented as button label).
|
||||||
|
* @param string $query Note query (for redirect).
|
||||||
*/
|
*/
|
||||||
public function add_action( $name, $label, $query ) {
|
public function add_action( $name, $label, $query ) {
|
||||||
$name = wc_clean( $name );
|
$name = wc_clean( $name );
|
||||||
$label = wc_clean( $label );
|
$label = wc_clean( $label );
|
||||||
$query = wc_clean( $query );
|
$query = wc_clean( $query );
|
||||||
|
|
||||||
|
@ -456,7 +467,7 @@ class WC_Admin_Note extends WC_Data {
|
||||||
'query' => $query,
|
'query' => $query,
|
||||||
);
|
);
|
||||||
|
|
||||||
$note_actions = $this->get_prop( 'actions', 'edit' );
|
$note_actions = $this->get_prop( 'actions', 'edit' );
|
||||||
$note_actions[] = (object) $action;
|
$note_actions[] = (object) $action;
|
||||||
$this->set_prop( 'actions', $note_actions );
|
$this->set_prop( 'actions', $note_actions );
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
/**
|
/**
|
||||||
* Handles storage and retrieval of admin notes
|
* Handles storage and retrieval of admin notes
|
||||||
*
|
*
|
||||||
|
* @package WooCommerce Admin/Classes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WC_Admin_Note_Data_Store class file.
|
* WC_Admin_Note_Data_Store class file.
|
||||||
*
|
*
|
||||||
|
@ -15,7 +14,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
/**
|
/**
|
||||||
* Method to create a new note in the database.
|
* Method to create a new note in the database.
|
||||||
*
|
*
|
||||||
* @param WC_Admin_Note
|
* @param WC_Admin_Note $note Admin note.
|
||||||
*/
|
*/
|
||||||
public function create( &$note ) {
|
public function create( &$note ) {
|
||||||
$date_created = current_time( 'timestamp', 1 );
|
$date_created = current_time( 'timestamp', 1 );
|
||||||
|
@ -24,14 +23,14 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$note_to_be_inserted = array(
|
$note_to_be_inserted = array(
|
||||||
'name' => $note->get_name(),
|
'name' => $note->get_name(),
|
||||||
'type' => $note->get_type(),
|
'type' => $note->get_type(),
|
||||||
'locale' => $note->get_locale(),
|
'locale' => $note->get_locale(),
|
||||||
'title' => $note->get_title(),
|
'title' => $note->get_title(),
|
||||||
'content' => $note->get_content(),
|
'content' => $note->get_content(),
|
||||||
'icon' => $note->get_icon(),
|
'icon' => $note->get_icon(),
|
||||||
'status' => $note->get_status(),
|
'status' => $note->get_status(),
|
||||||
'source' => $note->get_source(),
|
'source' => $note->get_source(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$note_to_be_inserted['content_data'] = wp_json_encode( $note->get_content_data(), JSON_FORCE_OBJECT );
|
$note_to_be_inserted['content_data'] = wp_json_encode( $note->get_content_data(), JSON_FORCE_OBJECT );
|
||||||
|
@ -51,7 +50,8 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
/**
|
/**
|
||||||
* Method to read a note.
|
* Method to read a note.
|
||||||
*
|
*
|
||||||
* @param WC_Admin_Note
|
* @param WC_Admin_Note $note Admin note.
|
||||||
|
* @throws Exception Throws exception when invalid data is found.
|
||||||
*/
|
*/
|
||||||
public function read( &$note ) {
|
public function read( &$note ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
@ -98,7 +98,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
/**
|
/**
|
||||||
* Updates a note in the database.
|
* Updates a note in the database.
|
||||||
*
|
*
|
||||||
* @param WC_Admin_Note
|
* @param WC_Admin_Note $note Admin note.
|
||||||
*/
|
*/
|
||||||
public function update( &$note ) {
|
public function update( &$note ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
@ -130,8 +130,8 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
/**
|
/**
|
||||||
* Deletes a note from the database.
|
* Deletes a note from the database.
|
||||||
*
|
*
|
||||||
* @param WC_Admin_Note
|
* @param WC_Admin_Note $note Admin note.
|
||||||
* @param array $args Array of args to pass to the delete method (not used).
|
* @param array $args Array of args to pass to the delete method (not used).
|
||||||
*/
|
*/
|
||||||
public function delete( &$note, $args = array() ) {
|
public function delete( &$note, $args = array() ) {
|
||||||
$note_id = $note->get_id();
|
$note_id = $note->get_id();
|
||||||
|
@ -147,8 +147,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
/**
|
/**
|
||||||
* Read actions from the database.
|
* Read actions from the database.
|
||||||
*
|
*
|
||||||
* @param WC_Admin_Note $note Note object.
|
* @param WC_Admin_Note $note Admin note.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
private function read_actions( &$note ) {
|
private function read_actions( &$note ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
Loading…
Reference in New Issue