From 4c98447f1cc6eca3f36077708192721fbc3f4043 Mon Sep 17 00:00:00 2001 From: Chigozie Orunta Date: Fri, 13 May 2022 19:27:08 +0100 Subject: [PATCH 01/16] Make provision for post and page post types within args --- includes/rest-api.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/rest-api.php b/includes/rest-api.php index 00c60278e..31bb5ec73 100644 --- a/includes/rest-api.php +++ b/includes/rest-api.php @@ -411,10 +411,13 @@ function check_post_types_permissions() { * @return \WP_REST_Response|\WP_Error */ function get_pull_content( $request ) { + $post_type = isset( $request['post_type'] ) ? $request['post_type'] : 'all'; + $post_type = 'all' === $post_type ? array( 'post', 'page' ) : $post_type; + $args = [ 'posts_per_page' => isset( $request['posts_per_page'] ) ? $request['posts_per_page'] : 20, 'paged' => isset( $request['page'] ) ? $request['page'] : 1, - 'post_type' => isset( $request['post_type'] ) ? $request['post_type'] : 'post', + 'post_type' => $post_type, 'post_status' => isset( $request['post_status'] ) ? $request['post_status'] : array( 'any' ), ]; From 1edf95e3b4adb84847e0ba099382c3be4200e772 Mon Sep 17 00:00:00 2001 From: Chigozie Orunta Date: Sat, 14 May 2022 23:45:25 +0100 Subject: [PATCH 02/16] Make post and page types available --- includes/rest-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/rest-api.php b/includes/rest-api.php index 31bb5ec73..6a43e29fe 100644 --- a/includes/rest-api.php +++ b/includes/rest-api.php @@ -417,7 +417,7 @@ function get_pull_content( $request ) { $args = [ 'posts_per_page' => isset( $request['posts_per_page'] ) ? $request['posts_per_page'] : 20, 'paged' => isset( $request['page'] ) ? $request['page'] : 1, - 'post_type' => $post_type, + 'post_type' => array( 'post', 'page' ), 'post_status' => isset( $request['post_status'] ) ? $request['post_status'] : array( 'any' ), ]; From 03a25b0613b89a47c486493c77da8b25e5edfcf3 Mon Sep 17 00:00:00 2001 From: Chigozie Orunta Date: Sat, 14 May 2022 23:50:27 +0100 Subject: [PATCH 03/16] Show View All for all connection types --- includes/classes/PullListTable.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/includes/classes/PullListTable.php b/includes/classes/PullListTable.php index 9cd2026a2..3b46d4eee 100644 --- a/includes/classes/PullListTable.php +++ b/includes/classes/PullListTable.php @@ -612,13 +612,11 @@ public function extra_tablenav( $which ) {
pull_post_type = ''; $connection_now->pull_post_types = \Distributor\Utils\available_pull_post_types( $connection_now, $connection_type ); - // Ensure we have at least one post type to pull. - $connection_now->pull_post_type = ''; - if ( ! empty( $connection_now->pull_post_types ) ) { - $connection_now->pull_post_type = ( 'internal' === $connection_type ) ? 'all' : $connection_now->pull_post_types[0]['slug']; - } - // Set the post type we want to pull (if any) // This is either from a query param, "post" post type, or the first in the list foreach ( $connection_now->pull_post_types as $post_type ) { - if ( isset( $_GET['pull_post_type'] ) ) { // @codingStandardsIgnoreLine No nonce needed here. - if ( $_GET['pull_post_type'] === $post_type['slug'] ) { // @codingStandardsIgnoreLine Comparing values, no nonce needed. - $connection_now->pull_post_type = $post_type['slug']; + if ( ! empty( $_GET['pull_post_type'] ) ) { // @codingStandardsIgnoreLine No nonce needed here. + if ( 'all' === $_GET['pull_post_type'] ) { + $connection_now->pull_post_type = wp_list_pluck( $connection_now->pull_post_types, 'slug' ); break; - } - } else { - if ( 'post' === $post_type['slug'] && 'external' === $connection_type ) { + } elseif ( $_GET['pull_post_type'] === $post_type['slug'] ) { // @codingStandardsIgnoreLine Comparing values, no nonce needed. $connection_now->pull_post_type = $post_type['slug']; break; } + } else { + $connection_now->pull_post_type = ! empty( $post_type['slug'] ) ? $post_type['slug'] : 'post'; + break; } } ?> From 96632aaed5927732475975e81a063af5dd057831 Mon Sep 17 00:00:00 2001 From: Mehul Gohil Date: Sat, 14 Jan 2023 11:09:31 +0530 Subject: [PATCH 05/16] improve the way data is pulled --- includes/classes/PullListTable.php | 49 ++++++++++++++++++------------ 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/includes/classes/PullListTable.php b/includes/classes/PullListTable.php index 4f86798e9..ecbd25369 100644 --- a/includes/classes/PullListTable.php +++ b/includes/classes/PullListTable.php @@ -441,15 +441,11 @@ public function prepare_items() { $current_page = $this->get_pagenum(); - // Support 'View all' filtering for internal connections. - if ( is_a( $connection_now, '\Distributor\InternalConnections\NetworkSiteConnection' ) ) { - 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; - } + // 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 ? $connection_now->pull_post_type : 'post'; + $post_type = $connection_now->pull_post_type; } $remote_get_args = [ @@ -527,17 +523,29 @@ public function prepare_items() { $remote_get_args['paged'] = 1; } - $remote_get = $connection_now->remote_get( $remote_get_args ); + if ( ! is_array( $remote_get_args['post_type'] ) ) { + $remote_get_args['post_type'] = [ $remote_get_args['post_type'] ]; + } - if ( is_wp_error( $remote_get ) ) { - $this->pull_error = $remote_get->get_error_messages(); + $total_items = ''; + $response_data = []; - return; - } + foreach( $remote_get_args['post_type'] as $type ) { + $remote_get_args['post_type'] = $type; + $remote_get = $connection_now->remote_get( $remote_get_args ); - // Get total items retrieved from the remote request if not already set. - if ( false === $total_items ) { - $total_items = $remote_get['total_items']; + if ( is_wp_error( $remote_get ) ) { + $this->pull_error = $remote_get->get_error_messages(); + + continue; + } + + // Get total items retrieved from the remote request if not already set. + // if ( false === $response_data['total_items'] ) { + $total_items += $remote_get['total_items']; + $response_data = array_merge( $response_data, array_values( $remote_get['items'] ) ); + + // } } $this->set_pagination_args( @@ -547,7 +555,7 @@ public function prepare_items() { ] ); - foreach ( $remote_get['items'] as $item ) { + foreach ( $response_data as $item ) { $this->items[] = $item; } } @@ -611,8 +619,9 @@ public function extra_tablenav( $which ) { } else { $connection_type = 'external'; } - - if ( $connection_now && $connection_now->pull_post_types && $connection_now->pull_post_type ) : + // echo "
"; print_r($connection_now);echo "
"; +// var_dump($connection_now && $connection_now->pull_post_types && $connection_now->pull_post_type); + if ( $connection_now && $connection_now->pull_post_types ) : ?>
@@ -622,7 +631,7 @@ public function extra_tablenav( $which ) { pull_post_types as $post_type ) : ?> - From 169781534c582e625be73da6085a5ed6a601a077 Mon Sep 17 00:00:00 2001 From: Mehul Gohil Date: Sat, 14 Jan 2023 11:15:59 +0530 Subject: [PATCH 06/16] improve some phpcs errors --- includes/classes/PullListTable.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/includes/classes/PullListTable.php b/includes/classes/PullListTable.php index ecbd25369..f0ea08b29 100644 --- a/includes/classes/PullListTable.php +++ b/includes/classes/PullListTable.php @@ -530,22 +530,17 @@ public function prepare_items() { $total_items = ''; $response_data = []; - foreach( $remote_get_args['post_type'] as $type ) { + foreach ( $remote_get_args['post_type'] as $type ) { $remote_get_args['post_type'] = $type; - $remote_get = $connection_now->remote_get( $remote_get_args ); + $remote_get = $connection_now->remote_get( $remote_get_args ); if ( is_wp_error( $remote_get ) ) { $this->pull_error = $remote_get->get_error_messages(); - continue; } - // Get total items retrieved from the remote request if not already set. - // if ( false === $response_data['total_items'] ) { - $total_items += $remote_get['total_items']; - $response_data = array_merge( $response_data, array_values( $remote_get['items'] ) ); - - // } + $total_items += $remote_get['total_items']; + $response_data = array_merge( $response_data, array_values( $remote_get['items'] ) ); } $this->set_pagination_args( @@ -619,8 +614,7 @@ public function extra_tablenav( $which ) { } else { $connection_type = 'external'; } - // echo "
"; print_r($connection_now);echo "
"; -// var_dump($connection_now && $connection_now->pull_post_types && $connection_now->pull_post_type); + if ( $connection_now && $connection_now->pull_post_types ) : ?> From d39eb312df602cfbb374f00863ff32adddde15d3 Mon Sep 17 00:00:00 2001 From: Mehul Gohil Date: Sat, 14 Jan 2023 15:05:22 +0530 Subject: [PATCH 07/16] resolve phpcs misalignment issue --- includes/classes/PullListTable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/classes/PullListTable.php b/includes/classes/PullListTable.php index f0ea08b29..8a95cf49c 100644 --- a/includes/classes/PullListTable.php +++ b/includes/classes/PullListTable.php @@ -539,7 +539,7 @@ public function prepare_items() { continue; } - $total_items += $remote_get['total_items']; + $total_items += $remote_get['total_items']; $response_data = array_merge( $response_data, array_values( $remote_get['items'] ) ); } From 58471b8aa2f22bf922eead522af7acbef5a273a4 Mon Sep 17 00:00:00 2001 From: Mehul Gohil Date: Wed, 26 Jun 2024 22:42:12 +0530 Subject: [PATCH 08/16] use post type variable --- includes/rest-api.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/rest-api.php b/includes/rest-api.php index d9cdab03c..a0e814c33 100644 --- a/includes/rest-api.php +++ b/includes/rest-api.php @@ -623,10 +623,11 @@ function check_post_types_permissions() { * @return \WP_REST_Response|\WP_Error */ function get_pull_content_list( $request ) { - $args = [ + $post_type = ! empty( $request['post_type'] ) ? $request['post_type'] : array( 'post', 'page' ); + $args = [ 'posts_per_page' => isset( $request['posts_per_page'] ) ? $request['posts_per_page'] : 20, 'paged' => isset( $request['page'] ) ? $request['page'] : 1, - 'post_type' => array( 'post', 'page' ), + 'post_type' => $post_type, 'post_status' => isset( $request['post_status'] ) ? $request['post_status'] : array( 'any' ), 'order' => ! empty( $request['order'] ) ? strtoupper( $request['order'] ) : 'DESC', ]; From 342cb0c8f506d72f952e78c015a545e841b01157 Mon Sep 17 00:00:00 2001 From: Mehul Gohil Date: Thu, 27 Jun 2024 00:26:34 +0530 Subject: [PATCH 09/16] fix the operand type error --- includes/classes/PullListTable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/classes/PullListTable.php b/includes/classes/PullListTable.php index 8a95cf49c..606710887 100644 --- a/includes/classes/PullListTable.php +++ b/includes/classes/PullListTable.php @@ -527,7 +527,7 @@ public function prepare_items() { $remote_get_args['post_type'] = [ $remote_get_args['post_type'] ]; } - $total_items = ''; + $total_items = 0; $response_data = []; foreach ( $remote_get_args['post_type'] as $type ) { From 5332b6c0da83ebcf9be771364030939e0685879e Mon Sep 17 00:00:00 2001 From: Mehul Gohil Date: Thu, 27 Jun 2024 00:34:34 +0530 Subject: [PATCH 10/16] add support for multiple pull errors --- includes/classes/PullListTable.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/classes/PullListTable.php b/includes/classes/PullListTable.php index 606710887..e14fc872a 100644 --- a/includes/classes/PullListTable.php +++ b/includes/classes/PullListTable.php @@ -29,9 +29,9 @@ class PullListTable extends \WP_List_Table { /** * Save error to determine if we can show the pull table * - * @var bool + * @var array */ - public $pull_error; + public $pull_error = []; /** * Initialize pull table @@ -535,7 +535,7 @@ public function prepare_items() { $remote_get = $connection_now->remote_get( $remote_get_args ); if ( is_wp_error( $remote_get ) ) { - $this->pull_error = $remote_get->get_error_messages(); + $this->pull_error[] = $remote_get->get_error_messages(); continue; } From e474219c8cc5cdc1e226d92bd03d84f6886cccdd Mon Sep 17 00:00:00 2001 From: Mehul Gohil Date: Thu, 27 Jun 2024 00:50:01 +0530 Subject: [PATCH 11/16] improve the logic for view all --- includes/classes/PullListTable.php | 32 ++++++++++-------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/includes/classes/PullListTable.php b/includes/classes/PullListTable.php index e14fc872a..34d515989 100644 --- a/includes/classes/PullListTable.php +++ b/includes/classes/PullListTable.php @@ -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, @@ -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, From dbc5104b82b68e391253996a01206d07c973e8f8 Mon Sep 17 00:00:00 2001 From: Mehul Gohil Date: Fri, 28 Jun 2024 15:20:08 +0530 Subject: [PATCH 12/16] resolve fatal error --- includes/classes/PullListTable.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/classes/PullListTable.php b/includes/classes/PullListTable.php index 34d515989..d1b17c03b 100644 --- a/includes/classes/PullListTable.php +++ b/includes/classes/PullListTable.php @@ -520,7 +520,8 @@ public function prepare_items() { $remote_get_args['post_type'] = [ $remote_get_args['post_type'] ]; } - $total_items = 0; + $total_items = 0; + $response_data = array(); // Setup remote connection from the connection object. $remote_get = $connection_now->remote_get( $remote_get_args ); From 5a1177927f53281ef6cae5b7cf6f11743f68d920 Mon Sep 17 00:00:00 2001 From: Mehul Gohil Date: Fri, 28 Jun 2024 15:26:27 +0530 Subject: [PATCH 13/16] reverted pull error change --- includes/classes/PullListTable.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/classes/PullListTable.php b/includes/classes/PullListTable.php index d1b17c03b..2b97c2ae2 100644 --- a/includes/classes/PullListTable.php +++ b/includes/classes/PullListTable.php @@ -29,9 +29,9 @@ class PullListTable extends \WP_List_Table { /** * Save error to determine if we can show the pull table * - * @var array + * @var bool */ - public $pull_error = []; + public $pull_error; /** * Initialize pull table @@ -528,7 +528,7 @@ public function prepare_items() { // Check and throw error if there is one. if ( is_wp_error( $remote_get ) ) { - $this->pull_error[] = $remote_get->get_error_messages(); + $this->pull_error = $remote_get->get_error_messages(); } $total_items = $remote_get['total_items']; From 75a23d78269a6590fbe305f8f5c95ad07d928ac4 Mon Sep 17 00:00:00 2001 From: Mehul Gohil Date: Fri, 28 Jun 2024 15:28:06 +0530 Subject: [PATCH 14/16] revert change to the removed code --- includes/classes/PullListTable.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/includes/classes/PullListTable.php b/includes/classes/PullListTable.php index 2b97c2ae2..084762335 100644 --- a/includes/classes/PullListTable.php +++ b/includes/classes/PullListTable.php @@ -439,7 +439,17 @@ public function prepare_items() { $per_page = $this->get_items_per_page( 'pull_posts_per_page', get_option( 'posts_per_page' ) ); $current_page = $this->get_pagenum(); - $post_type = ! empty( $connection_now->pull_post_type ) ? $connection_now->pull_post_type : array( 'post', 'page' ); + + // Support 'View all' filtering for internal connections. + if ( is_a( $connection_now, '\Distributor\InternalConnections\NetworkSiteConnection' ) ) { + 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; + } + } else { + $post_type = ! empty( $connection_now->pull_post_type ) ? $connection_now->pull_post_type : array( 'post', 'page' ); + } $remote_get_args = [ 'posts_per_page' => $per_page, From 7cdc43be12326f70b70766697eb975f7270c71f7 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Thu, 4 Jul 2024 10:56:38 +1000 Subject: [PATCH 15/16] Resolve array to string conversion notices. --- includes/classes/PullListTable.php | 10 +++------- includes/pull-ui.php | 14 ++++++++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/includes/classes/PullListTable.php b/includes/classes/PullListTable.php index 084762335..759afe833 100644 --- a/includes/classes/PullListTable.php +++ b/includes/classes/PullListTable.php @@ -441,14 +441,10 @@ public function prepare_items() { $current_page = $this->get_pagenum(); // Support 'View all' filtering for internal connections. - if ( is_a( $connection_now, '\Distributor\InternalConnections\NetworkSiteConnection' ) ) { - 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; - } + 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 = ! empty( $connection_now->pull_post_type ) ? $connection_now->pull_post_type : array( 'post', 'page' ); + $post_type = $connection_now->pull_post_type; } $remote_get_args = [ diff --git a/includes/pull-ui.php b/includes/pull-ui.php index 7166777d9..5261b3a34 100644 --- a/includes/pull-ui.php +++ b/includes/pull-ui.php @@ -475,19 +475,25 @@ function dashboard() { $connection_now->pull_post_type = ''; $connection_now->pull_post_types = \Distributor\Utils\available_pull_post_types( $connection_now, $connection_type ); + // Ensure we have at least one post type to pull. + $connection_now->pull_post_type = ''; + if ( ! empty( $connection_now->pull_post_types ) ) { + $connection_now->pull_post_type = 'all'; + } + // Set the post type we want to pull (if any) // This is either from a query param, "post" post type, or the first in the list foreach ( $connection_now->pull_post_types as $post_type ) { - if ( ! empty( $_GET['pull_post_type'] ) ) { // @codingStandardsIgnoreLine No nonce needed here. + if ( ! empty( $_GET['pull_post_type'] ) ) { if ( 'all' === $_GET['pull_post_type'] ) { - $connection_now->pull_post_type = wp_list_pluck( $connection_now->pull_post_types, 'slug' ); + $connection_now->pull_post_type = 'all'; break; - } elseif ( $_GET['pull_post_type'] === $post_type['slug'] ) { // @codingStandardsIgnoreLine Comparing values, no nonce needed. + } elseif ( $_GET['pull_post_type'] === $post_type['slug'] ) { $connection_now->pull_post_type = $post_type['slug']; break; } } else { - $connection_now->pull_post_type = ! empty( $post_type['slug'] ) ? $post_type['slug'] : 'post'; + $connection_now->pull_post_type = ! empty( $post_type['slug'] ) ? $post_type['slug'] : 'all'; break; } } From 253cf825bb18ba6a5a7d22c3cec4034b9a09bfe3 Mon Sep 17 00:00:00 2001 From: Mehul Gohil Date: Sat, 6 Jul 2024 16:11:38 +0530 Subject: [PATCH 16/16] revert the default post type to just post --- includes/rest-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/rest-api.php b/includes/rest-api.php index a0e814c33..5cc2b656e 100644 --- a/includes/rest-api.php +++ b/includes/rest-api.php @@ -623,7 +623,7 @@ function check_post_types_permissions() { * @return \WP_REST_Response|\WP_Error */ function get_pull_content_list( $request ) { - $post_type = ! empty( $request['post_type'] ) ? $request['post_type'] : array( 'post', 'page' ); + $post_type = ! empty( $request['post_type'] ) ? $request['post_type'] : array( 'post' ); $args = [ 'posts_per_page' => isset( $request['posts_per_page'] ) ? $request['posts_per_page'] : 20, 'paged' => isset( $request['page'] ) ? $request['page'] : 1,