From c131a7c1372b84d633f8824fc7dbedc7f587432e Mon Sep 17 00:00:00 2001 From: Juanma Rodriguez Escriche Date: Fri, 26 Apr 2024 14:04:11 +0200 Subject: [PATCH] Jetpack Sync: Update/send post for jetpack published post (#37071) * 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 --- ...pdate-send-post-for-jetpack-published-post | 4 ++++ projects/packages/sync/composer.json | 2 +- .../sync/src/class-package-version.php | 2 +- .../packages/sync/src/modules/class-posts.php | 22 ++++++++++++++----- ...pdate-send-post-for-jetpack-published-post | 5 +++++ .../composer.lock | 4 ++-- ...pdate-send-post-for-jetpack-published-post | 5 +++++ projects/plugins/backup/composer.lock | 4 ++-- ...pdate-send-post-for-jetpack-published-post | 5 +++++ projects/plugins/boost/composer.lock | 4 ++-- ...pdate-send-post-for-jetpack-published-post | 5 +++++ projects/plugins/jetpack/composer.lock | 4 ++-- .../sync/test_class.jetpack-sync-posts.php | 12 +++++----- ...pdate-send-post-for-jetpack-published-post | 5 +++++ projects/plugins/migration/composer.lock | 4 ++-- ...pdate-send-post-for-jetpack-published-post | 5 +++++ projects/plugins/protect/composer.lock | 4 ++-- ...pdate-send-post-for-jetpack-published-post | 5 +++++ projects/plugins/search/composer.lock | 4 ++-- ...pdate-send-post-for-jetpack-published-post | 5 +++++ projects/plugins/social/composer.lock | 4 ++-- ...pdate-send-post-for-jetpack-published-post | 5 +++++ projects/plugins/starter-plugin/composer.lock | 4 ++-- ...pdate-send-post-for-jetpack-published-post | 5 +++++ projects/plugins/videopress/composer.lock | 4 ++-- 25 files changed, 98 insertions(+), 34 deletions(-) create mode 100644 projects/packages/sync/changelog/update-send-post-for-jetpack-published-post create mode 100644 projects/plugins/automattic-for-agencies-client/changelog/update-send-post-for-jetpack-published-post create mode 100644 projects/plugins/backup/changelog/update-send-post-for-jetpack-published-post create mode 100644 projects/plugins/boost/changelog/update-send-post-for-jetpack-published-post create mode 100644 projects/plugins/jetpack/changelog/update-send-post-for-jetpack-published-post create mode 100644 projects/plugins/migration/changelog/update-send-post-for-jetpack-published-post create mode 100644 projects/plugins/protect/changelog/update-send-post-for-jetpack-published-post create mode 100644 projects/plugins/search/changelog/update-send-post-for-jetpack-published-post create mode 100644 projects/plugins/social/changelog/update-send-post-for-jetpack-published-post create mode 100644 projects/plugins/starter-plugin/changelog/update-send-post-for-jetpack-published-post create mode 100644 projects/plugins/videopress/changelog/update-send-post-for-jetpack-published-post diff --git a/projects/packages/sync/changelog/update-send-post-for-jetpack-published-post b/projects/packages/sync/changelog/update-send-post-for-jetpack-published-post new file mode 100644 index 0000000000000..cbe4ac8e619ef --- /dev/null +++ b/projects/packages/sync/changelog/update-send-post-for-jetpack-published-post @@ -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. diff --git a/projects/packages/sync/composer.json b/projects/packages/sync/composer.json index f6401dea7453a..abbefef08b8c4 100644 --- a/projects/packages/sync/composer.json +++ b/projects/packages/sync/composer.json @@ -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": { diff --git a/projects/packages/sync/src/class-package-version.php b/projects/packages/sync/src/class-package-version.php index b34ede89213a6..f94f7fffae8a2 100644 --- a/projects/packages/sync/src/class-package-version.php +++ b/projects/packages/sync/src/class-package-version.php @@ -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'; diff --git a/projects/packages/sync/src/modules/class-posts.php b/projects/packages/sync/src/modules/class-posts.php index 45598f92f1490..41ad7899cc68f 100644 --- a/projects/packages/sync/src/modules/class-posts.php +++ b/projects/packages/sync/src/modules/class-posts.php @@ -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 ); @@ -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' ) ); @@ -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. * @@ -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. * @@ -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 ] ); diff --git a/projects/plugins/automattic-for-agencies-client/changelog/update-send-post-for-jetpack-published-post b/projects/plugins/automattic-for-agencies-client/changelog/update-send-post-for-jetpack-published-post new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/automattic-for-agencies-client/changelog/update-send-post-for-jetpack-published-post @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/automattic-for-agencies-client/composer.lock b/projects/plugins/automattic-for-agencies-client/composer.lock index fd8e457e0d886..1827e2c1ca6dc 100644 --- a/projects/plugins/automattic-for-agencies-client/composer.lock +++ b/projects/plugins/automattic-for-agencies-client/composer.lock @@ -993,7 +993,7 @@ "dist": { "type": "path", "url": "../../packages/sync", - "reference": "b1bbaa41c0511633ee32d04d3ce37e4953a3c322" + "reference": "5f1e574ac98b4cfa494ee2585d7adb9efe89189b" }, "require": { "automattic/jetpack-connection": "@dev", @@ -1025,7 +1025,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" } }, "autoload": { diff --git a/projects/plugins/backup/changelog/update-send-post-for-jetpack-published-post b/projects/plugins/backup/changelog/update-send-post-for-jetpack-published-post new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/backup/changelog/update-send-post-for-jetpack-published-post @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/backup/composer.lock b/projects/plugins/backup/composer.lock index 4d59d4a39b252..ce401c0ee1d91 100644 --- a/projects/plugins/backup/composer.lock +++ b/projects/plugins/backup/composer.lock @@ -1546,7 +1546,7 @@ "dist": { "type": "path", "url": "../../packages/sync", - "reference": "b1bbaa41c0511633ee32d04d3ce37e4953a3c322" + "reference": "5f1e574ac98b4cfa494ee2585d7adb9efe89189b" }, "require": { "automattic/jetpack-connection": "@dev", @@ -1578,7 +1578,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" } }, "autoload": { diff --git a/projects/plugins/boost/changelog/update-send-post-for-jetpack-published-post b/projects/plugins/boost/changelog/update-send-post-for-jetpack-published-post new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/boost/changelog/update-send-post-for-jetpack-published-post @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/boost/composer.lock b/projects/plugins/boost/composer.lock index 40088db4a9649..ee475fdbd91d5 100644 --- a/projects/plugins/boost/composer.lock +++ b/projects/plugins/boost/composer.lock @@ -1536,7 +1536,7 @@ "dist": { "type": "path", "url": "../../packages/sync", - "reference": "b1bbaa41c0511633ee32d04d3ce37e4953a3c322" + "reference": "5f1e574ac98b4cfa494ee2585d7adb9efe89189b" }, "require": { "automattic/jetpack-connection": "@dev", @@ -1568,7 +1568,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" } }, "autoload": { diff --git a/projects/plugins/jetpack/changelog/update-send-post-for-jetpack-published-post b/projects/plugins/jetpack/changelog/update-send-post-for-jetpack-published-post new file mode 100644 index 0000000000000..a1c1831fa1ef7 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-send-post-for-jetpack-published-post @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: Updated composer.lock. + + diff --git a/projects/plugins/jetpack/composer.lock b/projects/plugins/jetpack/composer.lock index 3a1de4ddc8f1d..279d7b90f231f 100644 --- a/projects/plugins/jetpack/composer.lock +++ b/projects/plugins/jetpack/composer.lock @@ -2454,7 +2454,7 @@ "dist": { "type": "path", "url": "../../packages/sync", - "reference": "b1bbaa41c0511633ee32d04d3ce37e4953a3c322" + "reference": "5f1e574ac98b4cfa494ee2585d7adb9efe89189b" }, "require": { "automattic/jetpack-connection": "@dev", @@ -2486,7 +2486,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" } }, "autoload": { diff --git a/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-posts.php b/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-posts.php index 0b29c270a121e..467cff4a738d2 100644 --- a/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-posts.php +++ b/projects/plugins/jetpack/tests/php/sync/test_class.jetpack-sync-posts.php @@ -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 ); } /** diff --git a/projects/plugins/migration/changelog/update-send-post-for-jetpack-published-post b/projects/plugins/migration/changelog/update-send-post-for-jetpack-published-post new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/migration/changelog/update-send-post-for-jetpack-published-post @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/migration/composer.lock b/projects/plugins/migration/composer.lock index 14fb1b5f7d925..1155b6ccc6cb9 100644 --- a/projects/plugins/migration/composer.lock +++ b/projects/plugins/migration/composer.lock @@ -1546,7 +1546,7 @@ "dist": { "type": "path", "url": "../../packages/sync", - "reference": "b1bbaa41c0511633ee32d04d3ce37e4953a3c322" + "reference": "5f1e574ac98b4cfa494ee2585d7adb9efe89189b" }, "require": { "automattic/jetpack-connection": "@dev", @@ -1578,7 +1578,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" } }, "autoload": { diff --git a/projects/plugins/protect/changelog/update-send-post-for-jetpack-published-post b/projects/plugins/protect/changelog/update-send-post-for-jetpack-published-post new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/protect/changelog/update-send-post-for-jetpack-published-post @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/protect/composer.lock b/projects/plugins/protect/composer.lock index 0a531ee1b8da8..6db6ad213178a 100644 --- a/projects/plugins/protect/composer.lock +++ b/projects/plugins/protect/composer.lock @@ -1459,7 +1459,7 @@ "dist": { "type": "path", "url": "../../packages/sync", - "reference": "b1bbaa41c0511633ee32d04d3ce37e4953a3c322" + "reference": "5f1e574ac98b4cfa494ee2585d7adb9efe89189b" }, "require": { "automattic/jetpack-connection": "@dev", @@ -1491,7 +1491,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" } }, "autoload": { diff --git a/projects/plugins/search/changelog/update-send-post-for-jetpack-published-post b/projects/plugins/search/changelog/update-send-post-for-jetpack-published-post new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/search/changelog/update-send-post-for-jetpack-published-post @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/search/composer.lock b/projects/plugins/search/composer.lock index e4afb92cfe24c..712c3aafb2eb0 100644 --- a/projects/plugins/search/composer.lock +++ b/projects/plugins/search/composer.lock @@ -1550,7 +1550,7 @@ "dist": { "type": "path", "url": "../../packages/sync", - "reference": "b1bbaa41c0511633ee32d04d3ce37e4953a3c322" + "reference": "5f1e574ac98b4cfa494ee2585d7adb9efe89189b" }, "require": { "automattic/jetpack-connection": "@dev", @@ -1582,7 +1582,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" } }, "autoload": { diff --git a/projects/plugins/social/changelog/update-send-post-for-jetpack-published-post b/projects/plugins/social/changelog/update-send-post-for-jetpack-published-post new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/social/changelog/update-send-post-for-jetpack-published-post @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/social/composer.lock b/projects/plugins/social/composer.lock index 117f550ef38f0..c91ce26717f91 100644 --- a/projects/plugins/social/composer.lock +++ b/projects/plugins/social/composer.lock @@ -1541,7 +1541,7 @@ "dist": { "type": "path", "url": "../../packages/sync", - "reference": "b1bbaa41c0511633ee32d04d3ce37e4953a3c322" + "reference": "5f1e574ac98b4cfa494ee2585d7adb9efe89189b" }, "require": { "automattic/jetpack-connection": "@dev", @@ -1573,7 +1573,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" } }, "autoload": { diff --git a/projects/plugins/starter-plugin/changelog/update-send-post-for-jetpack-published-post b/projects/plugins/starter-plugin/changelog/update-send-post-for-jetpack-published-post new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/starter-plugin/changelog/update-send-post-for-jetpack-published-post @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/starter-plugin/composer.lock b/projects/plugins/starter-plugin/composer.lock index acdbc18baa8d3..cc45b29eb1a1e 100644 --- a/projects/plugins/starter-plugin/composer.lock +++ b/projects/plugins/starter-plugin/composer.lock @@ -1402,7 +1402,7 @@ "dist": { "type": "path", "url": "../../packages/sync", - "reference": "b1bbaa41c0511633ee32d04d3ce37e4953a3c322" + "reference": "5f1e574ac98b4cfa494ee2585d7adb9efe89189b" }, "require": { "automattic/jetpack-connection": "@dev", @@ -1434,7 +1434,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" } }, "autoload": { diff --git a/projects/plugins/videopress/changelog/update-send-post-for-jetpack-published-post b/projects/plugins/videopress/changelog/update-send-post-for-jetpack-published-post new file mode 100644 index 0000000000000..9aa70e3ec1f75 --- /dev/null +++ b/projects/plugins/videopress/changelog/update-send-post-for-jetpack-published-post @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Updated composer.lock. + + diff --git a/projects/plugins/videopress/composer.lock b/projects/plugins/videopress/composer.lock index 4dd3432070c0d..3a1db7f54c78e 100644 --- a/projects/plugins/videopress/composer.lock +++ b/projects/plugins/videopress/composer.lock @@ -1402,7 +1402,7 @@ "dist": { "type": "path", "url": "../../packages/sync", - "reference": "b1bbaa41c0511633ee32d04d3ce37e4953a3c322" + "reference": "5f1e574ac98b4cfa494ee2585d7adb9efe89189b" }, "require": { "automattic/jetpack-connection": "@dev", @@ -1434,7 +1434,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" } }, "autoload": {