From 0798d34e58b24afece80dbc09eecc443a83504b8 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 7 Mar 2023 17:41:11 +0530 Subject: [PATCH 01/12] tweak: add new filter and deprecated existing --- .../WordPressExternalConnection.php | 19 ++++++++++++++++++- .../NetworkSiteConnection.php | 17 ++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/includes/classes/ExternalConnections/WordPressExternalConnection.php b/includes/classes/ExternalConnections/WordPressExternalConnection.php index e5a1dbf93..ab09da013 100644 --- a/includes/classes/ExternalConnections/WordPressExternalConnection.php +++ b/includes/classes/ExternalConnections/WordPressExternalConnection.php @@ -724,7 +724,24 @@ public function push( $post_id, $args = array() ) { ); // Action documented in includes/classes/InternalConnections/NetworkSiteConnection.php. - do_action( 'dt_push_post', $response, $post_body, $type_url, $post_id, $args, $this ); + do_action_deprecated( + 'dt_push_post', + array( $response, $post_body, $type_url, $post_id, $args, $this ), + '2.0.0', + 'dt_push_external_post' + ); + + /** + * Fires the action after a post is pushed via Distributor before `restore_current_blog()`. + * + * @since 2.0.0 + * + * @param {WP_Post} $response The newly created post. + * @param {WP_Post} $post_id The original post. + * @param {array} $args The arguments passed into wp_insert_post. + * @param {Connection} $this The Distributor connection being pushed to. + */ + do_action( 'dt_push_external_post', $response, $post, $args, $this ); if ( is_wp_error( $response ) ) { return $response; diff --git a/includes/classes/InternalConnections/NetworkSiteConnection.php b/includes/classes/InternalConnections/NetworkSiteConnection.php index 354633888..fa97f3b24 100644 --- a/includes/classes/InternalConnections/NetworkSiteConnection.php +++ b/includes/classes/InternalConnections/NetworkSiteConnection.php @@ -200,7 +200,22 @@ public function push( $post_id, $args = array() ) { * @param {array} $args The arguments passed into wp_insert_post. * @param {Connection} $this The Distributor connection being pushed to. */ - do_action( 'dt_push_post', $new_post_id, $post_id, $args, $this ); + do_action_deprecated( + 'dt_push_post', + array( $new_post_id, $post_id, $args, $this ), + '2.0.0', + '' + ); + + /** + * Fires the action after a post is pushed via Distributor before `restore_current_blog()`. + * + * @since 2.0.0 + * + * @param {int} $new_post_id The newly created post. + * @param {int} $post_id The original post. + */ + do_action( 'dt_push_network_post', $new_post_id, $post_id ); restore_current_blog(); From e401d98cb7bfc184212d7d5b9ff2050fa8314122 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 7 Mar 2023 17:50:43 +0530 Subject: [PATCH 02/12] chore: resove merge conflict --- .../NetworkSiteConnection.php | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/includes/classes/InternalConnections/NetworkSiteConnection.php b/includes/classes/InternalConnections/NetworkSiteConnection.php index e86a03faa..862bf5fec 100644 --- a/includes/classes/InternalConnections/NetworkSiteConnection.php +++ b/includes/classes/InternalConnections/NetworkSiteConnection.php @@ -162,6 +162,20 @@ public function push( $post, $args = array() ) { Utils\set_meta( $new_post_id, $post_meta ); } + /** + * Allow bypassing of all term processing. + * + * @hook dt_push_post_terms + * + * @param {bool} true If Distributor should push the post terms. + * @param {int} $new_post_id The newly created post ID. + * @param {array} $post_terms Terms attached to the post, formatted by {@link \Distributor\Utils\prepare_taxonomy_terms()}. + * @param {int} $post_id The original post ID. + * @param {array} $args The arguments passed into wp_insert_post. + * @param {Connection} $this The distributor connection being pushed to. + * + * @return {bool} If Distributor should push the post terms. + */ if ( apply_filters( 'dt_push_post_terms', true, $new_post_id, $post_terms, $post_id, $args, $this ) ) { Utils\set_taxonomy_terms( $new_post_id, $post_terms ); } @@ -191,20 +205,7 @@ public function push( $post, $args = array() ) { delete_transient( 'dt_media_errors_' . $new_post_id ); } - /** - * Allow bypassing of all term processing. - * - * @hook dt_push_post_terms - * - * @param {bool} true If Distributor should push the post terms. - * @param {int} $new_post_id The newly created post ID. - * @param {array} $post_terms Terms attached to the post, formatted by {@link \Distributor\Utils\prepare_taxonomy_terms()}. - * @param {int} $post_id The original post ID. - * @param {array} $args The arguments passed into wp_insert_post. - * @param {Connection} $this The distributor connection being pushed to. - * - * @return {bool} If Distributor should push the post terms. - */ + /** This filter is documented in includes/classes/InternalConnections/NetworkSiteConnection.php */ do_action_deprecated( 'dt_push_post', array( $new_post_id, $post_id, $args, $this ), From 6bede2bb42bfde1522481297412eb8b87302e095 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 7 Mar 2023 17:53:11 +0530 Subject: [PATCH 03/12] doc: add action hook comment --- .../InternalConnections/NetworkSiteConnection.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/classes/InternalConnections/NetworkSiteConnection.php b/includes/classes/InternalConnections/NetworkSiteConnection.php index 862bf5fec..14377e7da 100644 --- a/includes/classes/InternalConnections/NetworkSiteConnection.php +++ b/includes/classes/InternalConnections/NetworkSiteConnection.php @@ -205,7 +205,14 @@ public function push( $post, $args = array() ) { delete_transient( 'dt_media_errors_' . $new_post_id ); } - /** This filter is documented in includes/classes/InternalConnections/NetworkSiteConnection.php */ + /** + * Fires after a post is pushed via Distributor before `restore_current_blog()`. + * + * @param {int} $new_post_id The newly created post. + * @param {int} $post_id The original post. + * @param {array} $args The arguments passed into wp_insert_post. + * @param {Connection} $this The Distributor connection being pushed to. + */ do_action_deprecated( 'dt_push_post', array( $new_post_id, $post_id, $args, $this ), From 2d683e28d59b08d5ef284b439d627bd7a3d8b5b1 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 24 Mar 2023 14:52:18 +0530 Subject: [PATCH 04/12] fix: pass same paramerter to action hook and improve documentation --- .../WordPressExternalConnection.php | 15 +++++++++------ .../InternalConnections/NetworkSiteConnection.php | 9 ++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/includes/classes/ExternalConnections/WordPressExternalConnection.php b/includes/classes/ExternalConnections/WordPressExternalConnection.php index ca3571b00..0289cc9db 100644 --- a/includes/classes/ExternalConnections/WordPressExternalConnection.php +++ b/includes/classes/ExternalConnections/WordPressExternalConnection.php @@ -714,16 +714,19 @@ public function push( $post, $args = array() ) { ); /** - * Fires the action after a post is pushed via Distributor before `restore_current_blog()`. + * Fires the action after a post is pushed via Distributor before remote request validation. * * @since 2.0.0 + * @hook dt_push_external_post * - * @param {WP_Post} $response The newly created post. - * @param {WP_Post} $post_id The original post. - * @param {array} $args The arguments passed into wp_insert_post. - * @param {Connection} $this The Distributor connection being pushed to. + * @param {array|WP_Error} $response The response from the remote request. + * @param {array} $post_body The Post data formatted for the REST API endpoint. + * @param {string} $type_url The Post type api endpoint. + * @param {int} $post_id The Post id. + * @param {array} $args The arguments passed into wp_insert_post. + * @param {WordPressExternalConnection} $this The Distributor connection being pushed to. */ - do_action( 'dt_push_external_post', $response, $post, $args, $this ); + do_action( 'dt_push_external_post', $response, $post_body, $type_url, $post_id, $args, $this ); if ( is_wp_error( $response ) ) { return $response; diff --git a/includes/classes/InternalConnections/NetworkSiteConnection.php b/includes/classes/InternalConnections/NetworkSiteConnection.php index 14377e7da..907b5aacb 100644 --- a/includes/classes/InternalConnections/NetworkSiteConnection.php +++ b/includes/classes/InternalConnections/NetworkSiteConnection.php @@ -224,11 +224,14 @@ public function push( $post, $args = array() ) { * Fires the action after a post is pushed via Distributor before `restore_current_blog()`. * * @since 2.0.0 + * @hook dt_push_network_post * - * @param {int} $new_post_id The newly created post. - * @param {int} $post_id The original post. + * @param {int} $new_post_id The newly created post. + * @param {int} $post_id The original post. + * @param {array} $args The arguments passed into wp_insert_post. + * @param {NetworkSiteConnection} $this The Distributor connection being pushed to. */ - do_action( 'dt_push_network_post', $new_post_id, $post_id ); + do_action( 'dt_push_network_post', $new_post_id, $post_id, $args, $this ); restore_current_blog(); From ea03a08520b9800d630eba860476fbe807f92807 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 24 Mar 2023 15:01:32 +0530 Subject: [PATCH 05/12] doc: improve documentation for deprecated dt_push_post action hook --- .../WordPressExternalConnection.php | 3 +- .../NetworkSiteConnection.php | 32 ++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/includes/classes/ExternalConnections/WordPressExternalConnection.php b/includes/classes/ExternalConnections/WordPressExternalConnection.php index 0289cc9db..e5f817edb 100644 --- a/includes/classes/ExternalConnections/WordPressExternalConnection.php +++ b/includes/classes/ExternalConnections/WordPressExternalConnection.php @@ -710,7 +710,8 @@ public function push( $post, $args = array() ) { 'dt_push_post', array( $response, $post_body, $type_url, $post_id, $args, $this ), '2.0.0', - 'dt_push_external_post' + 'dt_push_network_post|dt_push_external_post', + esc_html__( 'The dt_push_post action has been deprecated. Please use dt_push_network_post or dt_push_external_post instead.', 'distributor' ) ); /** diff --git a/includes/classes/InternalConnections/NetworkSiteConnection.php b/includes/classes/InternalConnections/NetworkSiteConnection.php index 907b5aacb..be7665bf8 100644 --- a/includes/classes/InternalConnections/NetworkSiteConnection.php +++ b/includes/classes/InternalConnections/NetworkSiteConnection.php @@ -124,14 +124,22 @@ public function push( $post, $args = array() ) { /** * Fires after a post is pushed via Distributor before `restore_current_blog()`. * - * @hook dt_push_post + * @since 1.0.0 + * @deprecated 2.0.0 The dt_push_post action has been deprecated. Please use dt_push_network_post or dt_push_external_post instead. + * @hook dt_push_post * - * @param {int} $new_post_id The newly created post ID. - * @param {int} $post_id The original post ID. - * @param {array} $args The arguments passed into wp_insert_post. - * @param {Connection} $this The Distributor connection being pushed to. + * @param {int} $new_post_id The newly created post. + * @param {int} $post_id The original post. + * @param {array} $args The arguments passed into wp_insert_post. + * @param {Connection} $this The Distributor connection being pushed to. */ - do_action( 'dt_push_post', $new_post_id, $post_id, $args, $this ); + do_action_deprecated( + 'dt_push_post', + array($new_post_id, $post_id, $args, $this), + '2.0.0', + 'dt_push_network_post|dt_push_external_post', + esc_html__( 'The dt_push_post action has been deprecated. Please use dt_push_network_post or dt_push_external_post instead.', 'distributor' ) + ); restore_current_blog(); @@ -205,19 +213,13 @@ public function push( $post, $args = array() ) { delete_transient( 'dt_media_errors_' . $new_post_id ); } - /** - * Fires after a post is pushed via Distributor before `restore_current_blog()`. - * - * @param {int} $new_post_id The newly created post. - * @param {int} $post_id The original post. - * @param {array} $args The arguments passed into wp_insert_post. - * @param {Connection} $this The Distributor connection being pushed to. - */ + /** This filter is documented in includes/classes/InternalConnections/NetworkSiteConnection.php */ do_action_deprecated( 'dt_push_post', array( $new_post_id, $post_id, $args, $this ), '2.0.0', - '' + 'dt_push_network_post|dt_push_external_post', + esc_html__( 'The dt_push_post action has been deprecated. Please use dt_push_network_post or dt_push_external_post instead.', 'distributor' ) ); /** From 4312ddd0c9bbeca10af211207902a188610e5a2d Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 24 Mar 2023 15:04:28 +0530 Subject: [PATCH 06/12] format: improve code formatting --- includes/classes/InternalConnections/NetworkSiteConnection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/classes/InternalConnections/NetworkSiteConnection.php b/includes/classes/InternalConnections/NetworkSiteConnection.php index be7665bf8..88485adad 100644 --- a/includes/classes/InternalConnections/NetworkSiteConnection.php +++ b/includes/classes/InternalConnections/NetworkSiteConnection.php @@ -135,7 +135,7 @@ public function push( $post, $args = array() ) { */ do_action_deprecated( 'dt_push_post', - array($new_post_id, $post_id, $args, $this), + array( $new_post_id, $post_id, $args, $this ), '2.0.0', 'dt_push_network_post|dt_push_external_post', esc_html__( 'The dt_push_post action has been deprecated. Please use dt_push_network_post or dt_push_external_post instead.', 'distributor' ) From 08955824473cedd967074342d39968ba36786aff Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 24 Mar 2023 15:06:51 +0530 Subject: [PATCH 07/12] doc: update since tag value --- includes/classes/InternalConnections/NetworkSiteConnection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/classes/InternalConnections/NetworkSiteConnection.php b/includes/classes/InternalConnections/NetworkSiteConnection.php index 88485adad..4527f9135 100644 --- a/includes/classes/InternalConnections/NetworkSiteConnection.php +++ b/includes/classes/InternalConnections/NetworkSiteConnection.php @@ -124,7 +124,7 @@ public function push( $post, $args = array() ) { /** * Fires after a post is pushed via Distributor before `restore_current_blog()`. * - * @since 1.0.0 + * @since 1.2.2 * @deprecated 2.0.0 The dt_push_post action has been deprecated. Please use dt_push_network_post or dt_push_external_post instead. * @hook dt_push_post * From d675e5f23a1d0d266966a497760afe0babcd9304 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 24 Mar 2023 15:10:20 +0530 Subject: [PATCH 08/12] fix: trigger dt_push_network_post --- .../NetworkSiteConnection.php | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/includes/classes/InternalConnections/NetworkSiteConnection.php b/includes/classes/InternalConnections/NetworkSiteConnection.php index 4527f9135..20ffbe7df 100644 --- a/includes/classes/InternalConnections/NetworkSiteConnection.php +++ b/includes/classes/InternalConnections/NetworkSiteConnection.php @@ -141,6 +141,19 @@ public function push( $post, $args = array() ) { esc_html__( 'The dt_push_post action has been deprecated. Please use dt_push_network_post or dt_push_external_post instead.', 'distributor' ) ); + /** + * Fires the action after a post is pushed via Distributor before `restore_current_blog()`. + * + * @since 2.0.0 + * @hook dt_push_network_post + * + * @param {int} $new_post_id The newly created post. + * @param {int} $post_id The original post. + * @param {array} $args The arguments passed into wp_insert_post. + * @param {NetworkSiteConnection} $this The Distributor connection being pushed to. + */ + do_action( 'dt_push_network_post', $new_post_id, $post_id, $args, $this ); + restore_current_blog(); return $new_post_id; @@ -222,17 +235,7 @@ public function push( $post, $args = array() ) { esc_html__( 'The dt_push_post action has been deprecated. Please use dt_push_network_post or dt_push_external_post instead.', 'distributor' ) ); - /** - * Fires the action after a post is pushed via Distributor before `restore_current_blog()`. - * - * @since 2.0.0 - * @hook dt_push_network_post - * - * @param {int} $new_post_id The newly created post. - * @param {int} $post_id The original post. - * @param {array} $args The arguments passed into wp_insert_post. - * @param {NetworkSiteConnection} $this The Distributor connection being pushed to. - */ + /** This filter is documented in includes/classes/InternalConnections/NetworkSiteConnection.php */ do_action( 'dt_push_network_post', $new_post_id, $post_id, $args, $this ); restore_current_blog(); From 3efac62971ebe4d1b92482fa5a02c668674c1732 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 24 Mar 2023 15:38:00 +0530 Subject: [PATCH 09/12] doc: fix typo --- includes/utils.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/utils.php b/includes/utils.php index 3894db973..587190986 100644 --- a/includes/utils.php +++ b/includes/utils.php @@ -846,11 +846,11 @@ function process_media( $url, $post_id, $args = [] ) { * @since 1.3.7 * @hook dt_media_processing_filename * - * @param {string} $media_name Filemame of the media being processed. + * @param {string} $media_name Filename of the media being processed. * @param {string} $url Media url. * @param {int} $post_id Post ID. * - * @return {string} Filemame of the media being processed. + * @return {string} Filename of the media being processed. */ $media_name = apply_filters( 'dt_media_processing_filename', $media_name, $url, $post_id ); From 1f72f2643e8bd9f986f23dd021950ea6a91d0d1f Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Fri, 24 Mar 2023 16:05:14 +0530 Subject: [PATCH 10/12] test: fix broken tests --- tests/php/NetworkSiteConnectionsTest.php | 1 + tests/php/WordPressExternalConnectionTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/php/NetworkSiteConnectionsTest.php b/tests/php/NetworkSiteConnectionsTest.php index ec2766109..14e3f5aa8 100644 --- a/tests/php/NetworkSiteConnectionsTest.php +++ b/tests/php/NetworkSiteConnectionsTest.php @@ -109,6 +109,7 @@ public function test_push() { ) ); + \WP_Mock::userFunction( 'do_action_deprecated' ); \WP_Mock::userFunction( 'get_current_user_id' ); \WP_Mock::userFunction( 'switch_to_blog' ); \WP_Mock::userFunction( 'add_filter' ); diff --git a/tests/php/WordPressExternalConnectionTest.php b/tests/php/WordPressExternalConnectionTest.php index 541a070fd..b74d1bc48 100644 --- a/tests/php/WordPressExternalConnectionTest.php +++ b/tests/php/WordPressExternalConnectionTest.php @@ -80,6 +80,7 @@ public function test_construct() { */ public function test_push() { $this->setup_post_meta_mock( array() ); + \WP_Mock::userFunction( 'do_action_deprecated' ); \WP_Mock::userFunction( 'untrailingslashit' ); \WP_Mock::userFunction( 'get_the_title' ); \WP_Mock::userFunction( 'wp_remote_post' ); @@ -129,7 +130,6 @@ public function test_push() { 'post_excerpt' => 'post excerpt', 'post_name' => 'slug', 'post_status' => 'publish', - 'post_type' => $post_type, 'ID' => 1, ]; From 1a85bf6b1cc496b2a70fcec88e7962f5d191fbd5 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 18 Apr 2023 10:27:54 +0530 Subject: [PATCH 11/12] Update includes/classes/ExternalConnections/WordPressExternalConnection.php Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> --- .../ExternalConnections/WordPressExternalConnection.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/classes/ExternalConnections/WordPressExternalConnection.php b/includes/classes/ExternalConnections/WordPressExternalConnection.php index e5f817edb..9cecedf6c 100644 --- a/includes/classes/ExternalConnections/WordPressExternalConnection.php +++ b/includes/classes/ExternalConnections/WordPressExternalConnection.php @@ -710,8 +710,7 @@ public function push( $post, $args = array() ) { 'dt_push_post', array( $response, $post_body, $type_url, $post_id, $args, $this ), '2.0.0', - 'dt_push_network_post|dt_push_external_post', - esc_html__( 'The dt_push_post action has been deprecated. Please use dt_push_network_post or dt_push_external_post instead.', 'distributor' ) + 'dt_push_network_post|dt_push_external_post' ); /** From c4a3b1b5f66d3550d31ebd6d6ab8bf0501f08058 Mon Sep 17 00:00:00 2001 From: Ravinder Kumar Date: Tue, 18 Apr 2023 10:28:05 +0530 Subject: [PATCH 12/12] Update includes/classes/InternalConnections/NetworkSiteConnection.php Co-authored-by: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> --- includes/classes/InternalConnections/NetworkSiteConnection.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/classes/InternalConnections/NetworkSiteConnection.php b/includes/classes/InternalConnections/NetworkSiteConnection.php index 20ffbe7df..abebb768e 100644 --- a/includes/classes/InternalConnections/NetworkSiteConnection.php +++ b/includes/classes/InternalConnections/NetworkSiteConnection.php @@ -137,8 +137,7 @@ public function push( $post, $args = array() ) { 'dt_push_post', array( $new_post_id, $post_id, $args, $this ), '2.0.0', - 'dt_push_network_post|dt_push_external_post', - esc_html__( 'The dt_push_post action has been deprecated. Please use dt_push_network_post or dt_push_external_post instead.', 'distributor' ) + 'dt_push_network_post|dt_push_external_post' ); /**