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

tweak: add new action hooks and deprecated existing #1024

Merged
merged 15 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -706,7 +706,27 @@ public function push( $post, $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_network_post|dt_push_external_post'
);

/**
* Fires the action after a post is pushed via Distributor before remote request validation.
*
* @since 2.0.0
* @hook dt_push_external_post
*
* @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_body, $type_url, $post_id, $args, $this );

if ( is_wp_error( $response ) ) {
return $response;
Expand Down
43 changes: 36 additions & 7 deletions includes/classes/InternalConnections/NetworkSiteConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,34 @@ public function push( $post, $args = array() ) {
/**
* Fires after a post is pushed via Distributor before `restore_current_blog()`.
*
* @hook dt_push_post
* @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
*
* @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'
);

/**
* 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();

Expand Down Expand Up @@ -206,7 +226,16 @@ public function push( $post, $args = array() ) {
}

/** This filter is documented in includes/classes/InternalConnections/NetworkSiteConnection.php */
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' )
ravinderk marked this conversation as resolved.
Show resolved Hide resolved
);

/** 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();

Expand Down
4 changes: 2 additions & 2 deletions includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
1 change: 1 addition & 0 deletions tests/php/NetworkSiteConnectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
2 changes: 1 addition & 1 deletion tests/php/WordPressExternalConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down Expand Up @@ -129,7 +130,6 @@ public function test_push() {
'post_excerpt' => 'post excerpt',
'post_name' => 'slug',
'post_status' => 'publish',
'post_type' => $post_type,
ravinderk marked this conversation as resolved.
Show resolved Hide resolved
'ID' => 1,
];

Expand Down