Fix per_page default handling, json encoding options, schema help
This commit is contained in:
parent
d450ea6545
commit
2a94177f71
|
@ -92,7 +92,7 @@ class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller {
|
||||||
public function get_items( $request ) {
|
public function get_items( $request ) {
|
||||||
$per_page = isset( $request['per_page'] ) ? intval( $request['per_page'] ) : 10;
|
$per_page = isset( $request['per_page'] ) ? intval( $request['per_page'] ) : 10;
|
||||||
if ( $per_page <= 0 ) {
|
if ( $per_page <= 0 ) {
|
||||||
$per_page = 1;
|
$per_page = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = isset( $request['page'] ) ? intval( $request['page'] ) : 1;
|
$page = isset( $request['page'] ) ? intval( $request['page'] ) : 1;
|
||||||
|
@ -214,7 +214,7 @@ class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller {
|
||||||
);
|
);
|
||||||
|
|
||||||
$schema['properties']['type'] = array(
|
$schema['properties']['type'] = array(
|
||||||
'description' => __( 'Type of the note.', 'wc-admin' ),
|
'description' => __( 'The type of the note (e.g. error, warning, etc.).', 'wc-admin' ),
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'context' => array( 'view', 'edit' ),
|
'context' => array( 'view', 'edit' ),
|
||||||
'readonly' => true,
|
'readonly' => true,
|
||||||
|
@ -256,7 +256,7 @@ class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller {
|
||||||
);
|
);
|
||||||
|
|
||||||
$schema['properties']['status'] = array(
|
$schema['properties']['status'] = array(
|
||||||
'description' => __( 'Status of the note.', 'wc-admin' ),
|
'description' => __( 'The status of the note (e.g. unactioned, actioned).', 'wc-admin' ),
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'context' => array( 'view', 'edit' ),
|
'context' => array( 'view', 'edit' ),
|
||||||
'readonly' => true,
|
'readonly' => true,
|
||||||
|
|
|
@ -288,7 +288,7 @@ class WC_Admin_Note extends WC_Data {
|
||||||
$this->error( 'admin_note_invalid_data', __( 'The admin note type prop cannot be empty.', 'wc-admin' ) );
|
$this->error( 'admin_note_invalid_data', __( 'The admin note type prop cannot be empty.', 'wc-admin' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! in_array( $type, self::get_allowed_types() ) ) {
|
if ( ! in_array( $type, self::get_allowed_types(), true ) ) {
|
||||||
$this->error(
|
$this->error(
|
||||||
'admin_note_invalid_data',
|
'admin_note_invalid_data',
|
||||||
sprintf(
|
sprintf(
|
||||||
|
@ -388,7 +388,7 @@ class WC_Admin_Note extends WC_Data {
|
||||||
$this->error( 'admin_note_invalid_data', __( 'The admin note status prop cannot be empty.', 'wc-admin' ) );
|
$this->error( 'admin_note_invalid_data', __( 'The admin note status prop cannot be empty.', 'wc-admin' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! in_array( $status, self::get_allowed_statuses() ) ) {
|
if ( ! in_array( $status, self::get_allowed_statuses(), true ) ) {
|
||||||
$this->error(
|
$this->error(
|
||||||
'admin_note_invalid_data',
|
'admin_note_invalid_data',
|
||||||
sprintf(
|
sprintf(
|
||||||
|
|
|
@ -33,9 +33,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
'source' => $note->get_source(),
|
'source' => $note->get_source(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$encoding_options = defined( 'JSON_FORCE_OBJECT' ) ? JSON_FORCE_OBJECT : 0; // phpcs:ignore PHPCompatibility.PHP.NewConstants
|
$note_to_be_inserted['content_data'] = wp_json_encode( $note->get_content_data() );
|
||||||
|
|
||||||
$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_created'] = gmdate( 'Y-m-d H:i:s', $date_created );
|
||||||
$note_to_be_inserted['date_reminder'] = null;
|
$note_to_be_inserted['date_reminder'] = null;
|
||||||
|
|
||||||
|
@ -104,7 +102,6 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
*/
|
*/
|
||||||
public function update( &$note ) {
|
public function update( &$note ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$encoding_options = defined( 'JSON_FORCE_OBJECT' ) ? JSON_FORCE_OBJECT : 0; // phpcs:ignore PHPCompatibility.PHP.NewConstants
|
|
||||||
|
|
||||||
if ( $note->get_id() ) {
|
if ( $note->get_id() ) {
|
||||||
$wpdb->update(
|
$wpdb->update(
|
||||||
|
@ -115,7 +112,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
'title' => $note->get_title(),
|
'title' => $note->get_title(),
|
||||||
'content' => $note->get_content(),
|
'content' => $note->get_content(),
|
||||||
'icon' => $note->get_icon(),
|
'icon' => $note->get_icon(),
|
||||||
'content_data' => wp_json_encode( $note->get_content_data(), $encoding_options ),
|
'content_data' => wp_json_encode( $note->get_content_data() ),
|
||||||
'status' => $note->get_status(),
|
'status' => $note->get_status(),
|
||||||
'source' => $note->get_source(),
|
'source' => $note->get_source(),
|
||||||
'date_created' => $note->get_date_created(),
|
'date_created' => $note->get_date_created(),
|
||||||
|
@ -214,7 +211,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
|
|
||||||
$per_page = isset( $args['per_page'] ) ? intval( $args['per_page'] ) : 10;
|
$per_page = isset( $args['per_page'] ) ? intval( $args['per_page'] ) : 10;
|
||||||
if ( $per_page <= 0 ) {
|
if ( $per_page <= 0 ) {
|
||||||
$per_page = 1;
|
$per_page = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = isset( $args['page'] ) ? intval( $args['page'] ) : 1;
|
$page = isset( $args['page'] ) ? intval( $args['page'] ) : 1;
|
||||||
|
|
Loading…
Reference in New Issue