Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
682d32b
dt_distribute_post_status first pass
adamsilverstein Aug 19, 2019
b8c6988
distribute status to external connections
adamsilverstein Aug 19, 2019
c0a23bc
fix typo
adamsilverstein Aug 20, 2019
d59c765
changes for phpcs
adamsilverstein Aug 21, 2019
0297cdc
Merge branch 'develop' into feature/distribute_post_status
adamsilverstein Sep 27, 2019
a92e40d
status distribution tests part 1, add helper plugin
adamsilverstein Oct 15, 2019
51efd70
complete testPushStatusDistribution
adamsilverstein Oct 15, 2019
5e7c887
consolidate testing login into TestCase
adamsilverstein Oct 15, 2019
826107f
test cleanup
adamsilverstein Oct 15, 2019
dbaa76b
Complete network tests
adamsilverstein Oct 15, 2019
4731ed7
Add helper for creating an external connection
adamsilverstein Oct 15, 2019
a0f6ddb
Add tests for testExternalPushStatusDistribution
adamsilverstein Oct 15, 2019
a0ef118
Add test for testExternalPullStatusDistribution
adamsilverstein Oct 15, 2019
8716047
when a subscription update includes status, update the post status
adamsilverstein Oct 15, 2019
e0d36ca
cleanup
adamsilverstein Oct 15, 2019
0817a99
Subscriptions: respect dt_distribute_post_status filter
adamsilverstein Oct 15, 2019
795aaa4
external push: initial push can stay as is - status is controlled in …
adamsilverstein Oct 15, 2019
1a2fe66
cleanup
adamsilverstein Oct 15, 2019
85446c2
Add @hook notation
adamsilverstein Oct 15, 2019
e1ffa7f
fixes from phpcbf
adamsilverstein Oct 15, 2019
9c95b15
Don’t run testDistributedCount in block editor
adamsilverstein Oct 16, 2019
32a9cfa
refactor(internal-connections): reduce indentation level
dinhtungdu Feb 10, 2020
4dabefd
refactor: wrap `dt_distribute_post_status` filter in a helper function
dinhtungdu Feb 10, 2020
c6a89c6
fix: merge conflict
dinhtungdu Feb 25, 2020
589ef5c
Merge branch 'develop' into feature/distribute_post_status
dinhtungdu Feb 25, 2020
f0d9398
test: fix pull external test case
dinhtungdu Feb 25, 2020
b44c41b
test: change expected author to `admin`
dinhtungdu Feb 25, 2020
3a564fd
fix: pull test cases
dinhtungdu Feb 27, 2020
68c74c7
test: fix pull external test case
dinhtungdu Feb 27, 2020
4c6cb39
test: set status of pulled post throught external connection to publish
dinhtungdu Feb 28, 2020
43b8867
test: active test plugin for entire network
dinhtungdu Feb 28, 2020
8c11dfe
test: fix editorHasBlocks check
dinhtungdu Feb 28, 2020
3dbb3b5
test: fix editorHasBlocks calls
dinhtungdu Feb 29, 2020
3cbe0b5
Merge branch 'develop' into feature/distribute_post_status
dinhtungdu Mar 16, 2020
3910c73
Merge branch 'develop' into feature/distribute_post_status
dinhtungdu Sep 26, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public static function credentials_form( $args = array() ) {
// Calculate the redirect_uri to use for authorization (the current admin url & query vars).
$redirect_uri = esc_url(
( is_ssl() ? 'https://' : 'http://' ) .
sanitize_text_field( isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' ) . // Input var okay. WPCS: CSRF ok.
sanitize_text_field( isset( $_SERVER['SCRIPT_NAME'] ) ? $_SERVER['SCRIPT_NAME'] : '' ) . // WPCS: input var ok.
sanitize_text_field( isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '' ) .
sanitize_text_field( isset( $_SERVER['SCRIPT_NAME'] ) ? $_SERVER['SCRIPT_NAME'] : '' ) .
'?' .
sanitize_text_field( isset( $_SERVER['QUERY_STRING'] ) ? $_SERVER['QUERY_STRING'] : '' ) // WPCS: input var ok.
sanitize_text_field( isset( $_SERVER['QUERY_STRING'] ) ? $_SERVER['QUERY_STRING'] : '' )
);
$args[ self::API_REDIRECT_URI ] = $redirect_uri;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ public function push( $post_id, $args = array() ) {

$signature = \Distributor\Subscriptions\generate_signature();

$distribute_post_status = apply_filters( 'dt_distribute_post_status', false );
$distribute_status = $distribute_post_status ? $post->post_status : 'publish';

/**
* Now let's push
*/
Expand All @@ -556,7 +559,7 @@ public function push( $post_id, $args = array() ) {
'slug' => $post->post_name,
'content' => Utils\get_processed_content( $post->post_content ),
'type' => $post->post_type,
'status' => ( ! empty( $args['post_status'] ) ) ? $args['post_status'] : 'publish',
'status' => ( ! empty( $args['post_status'] ) ) ? $args['post_status'] : $distribute_status,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@adamsilverstein If I mark $distribute_post_status as true, the source post status will only be distributed if $args['post_status'] is empty. $args['post_status'] comes from the connection map for the origin post, how is that populated or changed? In any case, going off the filter name I would expect $distribute_post_status to always take precedence, but it's very possible I'm woefully missing context here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

In this case of push, the post_status comes from whether you have checked the 'distribute as draft' checkbox, if you have that setting overrides the filter. I do need to test subscriptions and pull, i'm not sure that works correctly. See

if ( ! empty( $_POST['postStatus'] ) ) {
$push_args['post_status'] = $_POST['postStatus'];
}

'excerpt' => $post->post_excerpt,
'distributor_original_source_id' => $this->id,
'distributor_original_site_name' => get_bloginfo( 'name' ),
Expand Down
20 changes: 15 additions & 5 deletions includes/classes/InternalConnections/NetworkSiteConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,21 @@ public function push( $post_id, $args = array() ) {
$original_post_url = get_permalink( $post_id );
$using_gutenberg = \Distributor\Utils\is_using_gutenberg( $post );

/**
* Filter whether Distributor should update post statuses when the origin post status changes.
*
* False by default, return true to have post statuses distributed.
*/
$distribute_post_status = apply_filters( 'dt_distribute_post_status', false );

$new_post_args = array(
'post_title' => get_the_title( $post_id ),
'post_name' => $post->post_name,
'post_content' => Utils\get_processed_content( $post->post_content ),
'post_excerpt' => $post->post_excerpt,
'post_type' => $post->post_type,
'post_author' => get_current_user_id(),
'post_status' => 'publish',
'post_status' => $distribute_post_status ? $post->post_status : 'publish',
);

$media = \Distributor\Utils\prepare_media( $post_id );
Expand All @@ -100,10 +107,13 @@ public function push( $post_id, $args = array() ) {
if ( empty( $args['post_status'] ) ) {
if ( isset( $new_post_args['ID'] ) ) {

// Avoid updating the status of previously distributed posts.
$existing_status = get_post_status( (int) $new_post_args['ID'] );
if ( $existing_status ) {
$new_post_args['post_status'] = $existing_status;
if ( ! $distribute_post_status ) {
Comment thread
dinhtungdu marked this conversation as resolved.
Outdated

// Avoid updating the status of previously distributed posts.
$existing_status = get_post_status( (int) $new_post_args['ID'] );
if ( $existing_status ) {
$new_post_args['post_status'] = $existing_status;
}
}
}
} else {
Expand Down