Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to view all post types when Pulling from an External Connection #1002

Merged
merged 22 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4c98447
Make provision for post and page post types within args
chigozieorunta May 13, 2022
1edf95e
Make post and page types available
chigozieorunta May 14, 2022
03a25b0
Show View All for all connection types
chigozieorunta May 14, 2022
e1941b9
Merge branch 'develop' of https://github.com/10up/distributor into fe…
mehul0810 Jan 12, 2023
9fc9710
improve the way we set pull post type
mehul0810 Jan 14, 2023
96632aa
improve the way data is pulled
mehul0810 Jan 14, 2023
1697815
improve some phpcs errors
mehul0810 Jan 14, 2023
d39eb31
resolve phpcs misalignment issue
mehul0810 Jan 14, 2023
59915fc
Merge branch 'develop' into feature/861
ravinderk Mar 24, 2023
bdc9b85
Merge branch 'develop' into feature/861
mehul0810 Jun 26, 2024
58471b8
use post type variable
mehul0810 Jun 26, 2024
342cb0c
fix the operand type error
mehul0810 Jun 26, 2024
5332b6c
add support for multiple pull errors
mehul0810 Jun 26, 2024
e474219
improve the logic for view all
mehul0810 Jun 26, 2024
dbc5104
resolve fatal error
mehul0810 Jun 28, 2024
5a11779
reverted pull error change
mehul0810 Jun 28, 2024
75a23d7
revert change to the removed code
mehul0810 Jun 28, 2024
7cdc43b
Resolve array to string conversion notices.
peterwilsoncc Jul 4, 2024
ce538c4
Merge branch 'develop' into feature/861
Sidsector9 Jul 5, 2024
253cf82
revert the default post type to just post
mehul0810 Jul 6, 2024
ff8b199
Merge branch 'develop' into feature/861
Sidsector9 Jul 8, 2024
2d90008
Merge branch 'develop' into feature/861
peterwilsoncc Jul 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions includes/classes/PullListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,7 @@ 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 internal connections.
Expand All @@ -449,7 +448,7 @@ public function prepare_items() {
$post_type = $connection_now->pull_post_type;
}
} else {
$post_type = $connection_now->pull_post_type ? $connection_now->pull_post_type : 'post';
$post_type = ! empty( $connection_now->pull_post_type ) ? $connection_now->pull_post_type : array( 'post', 'page' );
}

$remote_get_args = [
Expand Down Expand Up @@ -527,18 +526,23 @@ public function prepare_items() {
$remote_get_args['paged'] = 1;
}

if ( ! is_array( $remote_get_args['post_type'] ) ) {
$remote_get_args['post_type'] = [ $remote_get_args['post_type'] ];
}

$total_items = 0;
$response_data = array();

// Setup remote connection from the connection object.
$remote_get = $connection_now->remote_get( $remote_get_args );

// Check and throw error if there is one.
if ( is_wp_error( $remote_get ) ) {
$this->pull_error = $remote_get->get_error_messages();

return;
}

// Get total items retrieved from the remote request if not already set.
if ( false === $total_items ) {
$total_items = $remote_get['total_items'];
}
$total_items = $remote_get['total_items'];
$response_data = array_merge( $response_data, array_values( $remote_get['items'] ) );

$this->set_pagination_args(
[
Expand All @@ -547,7 +551,7 @@ public function prepare_items() {
]
);

foreach ( $remote_get['items'] as $item ) {
foreach ( $response_data as $item ) {
$this->items[] = $item;
}
}
Expand Down Expand Up @@ -612,17 +616,15 @@ public function extra_tablenav( $which ) {
$connection_type = 'external';
}

if ( $connection_now && $connection_now->pull_post_types && $connection_now->pull_post_type ) :
if ( $connection_now && $connection_now->pull_post_types ) :
?>

<div class="alignleft actions dt-pull-post-type">
<label for="pull_post_type" class="screen-reader-text">Content to Pull</label>
<select id="pull_post_type" name="pull_post_type">
<?php if ( 'internal' === $connection_type ) : ?>
<option <?php selected( $connection_now->pull_post_type, 'all' ); ?> value="all">
<?php esc_html_e( 'View all', 'distributor' ); ?>
</option>
<?php endif; ?>
<option <?php selected( $connection_now->pull_post_type, 'all' ); ?> value="all">
<?php esc_html_e( 'View all', 'distributor' ); ?>
</option>
<?php foreach ( $connection_now->pull_post_types as $post_type ) : ?>
<option <?php selected( $connection_now->pull_post_type, $post_type['slug'] ); ?> value="<?php echo esc_attr( $post_type['slug'] ); ?>">
<?php echo esc_html( $post_type['name'] ); ?>
Expand Down
20 changes: 8 additions & 12 deletions includes/pull-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,27 +472,23 @@ function dashboard() {
</select>

<?php
$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 = ( '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;
}
}
?>
Expand Down
5 changes: 3 additions & 2 deletions includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default is set to post in get_pull_content_list_args() so it's unlikely this will ever be set to [post, page].

I included it back when I was rewriting this as a safety check just in case someone messes with the URL.

Was the intent with this change to default to the View All view? For internal connections Distributor offers a View All view but defaults to posts only, so I think it's best to match that for the time being.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterwilsoncc Replaced it to show only the post by default.

The intent with this change was to get the list of post type that needs to be listed or else default to post. But, we are not defaulting the post type filter to View All. It is still Post

$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' ),
'order' => ! empty( $request['order'] ) ? strtoupper( $request['order'] ) : 'DESC',
];
Expand Down
Loading