Skip to content

Commit

Permalink
Jetpack Sync: Update/send post for jetpack published post (#37071)
Browse files Browse the repository at this point in the history
* Send post in jetpack_published_post action. Remove the extra wp_insert_post action

* Changelog

* Fix tests

* Version bump

* Added filter_jetpack_sync_before_enqueue_jetpack_published_post
  • Loading branch information
darssen authored Apr 26, 2024
1 parent adace6c commit c131a7c
Show file tree
Hide file tree
Showing 25 changed files with 98 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Sync: When publishing post, sending the actual post in the jetpack_published_post action to avoid sending unnecessary extra action.
2 changes: 1 addition & 1 deletion projects/packages/sync/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"link-template": "https://github.com/Automattic/jetpack-sync/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "2.13.x-dev"
"dev-trunk": "2.14.x-dev"
}
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/sync/src/class-package-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class Package_Version {

const PACKAGE_VERSION = '2.13.2-alpha';
const PACKAGE_VERSION = '2.14.0-alpha';

const PACKAGE_SLUG = 'sync';

Expand Down
22 changes: 16 additions & 6 deletions projects/packages/sync/src/modules/class-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function init_listeners( $callable ) {
add_action( 'jetpack_sync_save_post', $callable, 10, 4 );

add_action( 'deleted_post', $callable, 10 );
add_action( 'jetpack_published_post', $callable, 10, 2 );
add_action( 'jetpack_published_post', $callable, 10, 3 );
add_filter( 'jetpack_sync_before_enqueue_deleted_post', array( $this, 'filter_blacklisted_post_types_deleted' ) );

add_action( 'transition_post_status', array( $this, 'save_published' ), 10, 3 );
Expand All @@ -161,6 +161,7 @@ public function init_listeners( $callable ) {
$this->init_meta_whitelist_handler( 'post', array( $this, 'filter_meta' ) );

add_filter( 'jetpack_sync_before_enqueue_jetpack_sync_save_post', array( $this, 'filter_jetpack_sync_before_enqueue_jetpack_sync_save_post' ) );
add_filter( 'jetpack_sync_before_enqueue_jetpack_published_post', array( $this, 'filter_jetpack_sync_before_enqueue_jetpack_published_post' ) );

add_action( 'jetpack_daily_akismet_meta_cleanup_before', array( $this, 'daily_akismet_meta_cleanup_before' ) );
add_action( 'jetpack_daily_akismet_meta_cleanup_after', array( $this, 'daily_akismet_meta_cleanup_after' ) );
Expand Down Expand Up @@ -351,6 +352,18 @@ public function filter_jetpack_sync_before_enqueue_jetpack_sync_save_post( $args
return array( $post_id, $this->filter_post_content_and_add_links( $post ), $update, $previous_state );
}

/**
* Add filtered post content.
*
* @param array $args Hook arguments.
* @return array Hook arguments.
*/
public function filter_jetpack_sync_before_enqueue_jetpack_published_post( $args ) {
list( $post_id, $flags, $post ) = $args;

return array( $post_id, $flags, $this->filter_post_content_and_add_links( $post ) );
}

/**
* Filter all blacklisted post types.
*
Expand Down Expand Up @@ -732,10 +745,6 @@ public function send_published( $post_ID, $post ) {
// Only Send Pulished Post event if post_type is not blacklisted.
if ( ! in_array( $post->post_type, Settings::get_setting( 'post_types_blacklist' ), true ) ) {

// Refreshing the post in the cache site before triggering the publish event.
// The true parameter means that it's an update action, not create action.
$this->wp_insert_post( $post_ID, $post, true );

/**
* Action that gets synced when a post type gets published.
*
Expand All @@ -744,8 +753,9 @@ public function send_published( $post_ID, $post ) {
*
* @param int $post_ID
* @param mixed array $flags post flags that are added to the post
* @param WP_Post $post The post object
*/
do_action( 'jetpack_published_post', $post_ID, $flags );
do_action( 'jetpack_published_post', $post_ID, $flags, $post );
}
unset( $this->just_published[ $post_ID ] );

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/automattic-for-agencies-client/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/backup/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/boost/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/jetpack/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1366,15 +1366,15 @@ public function test_sync_jetpack_publish_post_works_with_interjecting_plugins()

$events = $this->server_event_storage->get_all_events();

$events = array_slice( $events, -6 );
$events = array_slice( $events, -4 );

$this->assertEquals( $events[0]->args[0], $events[2]->args[0] );
$this->assertEquals( $events[0]->args[0], $events[1]->args[0] );
$this->assertEquals( 'jetpack_sync_save_post', $events[0]->action );
$this->assertEquals( 'jetpack_published_post', $events[2]->action );
$this->assertEquals( 'jetpack_published_post', $events[1]->action );

$this->assertEquals( $events[3]->args[0], $events[5]->args[0] );
$this->assertEquals( 'jetpack_sync_save_post', $events[3]->action );
$this->assertEquals( 'jetpack_published_post', $events[5]->action );
$this->assertEquals( $events[2]->args[0], $events[3]->args[0] );
$this->assertEquals( 'jetpack_sync_save_post', $events[2]->action );
$this->assertEquals( 'jetpack_published_post', $events[3]->action );
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/migration/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/protect/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/search/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/social/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/starter-plugin/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


4 changes: 2 additions & 2 deletions projects/plugins/videopress/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c131a7c

Please sign in to comment.