Fix static visibility, textdomain and use of JSON_FORCE_OBJECT

This commit is contained in:
Allen Snook 2018-09-27 10:48:25 -07:00
parent db7456ae55
commit e5e175cfab
2 changed files with 24 additions and 21 deletions

View File

@ -98,7 +98,7 @@ class WC_Admin_Note extends WC_Data {
*
* @return array
*/
static public function get_allowed_types() {
public static function get_allowed_types() {
$allowed_types = array(
self::E_WC_ADMIN_NOTE_ERROR,
self::E_WC_ADMIN_NOTE_WARNING,
@ -114,7 +114,7 @@ class WC_Admin_Note extends WC_Data {
*
* @return array
*/
static public function get_allowed_statuses() {
public static function get_allowed_statuses() {
$allowed_statuses = array(
self::E_WC_ADMIN_NOTE_ACTIONED,
self::E_WC_ADMIN_NOTE_UNACTIONED,
@ -272,7 +272,7 @@ class WC_Admin_Note extends WC_Data {
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->error( 'admin_note_invalid_data', __( 'The admin note name prop cannot be empty.', 'wc-admin' ) );
}
$this->set_prop( 'name', $name );
@ -285,7 +285,7 @@ class WC_Admin_Note extends WC_Data {
*/
public function set_type( $type ) {
if ( empty( $type ) ) {
$this->error( 'admin_note_invalid_data', __( 'The admin note type prop cannot be empty.', 'woocommerce' ) );
$this->error( 'admin_note_invalid_data', __( 'The admin note type prop cannot be empty.', 'wc-admin' ) );
}
if ( ! in_array( $type, self::get_allowed_types() ) ) {
@ -293,7 +293,7 @@ class WC_Admin_Note extends WC_Data {
'admin_note_invalid_data',
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.', 'wc-admin' ),
$type
)
);
@ -309,7 +309,7 @@ class WC_Admin_Note extends WC_Data {
*/
public function set_locale( $locale ) {
if ( empty( $locale ) ) {
$this->error( 'admin_note_invalid_data', __( 'The admin note locale prop cannot be empty.', 'woocommerce' ) );
$this->error( 'admin_note_invalid_data', __( 'The admin note locale prop cannot be empty.', 'wc-admin' ) );
}
$this->set_prop( 'locale', $locale );
@ -322,7 +322,7 @@ class WC_Admin_Note extends WC_Data {
*/
public function set_title( $title ) {
if ( empty( $title ) ) {
$this->error( 'admin_note_invalid_data', __( 'The admin note title prop cannot be empty.', 'woocommerce' ) );
$this->error( 'admin_note_invalid_data', __( 'The admin note title prop cannot be empty.', 'wc-admin' ) );
}
$this->set_prop( 'title', $title );
@ -343,7 +343,7 @@ class WC_Admin_Note extends WC_Data {
$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->error( 'admin_note_invalid_data', __( 'The admin note content prop cannot be empty.', 'wc-admin' ) );
}
$this->set_prop( 'content', $content );
@ -356,7 +356,7 @@ class WC_Admin_Note extends WC_Data {
*/
public function set_icon( $icon ) {
if ( empty( $icon ) ) {
$this->error( 'admin_note_invalid_data', __( 'The admin note icon prop cannot be empty.', 'woocommerce' ) );
$this->error( 'admin_note_invalid_data', __( 'The admin note icon prop cannot be empty.', 'wc-admin' ) );
}
$this->set_prop( 'icon', $icon );
@ -372,7 +372,7 @@ class WC_Admin_Note extends WC_Data {
// 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->error( 'admin_note_invalid_data', __( 'The admin note content_data prop must be an instance of stdClass.', 'wc-admin' ) );
}
$this->set_prop( 'content_data', $content_data );
@ -385,7 +385,7 @@ class WC_Admin_Note extends WC_Data {
*/
public function set_status( $status ) {
if ( empty( $status ) ) {
$this->error( 'admin_note_invalid_data', __( 'The admin note status prop cannot be empty.', 'woocommerce' ) );
$this->error( 'admin_note_invalid_data', __( 'The admin note status prop cannot be empty.', 'wc-admin' ) );
}
if ( ! in_array( $status, self::get_allowed_statuses() ) ) {
@ -393,7 +393,7 @@ class WC_Admin_Note extends WC_Data {
'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' ),
__( 'The admin note status prop (%s) is not one of the supported statuses.', 'wc-admin' ),
$status
)
);
@ -409,7 +409,7 @@ class WC_Admin_Note extends WC_Data {
*/
public function set_source( $source ) {
if ( empty( $source ) ) {
$this->error( 'admin_note_invalid_data', __( 'The admin note source prop cannot be empty.', 'woocommerce' ) );
$this->error( 'admin_note_invalid_data', __( 'The admin note source prop cannot be empty.', 'wc-admin' ) );
}
$this->set_prop( 'source', $source );
@ -422,7 +422,7 @@ class WC_Admin_Note extends WC_Data {
*/
public function set_date_created( $date ) {
if ( empty( $date ) ) {
$this->error( 'admin_note_invalid_data', __( 'The admin note date prop cannot be empty.', 'woocommerce' ) );
$this->error( 'admin_note_invalid_data', __( 'The admin note date prop cannot be empty.', 'wc-admin' ) );
}
$this->set_date_prop( 'date_created', $date );
@ -450,15 +450,15 @@ class WC_Admin_Note extends WC_Data {
$query = wc_clean( $query );
if ( empty( $name ) ) {
$this->error( 'admin_note_invalid_data', __( 'The admin note action name prop cannot be empty.', 'woocommerce' ) );
$this->error( 'admin_note_invalid_data', __( 'The admin note action name prop cannot be empty.', 'wc-admin' ) );
}
if ( empty( $label ) ) {
$this->error( 'admin_note_invalid_data', __( 'The admin note action label prop cannot be empty.', 'woocommerce' ) );
$this->error( 'admin_note_invalid_data', __( 'The admin note action label prop cannot be empty.', 'wc-admin' ) );
}
if ( empty( $query ) ) {
$this->error( 'admin_note_invalid_data', __( 'The admin note action query prop cannot be empty.', 'woocommerce' ) );
$this->error( 'admin_note_invalid_data', __( 'The admin note action query prop cannot be empty.', 'wc-admin' ) );
}
$action = array(

View File

@ -33,7 +33,9 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
'source' => $note->get_source(),
);
$note_to_be_inserted['content_data'] = wp_json_encode( $note->get_content_data(), JSON_FORCE_OBJECT );
$encoding_options = defined( 'JSON_FORCE_OBJECT' ) ? JSON_FORCE_OBJECT : 0;
$note_to_be_inserted['content_data'] = wp_json_encode( $note->get_content_data(), $encoding_options );
$note_to_be_inserted['date_created'] = gmdate( 'Y-m-d H:i:s', $date_created );
$note_to_be_inserted['date_reminder'] = null;
@ -91,7 +93,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
$note->set_object_read( true );
do_action( 'woocommerce_admin_note_loaded', $note );
} else {
throw new Exception( __( 'Invalid data store for admin note.', 'woocommerce' ) );
throw new Exception( __( 'Invalid data store for admin note.', 'wc-admin' ) );
}
}
@ -102,8 +104,9 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
*/
public function update( &$note ) {
global $wpdb;
if ( $note->get_id() ) {
$encoding_options = defined( 'JSON_FORCE_OBJECT' ) ? JSON_FORCE_OBJECT : 0;
if ( $note->get_id() ) {
$wpdb->update(
$wpdb->prefix . 'woocommerce_admin_notes', array(
'name' => $note->get_name(),
@ -112,7 +115,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
'title' => $note->get_title(),
'content' => $note->get_content(),
'icon' => $note->get_icon(),
'content_data' => wp_json_encode( $note->get_content_data(), JSON_FORCE_OBJECT ),
'content_data' => wp_json_encode( $note->get_content_data(), $encoding_options ),
'status' => $note->get_status(),
'source' => $note->get_source(),
'date_created' => $note->get_date_created(),