Skip to content

Commit

Permalink
improve the logic for view all
Browse files Browse the repository at this point in the history
  • Loading branch information
mehul0810 committed Jun 26, 2024
1 parent 5332b6c commit e474219
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions includes/classes/PullListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,16 +437,9 @@ public function prepare_items() {
/** Process bulk action */
$this->process_bulk_action();

$per_page = $this->get_items_per_page( 'pull_posts_per_page', get_option( 'posts_per_page' ) );

$per_page = $this->get_items_per_page( 'pull_posts_per_page', get_option( 'posts_per_page' ) );
$current_page = $this->get_pagenum();

// Support 'View all' filtering for all type of connections.
if ( empty( $connection_now->pull_post_type ) || 'all' === $connection_now->pull_post_type ) {
$post_type = wp_list_pluck( $connection_now->pull_post_types, 'slug' );
} else {
$post_type = $connection_now->pull_post_type;
}
$post_type = ! empty( $connection_now->pull_post_type ) ? $connection_now->pull_post_type : array( 'post', 'page' );

$remote_get_args = [
'posts_per_page' => $per_page,
Expand Down Expand Up @@ -527,22 +520,19 @@ public function prepare_items() {
$remote_get_args['post_type'] = [ $remote_get_args['post_type'] ];
}

$total_items = 0;
$response_data = [];
$total_items = 0;

foreach ( $remote_get_args['post_type'] as $type ) {
$remote_get_args['post_type'] = $type;
$remote_get = $connection_now->remote_get( $remote_get_args );
// Setup remote connection from the connection object.
$remote_get = $connection_now->remote_get( $remote_get_args );

if ( is_wp_error( $remote_get ) ) {
$this->pull_error[] = $remote_get->get_error_messages();
continue;
}

$total_items += $remote_get['total_items'];
$response_data = array_merge( $response_data, array_values( $remote_get['items'] ) );
// Check and throw error if there is one.
if ( is_wp_error( $remote_get ) ) {
$this->pull_error[] = $remote_get->get_error_messages();
}

$total_items = $remote_get['total_items'];
$response_data = array_merge( $response_data, array_values( $remote_get['items'] ) );

$this->set_pagination_args(
[
'total_items' => $total_items,
Expand Down

0 comments on commit e474219

Please sign in to comment.