get_col( "SELECT {$id_field} FROM {$table_name} WHERE {$where_sql} AND {$id_field} < {$previous_max_id} ORDER BY {$id_field} DESC LIMIT {$items_per_page}" ) ) { // Request posts in groups of N for efficiency $chunked_ids = array_chunk( $ids, self::ARRAY_CHUNK_SIZE ); // if we hit our row limit, process and return if ( $chunk_count + count( $chunked_ids ) >= $max_items_to_enqueue ) { $remaining_items_count = $max_items_to_enqueue - $chunk_count; $remaining_items = array_slice( $chunked_ids, 0, $remaining_items_count ); $listener->bulk_enqueue_full_sync_actions( $action_name, $remaining_items ); $last_chunk = end( $remaining_items ); return array( $remaining_items_count + $chunk_count, end( $last_chunk ) ); } $listener->bulk_enqueue_full_sync_actions( $action_name, $chunked_ids ); $chunk_count += count( $chunked_ids ); $page += 1; $previous_max_id = end( $ids ); } return array( $chunk_count, true ); } protected function get_metadata( $ids, $meta_type, $meta_key_whitelist ) { global $wpdb; $table = _get_meta_table( $meta_type ); $id = $meta_type . '_id'; if ( ! $table ) { return array(); } $private_meta_whitelist_sql = "'" . implode( "','", array_map( 'esc_sql', $meta_key_whitelist ) ) . "'"; return array_map( array( $this, 'unserialize_meta' ), $wpdb->get_results( "SELECT $id, meta_key, meta_value, meta_id FROM $table WHERE $id IN ( " . implode( ',', wp_parse_id_list( $ids ) ) . ' )'. " AND meta_key IN ( $private_meta_whitelist_sql ) " , OBJECT ) ); } public function init_listeners_for_meta_type( $meta_type, $callable ) { add_action( "added_{$meta_type}_meta", $callable, 10, 4 ); add_action( "updated_{$meta_type}_meta", $callable, 10, 4 ); add_action( "deleted_{$meta_type}_meta", $callable, 10, 4 ); } public function init_meta_whitelist_handler( $meta_type, $whitelist_handler ) { add_filter( "jetpack_sync_before_enqueue_added_{$meta_type}_meta", $whitelist_handler ); add_filter( "jetpack_sync_before_enqueue_updated_{$meta_type}_meta", $whitelist_handler ); add_filter( "jetpack_sync_before_enqueue_deleted_{$meta_type}_meta", $whitelist_handler ); } protected function get_term_relationships( $ids ) { global $wpdb; return $wpdb->get_results( "SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id IN ( " . implode( ',', wp_parse_id_list( $ids ) ) . ' )', OBJECT ); } public function unserialize_meta( $meta ) { $meta->meta_value = maybe_unserialize( $meta->meta_value ); return $meta; } public function get_objects_by_id( $object_type, $ids ) { if ( empty( $ids ) || empty( $object_type ) ) { return array(); } $objects = array(); foreach( (array) $ids as $id ) { $object = $this->get_object_by_id( $object_type, $id ); // Only add object if we have the object. if ( $object ) { $objects[ $id ] = $object; } } return $objects; } }