PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | jetpack_vendor/automattic/jetpack-sync/src/sync-queue/class-queue-storage-options.php +25 -23 12.5.2 → 16.3-a.1 View file →
@@ -66,37 +66,39 @@
66 66 /**
67 67 * Fetch items from the queue.
68 68 *
69 69 * @param int|null $item_count How many items to fetch from the queue.
70 - * The parameter is null-able, if no limit on the amount of items.
70 + * Null for no limit.
71 + * @param string $order Sort direction for the items. Accepts 'ASC' or 'DESC'.
72 + * Any other value will be treated as 'ASC'.
71 73 *
72 - * @return array|object|\stdClass[]|null
74 + * @return array|object|null Array of result objects on success, or null on failure.
73 75 */
74 - public function fetch_items( $item_count ) {
76 + public function fetch_items( $item_count, $order = 'ASC' ) {
75 77 global $wpdb;
76 78
77 - // TODO make it more simple for the $item_count
79 + $order = 'DESC' === $order ? 'DESC' : 'ASC';
80 +
81 + $sql_order = "ORDER BY option_name {$order}";
82 +
83 + $sql = "SELECT option_name AS id, option_value AS value
84 + FROM $wpdb->options
85 + WHERE option_name LIKE %s
86 + {$sql_order}";
87 +
88 + $params = array( "jpsq_{$this->queue_id}-%" );
89 +
78 90 if ( $item_count ) {
79 - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.DirectQuery
80 - $items = $wpdb->get_results(
81 - $wpdb->prepare(
82 - "SELECT option_name AS id, option_value AS value FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_name ASC LIMIT %d",
83 - "jpsq_{$this->queue_id}-%",
84 - $item_count
85 - ),
86 - OBJECT
87 - );
88 - } else {
89 - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.DirectQuery
90 - $items = $wpdb->get_results(
91 - $wpdb->prepare(
92 - "SELECT option_name AS id, option_value AS value FROM $wpdb->options WHERE option_name LIKE %s ORDER BY option_name ASC",
93 - "jpsq_{$this->queue_id}-%"
94 - ),
95 - OBJECT
96 - );
91 + $sql .= ' LIMIT %d';
92 + $params[] = $item_count;
97 93 }
98 94
95 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
96 + $items = $wpdb->get_results(
97 + $wpdb->prepare( $sql, $params ), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
98 + OBJECT
99 + );
100 +
99 101 return $items;
100 102 }
101 103
102 104 /**
@@ -241,9 +243,9 @@
241 243 * Return $max_count items from the queue, including their value string length.
242 244 *
243 245 * @param int $max_count How many items to fetch from the queue.
244 246 *
245 - * @return \stdClass[]|null
247 + * @return object[]|null
246 248 */
247 249 public function get_items_ids_with_size( $max_count ) {
248 250 global $wpdb;
249 251