Skip to content

Commit 00d3977

Browse files
author
10upbot on GitHub
committed
Committing built version of 2a958c1
1 parent a022cdf commit 00d3977

File tree

8 files changed

+323
-17
lines changed

8 files changed

+323
-17
lines changed

.github/workflows/build-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ jobs:
2424
- name: Deploy to GH Pages
2525
uses: maxheld83/ghpages@v0.2.1
2626
env:
27-
BUILD_DIR: 'docs/'
27+
BUILD_DIR: 'docs-built/'
2828
GH_PAT: ${{ secrets.GH_PAT }}

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file, per [the Ke
44

55
## [Unreleased] - TBD
66

7+
## [1.6.7] - 2021-11-09
8+
### Added
9+
- Added `Snippets` page to [Distributor's documentation site](https://10up.github.io/distributor/) with helpful filters and callbacks (props [@claytoncollie](https://github.com/claytoncollie) via [#817](https://github.com/10up/distributor/pull/817)).
10+
11+
### Fixed
12+
- Change how the `New` tab on the Pull Content screen is populated for External Connections (props [@dkotter](https://github.com/dkotter), [@dinhtungdu](https://github.com/dinhtungdu), [@cadic](https://github.com/cadic), [@helen](https://github.com/helen), [@jjgrainger](https://github.com/jjgrainger), [@jakemgold](https://github.com/jakemgold), [Lily Bonney](https://www.linkedin.com/in/lilybonney/), [Mollie Pugh](https://www.linkedin.com/in/molliepugh/), [Martina Haines](https://www.linkedin.com/in/martinahaines/) via [#811](https://github.com/10up/distributor/pull/811)).
13+
714
## [1.6.6] - 2021-09-28
815
### Added
916
- Add filters to control terms and meta distribution for internal connections: `dt_push_post_meta` and `dt_push_post_terms` (props [@dinhtungdu](https://github.com/dinhtungdu), [@dkotter](https://github.com/dkotter) via [#800](https://github.com/10up/distributor/pull/800)).
@@ -303,6 +310,8 @@ This adds a post type selector when viewing the Pull Content list for both exter
303310
- Initial closed release.
304311

305312
[Unreleased]: https://github.com/10up/distributor/compare/trunk...develop
313+
[1.6.7]: https://github.com/10up/distributor/compare/1.6.6...1.6.7
314+
[1.6.6]: https://github.com/10up/distributor/compare/1.6.5...1.6.6
306315
[1.6.5]: https://github.com/10up/distributor/compare/1.6.4...1.6.5
307316
[1.6.4]: https://github.com/10up/distributor/compare/1.6.3...1.6.4
308317
[1.6.3]: https://github.com/10up/distributor/compare/1.6.2...1.6.3

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
> Distributor is a WordPress plugin that makes it easy to distribute and reuse content across your websites — whether in a single multisite or across the web.
66
7-
[![Support Level](https://img.shields.io/badge/support-active-green.svg)](#support-level) [![Tests](https://github.com/10up/distributor/actions/workflows/test.yml/badge.svg)](https://github.com/10up/distributor/actions/workflows/test.yml) [![Linting](https://github.com/10up/distributor/actions/workflows/lint.yml/badge.svg)](https://github.com/10up/distributor/actions/workflows/lint.yml) [![Code scanning](https://github.com/10up/distributor/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/10up/distributor/actions/workflows/codeql-analysis.yml) [![Release Version](https://img.shields.io/github/release/10up/distributor.svg)](https://github.com/10up/distributor/releases/latest) ![WordPress tested up to version](https://img.shields.io/badge/WordPress-v5.7%20tested-success.svg) [![License](https://img.shields.io/github/license/10up/distributor.svg)](https://github.com/10up/distributor/blob/develop/LICENSE.md)
7+
[![Support Level](https://img.shields.io/badge/support-active-green.svg)](#support-level) [![Tests](https://github.com/10up/distributor/actions/workflows/test.yml/badge.svg)](https://github.com/10up/distributor/actions/workflows/test.yml) [![Linting](https://github.com/10up/distributor/actions/workflows/lint.yml/badge.svg)](https://github.com/10up/distributor/actions/workflows/lint.yml) [![Code scanning](https://github.com/10up/distributor/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/10up/distributor/actions/workflows/codeql-analysis.yml) [![Release Version](https://img.shields.io/github/release/10up/distributor.svg)](https://github.com/10up/distributor/releases/latest) ![WordPress tested up to version](https://img.shields.io/badge/WordPress-v5.8%20tested-success.svg) [![License](https://img.shields.io/github/license/10up/distributor.svg)](https://github.com/10up/distributor/blob/develop/LICENSE.md)
88

99
*You can learn more about Distributor's features at [DistributorPlugin.com](https://distributorplugin.com) and documentation at the [Distributor documentation site](https://10up.github.io/distributor/).*
1010

@@ -15,7 +15,7 @@ _Note:_ The latest stable version of the plugin is the _stable_ branch. [Downloa
1515
* [Requirements](#requirements)
1616
* [Installation](#installation)
1717
* [Registration](#registration)
18-
* [Setup External Connections](#setup-external-connections-using-application-passwords)
18+
* [Set Up External Connections](#set-up-external-connections-using-application-passwords)
1919
* [How to Distribute Content](#how-to-distribute-content)
2020
* [Pushing Content](#pushing-content)
2121
* [Pulling Content](#pulling-content)

distributor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin URI: https://github.com/10up/distributor
55
* Update URI: https://distributorplugin.com
66
* Description: Makes it easy to distribute and reuse content across your websites, whether inside of a multisite or across the web.
7-
* Version: 1.6.6
7+
* Version: 1.6.7
88
* Author: 10up Inc.
99
* Author URI: https://distributorplugin.com
1010
* License: GPLv2 or later
@@ -18,7 +18,7 @@
1818
exit; // Exit if accessed directly.
1919
}
2020

21-
define( 'DT_VERSION', '1.6.6' );
21+
define( 'DT_VERSION', '1.6.7' );
2222
define( 'DT_PLUGIN_FILE', preg_replace( '#^.*plugins/(.*)$#i', '$1', __FILE__ ) );
2323
define( 'DT_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
2424

includes/classes/ExternalConnections/WordPressExternalConnection.php

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,19 @@ public function remote_get( $args = array() ) {
165165
}
166166
}
167167

168+
// When running a query for the Pull screen with excluded items, make a POST request instead
169+
if ( empty( $id ) && isset( $args['post__not_in'] ) && isset( $args['dt_pull_list'] ) ) {
170+
$query_args['post_type'] = isset( $post_type ) ? $post_type : 'post';
171+
$query_args['per_page'] = isset( $posts_per_page ) ? $posts_per_page : 20;
172+
173+
$posts_response = $this->remote_post(
174+
untrailingslashit( $this->base_url ) . '/' . self::$namespace . '/distributor/list-pull-content',
175+
$query_args
176+
);
177+
178+
return $posts_response;
179+
}
180+
168181
static $types_urls;
169182
$types_urls = array();
170183

@@ -370,6 +383,110 @@ public function remote_get( $args = array() ) {
370383
}
371384
}
372385

386+
/**
387+
* Make a remote_post request.
388+
*
389+
* @param string $url Endpoint URL.
390+
* @param array $args Query arguments
391+
* @return array|\WP_Error
392+
*/
393+
public function remote_post( $url = '', $args = array() ) {
394+
if ( ! $url ) {
395+
return new \WP_Error( 'endpoint-error', esc_html__( 'Endpoint URL must be set', 'distributor' ) );
396+
}
397+
398+
$request = wp_remote_post(
399+
$url,
400+
$this->auth_handler->format_post_args(
401+
array(
402+
/**
403+
* Filter the timeout used when calling `remote_post`
404+
*
405+
* @since 1.6.7
406+
* @hook dt_remote_post_timeout
407+
*
408+
* @param int $timeout The timeout to use for the remote post. Default `45`.
409+
* @param array $args The request arguments
410+
*
411+
* @return int The timeout to use for the remote_post call.
412+
*/
413+
'timeout' => apply_filters( 'dt_remote_post_timeout', 45, $args ),
414+
/**
415+
* Filter the remote_post query arguments
416+
*
417+
* @since 1.6.7
418+
* @hook dt_remote_post_query_args
419+
*
420+
* @param {array} $args The request arguments.
421+
* @param {WordPressExternalConnection} $this The current connection object.
422+
*
423+
* @return {array} The query arguments.
424+
*/
425+
'body' => apply_filters( 'dt_remote_post_query_args', $args, $this ),
426+
)
427+
)
428+
);
429+
430+
if ( is_wp_error( $request ) ) {
431+
return $request;
432+
}
433+
434+
$response_code = wp_remote_retrieve_response_code( $request );
435+
436+
if ( 200 !== $response_code ) {
437+
if ( 404 === $response_code ) {
438+
return new \WP_Error( 'bad-endpoint', esc_html__( 'Could not connect to API endpoint.', 'distributor' ) );
439+
}
440+
441+
$posts_body = json_decode( wp_remote_retrieve_body( $request ), true );
442+
443+
$code = empty( $posts_body['code'] ) ? 'endpoint-error' : esc_html( $posts_body['code'] );
444+
$message = empty( $posts_body['message'] ) ? esc_html__( 'API endpoint error.', 'distributor' ) : esc_html( $posts_body['message'] );
445+
446+
return new \WP_Error( $code, $message );
447+
}
448+
449+
$posts_body = wp_remote_retrieve_body( $request );
450+
$response_headers = wp_remote_retrieve_headers( $request );
451+
452+
if ( empty( $posts_body ) ) {
453+
return new \WP_Error( 'no-response-body', esc_html__( 'Response body is empty', 'distributor' ) );
454+
}
455+
456+
$posts = json_decode( $posts_body, true );
457+
$formatted_posts = array();
458+
459+
foreach ( $posts as $post ) {
460+
$post['full_connection'] = ! empty( $response_headers['X-Distributor'] );
461+
462+
$formatted_posts[] = $this->to_wp_post( $post );
463+
}
464+
465+
$total_posts = ! empty( $response_headers['X-WP-Total'] ) ? $response_headers['X-WP-Total'] : count( $formatted_posts );
466+
467+
/**
468+
* Filter the items returned when using `WordPressExternalConnection::remote_post`
469+
*
470+
* @since 1.6.7
471+
* @hook dt_remote_post
472+
*
473+
* @param {array} $items The items returned from the POST request.
474+
* @param {array} $args The arguments used in the POST request.
475+
* @param {WordPressExternalConnection} $this The current connection object.
476+
*
477+
* @return {array} The items returned from a remote POST request.
478+
*/
479+
return apply_filters(
480+
'dt_remote_post',
481+
[
482+
'items' => $formatted_posts,
483+
'total_items' => $total_posts,
484+
],
485+
$args,
486+
$this
487+
);
488+
}
489+
373490
/**
374491
* Pull items. Pass array of posts, each post should look like:
375492
* [ 'remote_post_id' => POST ID TO GET, 'post_id' (optional) => POST ID TO MAP TO ]

includes/classes/PullListTable.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,7 @@ public function prepare_items() {
441441
'posts_per_page' => $per_page,
442442
'paged' => $current_page,
443443
'post_type' => $post_type,
444-
'orderby' => 'ID', // this is because of include/exclude truncation
445-
'order' => 'DESC', // default but specifying to be safe
444+
'dt_pull_list' => true, // custom argument used to only run code on this screen
446445
];
447446

448447
if ( ! empty( $_GET['s'] ) ) { // @codingStandardsIgnoreLine Nonce isn't required.
@@ -478,15 +477,11 @@ public function prepare_items() {
478477
}
479478

480479
if ( empty( $_GET['status'] ) || 'new' === $_GET['status'] ) { // @codingStandardsIgnoreLine Nonce not required.
481-
// Sort from highest ID (newest) to low so the slice only affects later pagination.
482-
rsort( $skipped, SORT_NUMERIC );
483-
rsort( $syndicated, SORT_NUMERIC );
480+
$post_ids = array_merge( $skipped, $syndicated );
484481

485-
// This is somewhat arbitrarily set to 200 and should probably be made filterable eventually.
486-
// IDs can get rather large and 400 easily exceeds typical header size limits.
487-
$post_ids = array_slice( array_merge( $skipped, $syndicated ), 0, 200, true );
488-
489-
$remote_get_args['post__not_in'] = $post_ids;
482+
if ( ! empty( $post_ids ) ) {
483+
$remote_get_args['post__not_in'] = $post_ids;
484+
}
490485

491486
$remote_get_args['meta_query'] = [
492487
[

0 commit comments

Comments
 (0)