Rewrite the queries a bit to leverage prepare when possible
This commit is contained in:
parent
bb14dcd995
commit
a46d83aea3
|
@ -205,13 +205,6 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
public function get_notes( $args = array() ) {
|
public function get_notes( $args = array() ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
// Build the query.
|
|
||||||
$query = "
|
|
||||||
SELECT note_id, title, content
|
|
||||||
FROM {$wpdb->prefix}woocommerce_admin_notes
|
|
||||||
ORDER BY note_id DESC
|
|
||||||
";
|
|
||||||
|
|
||||||
$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 = 10;
|
$per_page = 10;
|
||||||
|
@ -225,7 +218,13 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
$offset = $per_page * ( $page - 1 );
|
$offset = $per_page * ( $page - 1 );
|
||||||
$pagination = sprintf( ' LIMIT %d, %d', $offset, $per_page );
|
$pagination = sprintf( ' LIMIT %d, %d', $offset, $per_page );
|
||||||
|
|
||||||
return $wpdb->get_results( $query . $pagination ); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
|
return $wpdb->get_results(
|
||||||
|
$wpdb->prepare(
|
||||||
|
"SELECT note_id, title, content FROM {$wpdb->prefix}woocommerce_admin_notes ORDER BY note_id DESC LIMIT %d, %d",
|
||||||
|
$offset,
|
||||||
|
$per_page
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -235,14 +234,8 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
*/
|
*/
|
||||||
public function get_notes_count() {
|
public function get_notes_count() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
// phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
|
||||||
// Build the query.
|
return $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}woocommerce_admin_notes" );
|
||||||
$query = "
|
|
||||||
SELECT COUNT(*)
|
|
||||||
FROM {$wpdb->prefix}woocommerce_admin_notes
|
|
||||||
";
|
|
||||||
|
|
||||||
return $wpdb->get_var( $query ); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -255,7 +248,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
return $wpdb->get_col(
|
return $wpdb->get_col(
|
||||||
$wpdb->prepare(
|
$wpdb->prepare(
|
||||||
"SELECT note_id FROM {$wpdb->prefix}woocommerce_admin_notes WHERE name = %s ORDER BY note_id ASC;",
|
"SELECT note_id FROM {$wpdb->prefix}woocommerce_admin_notes WHERE name = %s ORDER BY note_id ASC",
|
||||||
$name
|
$name
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue