From c59111945f286104c0f133d87f1210fa309e5c13 Mon Sep 17 00:00:00 2001 From: Adam Boro Date: Tue, 6 Feb 2024 09:48:47 +0100 Subject: [PATCH 1/8] fix(distributor): match yoast primary category --- includes/class-distributor-customizations.php | 2 - .../distributor-customizations/global.php | 90 ++++++++++++++----- 2 files changed, 68 insertions(+), 24 deletions(-) diff --git a/includes/class-distributor-customizations.php b/includes/class-distributor-customizations.php index e51c9d54..12d45f46 100644 --- a/includes/class-distributor-customizations.php +++ b/includes/class-distributor-customizations.php @@ -24,6 +24,4 @@ public static function init() { Distributor_Customizations\Author_Ingestion::init(); Distributor_Customizations\Authorship_Filters::init(); } - - } diff --git a/includes/distributor-customizations/global.php b/includes/distributor-customizations/global.php index b9367505..43159beb 100644 --- a/includes/distributor-customizations/global.php +++ b/includes/distributor-customizations/global.php @@ -1,23 +1,64 @@ ID ); + $category_id = $primary_term->get_primary_term(); + if ( $category_id ) { + $category = get_term( $category_id ); + return $category->slug; + } + } +} + +/** + * Fix primary category on the Node. + * + * @param WP_Post $post The post object. + * @param WP_REST_Request $request The request data. + */ +function newspack_network_fix_primary_category( $post, $request ) { + $primary_category_id = get_post_meta( $post->ID, '_yoast_wpseo_primary_category', true ); + $primary_category_slug = get_post_meta( $post->ID, 'yoast_primary_category_slug', true ); + $hub_primary_category = get_term( $primary_category_id ); + if ( ! $hub_primary_category ) { + // Attempt to find a matching category on the Hub site by slug. + $hub_primary_category = get_term_by( 'slug', $primary_category_slug, 'category' ); + } + if ( $hub_primary_category ) { + update_post_meta( $post->ID, '_yoast_wpseo_primary_category', $hub_primary_category->term_id ); + } elseif ( class_exists( '\Newspack\Logger' ) ) { + \Newspack\Logger::error( __( 'No matching category found on the Hub site.', 'newspack-network' ) ); + } +} + +/** + * This filter is used to filter the arguments sent to the remote server during a push. */ add_filter( 'dt_push_post_args', function( $post_body, $post ) { + // Pass the original published date to the new pushed post and set the same published date + // instead of setting it to the current time. $post_body['date'] = $post->post_date; $post_body['date_gmt'] = $post->post_date_gmt; + + $slug = newspack_network_get_primary_category_slug( $post_body, $post ); + if ( $slug ) { + $post_body['distributor_meta']['yoast_primary_category_slug'] = $slug; + } + return $post_body; }, 10, @@ -38,34 +79,19 @@ function( $post_array, $remote_id, $post ) { 10, 3 ); -/** - * ========================================= - * ===== End of Post publication date ====== - * ========================================= - */ /** - * ========================================= - * ===== Allow editors to pull content ===== - * ========================================= + * Allow editors to pull content. */ function newspack_network_filter_distributor_menu_cap() { return 'edit_others_posts'; } add_filter( 'dt_capabilities', 'newspack_network_filter_distributor_menu_cap' ); add_filter( 'dt_pull_capabilities', 'newspack_network_filter_distributor_menu_cap' ); -/** - * ========================================= - * ==== End of editors to pull content ===== - * ========================================= - */ /** - * ========================================= - * =========== Bug Workaround ============== * This is a workaround the bug fixed in https://github.com/10up/distributor/pull/1185 * Until that fix is released, we need to keep this workaround. - * ========================================= */ add_action( 'init', @@ -73,3 +99,23 @@ function() { wp_cache_delete( 'dt_media::{$post_id}', 'dt::post' ); } ); + +/** + * Send primary category slug to the Node when updating a post. + */ +add_filter( + 'dt_subscription_post_args', + function( $post_body, $post ) { + $slug = newspack_network_get_primary_category_slug( $post_body, $post ); + $post_body['post_data']['distributor_meta']['yoast_primary_category_slug'] = $slug; + return $post_body; + }, + 10, + 2 +); + +/** + * Map Hub primary category to the primary category on the Node. + */ +add_action( 'dt_process_subscription_attributes', 'newspack_network_fix_primary_category', 10, 2 ); +add_action( 'dt_process_distributor_attributes', 'newspack_network_fix_primary_category', 10, 2 ); From af03b03f5a946ecb1e8a2bb0f11fa5d748d6b56c Mon Sep 17 00:00:00 2001 From: Adam Boro Date: Tue, 6 Feb 2024 13:46:48 +0100 Subject: [PATCH 2/8] refactor(distributor): class for base/global cusomizations --- includes/class-distributor-customizations.php | 2 +- .../distributor-customizations/class-base.php | 128 ++++++++++++++++++ .../distributor-customizations/global.php | 121 ----------------- 3 files changed, 129 insertions(+), 122 deletions(-) create mode 100644 includes/distributor-customizations/class-base.php delete mode 100644 includes/distributor-customizations/global.php diff --git a/includes/class-distributor-customizations.php b/includes/class-distributor-customizations.php index 12d45f46..554a8c8c 100644 --- a/includes/class-distributor-customizations.php +++ b/includes/class-distributor-customizations.php @@ -18,7 +18,7 @@ class Distributor_Customizations { * @return void */ public static function init() { - require_once NEWSPACK_NETWORK_PLUGIN_DIR . '/includes/distributor-customizations/global.php'; + Distributor_Customizations\Base::init(); Distributor_Customizations\Canonical_Url::init(); Distributor_Customizations\Author_Distribution::init(); Distributor_Customizations\Author_Ingestion::init(); diff --git a/includes/distributor-customizations/class-base.php b/includes/distributor-customizations/class-base.php new file mode 100644 index 00000000..9214556d --- /dev/null +++ b/includes/distributor-customizations/class-base.php @@ -0,0 +1,128 @@ +ID ); + $category_id = $primary_term->get_primary_term(); + if ( $category_id ) { + $category = get_term( $category_id ); + return $category->slug; + } + } + } + + /** + * Fix primary category on the Node. + * + * @param WP_Post $post The post object. + * @param WP_REST_Request $request The request data. + */ + public static function fix_primary_category( $post, $request ) { + $primary_category_id = get_post_meta( $post->ID, '_yoast_wpseo_primary_category', true ); + $primary_category_slug = get_post_meta( $post->ID, 'yoast_primary_category_slug', true ); + $hub_primary_category = get_term( $primary_category_id ); + if ( ! $hub_primary_category ) { + // Attempt to find a matching category on the Hub site by slug. + $hub_primary_category = get_term_by( 'slug', $primary_category_slug, 'category' ); + } + if ( $hub_primary_category ) { + update_post_meta( $post->ID, '_yoast_wpseo_primary_category', $hub_primary_category->term_id ); + } elseif ( class_exists( '\Newspack\Logger' ) ) { + \Newspack\Logger::error( __( 'No matching category found on the Hub site.', 'newspack-network' ) ); + } + } + + /** + * Filter the arguments sent to the remote server during a push. + * + * @param array $post_body The post data to be sent to the Node. + * @param WP_Post $post The post object. + */ + public static function filter_push_post_args( $post_body, $post ) { + // Pass the original published date to the new pushed post and set the same published date + // instead of setting it to the current time. + $post_body['date'] = $post->post_date; + $post_body['date_gmt'] = $post->post_date_gmt; + + $slug = self::get_primary_category_slug( $post_body, $post ); + if ( $slug ) { + $post_body['distributor_meta']['yoast_primary_category_slug'] = $slug; + } + + return $post_body; + } + + /** + * Keep the publication date on the new pulled post. + * + * @param array $post_array The post data to be sent to the Node. + * @param int $remote_id The remote post ID. + * @param WP_Post $post The post object. + */ + public static function filter_pull_post_args( $post_array, $remote_id, $post ) { + $post_array['post_date'] = $post->post_date; + $post_array['post_date_gmt'] = $post->post_date_gmt; + return $post_array; + } + + /** + * Send primary category slug to the Node when updating a post. + * + * @param array $post_body The post data to be sent to the Node. + * @param WP_Post $post The post object. + */ + public static function filter_subscription_post_args( $post_body, $post ) { + $slug = self::get_primary_category_slug( $post_body, $post ); + $post_body['post_data']['distributor_meta']['yoast_primary_category_slug'] = $slug; + return $post_body; + } + + /** + * Allow editors to pull content. + */ + public static function filter_distributor_menu_cap() { + return 'edit_others_posts'; + } +} diff --git a/includes/distributor-customizations/global.php b/includes/distributor-customizations/global.php deleted file mode 100644 index 43159beb..00000000 --- a/includes/distributor-customizations/global.php +++ /dev/null @@ -1,121 +0,0 @@ -ID ); - $category_id = $primary_term->get_primary_term(); - if ( $category_id ) { - $category = get_term( $category_id ); - return $category->slug; - } - } -} - -/** - * Fix primary category on the Node. - * - * @param WP_Post $post The post object. - * @param WP_REST_Request $request The request data. - */ -function newspack_network_fix_primary_category( $post, $request ) { - $primary_category_id = get_post_meta( $post->ID, '_yoast_wpseo_primary_category', true ); - $primary_category_slug = get_post_meta( $post->ID, 'yoast_primary_category_slug', true ); - $hub_primary_category = get_term( $primary_category_id ); - if ( ! $hub_primary_category ) { - // Attempt to find a matching category on the Hub site by slug. - $hub_primary_category = get_term_by( 'slug', $primary_category_slug, 'category' ); - } - if ( $hub_primary_category ) { - update_post_meta( $post->ID, '_yoast_wpseo_primary_category', $hub_primary_category->term_id ); - } elseif ( class_exists( '\Newspack\Logger' ) ) { - \Newspack\Logger::error( __( 'No matching category found on the Hub site.', 'newspack-network' ) ); - } -} - -/** - * This filter is used to filter the arguments sent to the remote server during a push. - */ -add_filter( - 'dt_push_post_args', - function( $post_body, $post ) { - // Pass the original published date to the new pushed post and set the same published date - // instead of setting it to the current time. - $post_body['date'] = $post->post_date; - $post_body['date_gmt'] = $post->post_date_gmt; - - $slug = newspack_network_get_primary_category_slug( $post_body, $post ); - if ( $slug ) { - $post_body['distributor_meta']['yoast_primary_category_slug'] = $slug; - } - - return $post_body; - }, - 10, - 2 -); -/** - * Keep the publication date on the new pulled post. - * - * This filters the arguments passed into wp_insert_post during a pull. - */ -add_filter( - 'dt_pull_post_args', - function( $post_array, $remote_id, $post ) { - $post_array['post_date'] = $post->post_date; - $post_array['post_date_gmt'] = $post->post_date_gmt; - return $post_array; - }, - 10, - 3 -); - -/** - * Allow editors to pull content. - */ -function newspack_network_filter_distributor_menu_cap() { - return 'edit_others_posts'; -} -add_filter( 'dt_capabilities', 'newspack_network_filter_distributor_menu_cap' ); -add_filter( 'dt_pull_capabilities', 'newspack_network_filter_distributor_menu_cap' ); - -/** - * This is a workaround the bug fixed in https://github.com/10up/distributor/pull/1185 - * Until that fix is released, we need to keep this workaround. - */ -add_action( - 'init', - function() { - wp_cache_delete( 'dt_media::{$post_id}', 'dt::post' ); - } -); - -/** - * Send primary category slug to the Node when updating a post. - */ -add_filter( - 'dt_subscription_post_args', - function( $post_body, $post ) { - $slug = newspack_network_get_primary_category_slug( $post_body, $post ); - $post_body['post_data']['distributor_meta']['yoast_primary_category_slug'] = $slug; - return $post_body; - }, - 10, - 2 -); - -/** - * Map Hub primary category to the primary category on the Node. - */ -add_action( 'dt_process_subscription_attributes', 'newspack_network_fix_primary_category', 10, 2 ); -add_action( 'dt_process_distributor_attributes', 'newspack_network_fix_primary_category', 10, 2 ); From ffec10916321afa191dcdb1d5ac859a9ad57fa19 Mon Sep 17 00:00:00 2001 From: Adam Boro Date: Tue, 6 Feb 2024 14:12:12 +0100 Subject: [PATCH 3/8] feat(distributor): synchronize post status --- .../distributor-customizations/class-base.php | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/includes/distributor-customizations/class-base.php b/includes/distributor-customizations/class-base.php index 9214556d..e6f4d6e9 100644 --- a/includes/distributor-customizations/class-base.php +++ b/includes/distributor-customizations/class-base.php @@ -21,8 +21,8 @@ public static function init() { add_filter( 'dt_push_post_args', [ __CLASS__, 'filter_push_post_args' ], 10, 2 ); add_filter( 'dt_pull_post_args', [ __CLASS__, 'filter_pull_post_args' ], 10, 3 ); add_filter( 'dt_subscription_post_args', [ __CLASS__, 'filter_subscription_post_args' ], 10, 2 ); - add_action( 'dt_process_subscription_attributes', [ __CLASS__, 'fix_primary_category' ], 10, 2 ); - add_action( 'dt_process_distributor_attributes', [ __CLASS__, 'fix_primary_category' ], 10, 2 ); + add_action( 'dt_process_subscription_attributes', [ __CLASS__, 'process_attributes' ], 10, 2 ); + add_action( 'dt_process_distributor_attributes', [ __CLASS__, 'process_attributes' ], 10, 2 ); /** * This is a workaround the bug fixed in https://github.com/10up/distributor/pull/1185 @@ -54,12 +54,13 @@ private static function get_primary_category_slug( $post_body, $post ) { } /** - * Fix primary category on the Node. + * Process distributed post attributes after the distribution has completed. * * @param WP_Post $post The post object. * @param WP_REST_Request $request The request data. */ - public static function fix_primary_category( $post, $request ) { + public static function process_attributes( $post, $request ) { + // Fix the primary category. $primary_category_id = get_post_meta( $post->ID, '_yoast_wpseo_primary_category', true ); $primary_category_slug = get_post_meta( $post->ID, 'yoast_primary_category_slug', true ); $hub_primary_category = get_term( $primary_category_id ); @@ -72,6 +73,18 @@ public static function fix_primary_category( $post, $request ) { } elseif ( class_exists( '\Newspack\Logger' ) ) { \Newspack\Logger::error( __( 'No matching category found on the Hub site.', 'newspack-network' ) ); } + + // Synchronize the post status. + $hub_post_status = get_post_meta( $post->ID, 'post_status', true ); + $current_post_status = get_post_status( $post->ID ); + if ( $hub_post_status && $hub_post_status !== $current_post_status ) { + wp_update_post( + [ + 'ID' => $post->ID, + 'post_status' => $hub_post_status, + ] + ); + } } /** @@ -116,6 +129,9 @@ public static function filter_pull_post_args( $post_array, $remote_id, $post ) { public static function filter_subscription_post_args( $post_body, $post ) { $slug = self::get_primary_category_slug( $post_body, $post ); $post_body['post_data']['distributor_meta']['yoast_primary_category_slug'] = $slug; + // Attaching the post status only on updates (so not in filter_push_post_args). + // By default, only published posts are distributable, so there's no need to attach the post status on new posts. + $post_body['post_data']['distributor_meta']['post_status'] = $post->post_status; return $post_body; } From 978c4b99a838bf8b9c5a51068b4607027b7548b1 Mon Sep 17 00:00:00 2001 From: Adam Boro Date: Tue, 6 Feb 2024 14:17:03 +0100 Subject: [PATCH 4/8] chore: lint fix --- includes/distributor-customizations/class-base.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/distributor-customizations/class-base.php b/includes/distributor-customizations/class-base.php index e6f4d6e9..a5e6010d 100644 --- a/includes/distributor-customizations/class-base.php +++ b/includes/distributor-customizations/class-base.php @@ -15,8 +15,8 @@ class Base { * Initialize hooks. */ public static function init() { - add_filter( 'dt_capabilities', [ __CLASS__,'filter_distributor_menu_cap' ] ); - add_filter( 'dt_pull_capabilities', [ __CLASS__,'filter_distributor_menu_cap' ] ); + add_filter( 'dt_capabilities', [ __CLASS__, 'filter_distributor_menu_cap' ] ); + add_filter( 'dt_pull_capabilities', [ __CLASS__, 'filter_distributor_menu_cap' ] ); add_filter( 'dt_push_post_args', [ __CLASS__, 'filter_push_post_args' ], 10, 2 ); add_filter( 'dt_pull_post_args', [ __CLASS__, 'filter_pull_post_args' ], 10, 3 ); From 3a42e71b32f57157f3d49d56c877a2f759af83f6 Mon Sep 17 00:00:00 2001 From: Adam Boro Date: Fri, 9 Feb 2024 09:19:31 +0100 Subject: [PATCH 5/8] refactor: meta field name --- includes/distributor-customizations/class-base.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/distributor-customizations/class-base.php b/includes/distributor-customizations/class-base.php index 9fbcf8be..13a97ad2 100644 --- a/includes/distributor-customizations/class-base.php +++ b/includes/distributor-customizations/class-base.php @@ -93,7 +93,7 @@ public static function process_attributes( $post ) { } // Synchronize the post status. - $hub_post_status = get_post_meta( $post->ID, 'post_status', true ); + $hub_post_status = get_post_meta( $post->ID, 'newspack_network_post_status', true ); $current_post_status = get_post_status( $post->ID ); if ( $hub_post_status && $hub_post_status !== $current_post_status ) { wp_update_post( @@ -155,7 +155,7 @@ public static function filter_subscription_post_args( $post_body, $post ) { $post_body['post_data']['distributor_meta']['newspack_network_primary_cat_slug'] = $slug; // Attaching the post status only on updates (so not in filter_push_post_args). // By default, only published posts are distributable, so there's no need to attach the post status on new posts. - $post_body['post_data']['distributor_meta']['post_status'] = $post->post_status; + $post_body['post_data']['distributor_meta']['newspack_network_post_status'] = $post->post_status; return $post_body; } From a1e1595edcf88f80d27695ecb40eb6ae7a6705d5 Mon Sep 17 00:00:00 2001 From: Adam Boro Date: Fri, 9 Feb 2024 09:23:32 +0100 Subject: [PATCH 6/8] refactor: use constants for post meta names --- .../distributor-customizations/class-base.php | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/includes/distributor-customizations/class-base.php b/includes/distributor-customizations/class-base.php index 13a97ad2..f35fe127 100644 --- a/includes/distributor-customizations/class-base.php +++ b/includes/distributor-customizations/class-base.php @@ -11,6 +11,10 @@ * General Distributor customizations. */ class Base { + const YOAST_PRIMARY_CAT_META_NAME = '_yoast_wpseo_primary_category'; + const PRIMARY_CAT_SLUG_META_NAME = 'newspack_network_primary_cat_slug'; + const POST_STATUS_META_NAME = 'newspack_network_post_status'; + /** * Initialize hooks. */ @@ -47,10 +51,10 @@ private static function get_primary_category_slug( $post, $is_pulling = false ) if ( $is_pulling ) { // When pulling content, the post will be the remote site post (not on the WP instance that executes this code). // The category slug has to be read from the data on the post object. - if ( ! isset( $post->meta['_yoast_wpseo_primary_category'] ) ) { + if ( ! isset( $post->meta[ self::YOAST_PRIMARY_CAT_META_NAME ] ) ) { return; } - $primary_category_id = reset( $post->meta['_yoast_wpseo_primary_category'] ); + $primary_category_id = reset( $post->meta[ self::YOAST_PRIMARY_CAT_META_NAME ] ); if ( ! $primary_category_id ) { return; } @@ -83,17 +87,17 @@ function ( $category ) use ( $primary_category_id ) { */ public static function process_attributes( $post ) { // Fix the primary category. - $primary_category_slug = get_post_meta( $post->ID, 'newspack_network_primary_cat_slug', true ); + $primary_category_slug = get_post_meta( $post->ID, self::PRIMARY_CAT_SLUG_META_NAME, true ); // Match the category by slug, the IDs might have a clash. $found_primary_category = get_term_by( 'slug', $primary_category_slug, 'category' ); if ( $found_primary_category ) { - update_post_meta( $post->ID, '_yoast_wpseo_primary_category', $found_primary_category->term_id ); + update_post_meta( $post->ID, self::YOAST_PRIMARY_CAT_META_NAME, $found_primary_category->term_id ); } elseif ( class_exists( '\Newspack\Logger' ) ) { \Newspack\Logger::error( __( 'No matching category found on the Hub site.', 'newspack-network' ) ); } // Synchronize the post status. - $hub_post_status = get_post_meta( $post->ID, 'newspack_network_post_status', true ); + $hub_post_status = get_post_meta( $post->ID, self::POST_STATUS_META_NAME, true ); $current_post_status = get_post_status( $post->ID ); if ( $hub_post_status && $hub_post_status !== $current_post_status ) { wp_update_post( @@ -119,7 +123,7 @@ public static function filter_push_post_args( $post_body, $post ) { $slug = self::get_primary_category_slug( $post ); if ( $slug ) { - $post_body['distributor_meta']['newspack_network_primary_cat_slug'] = $slug; + $post_body['distributor_meta'][ self::PRIMARY_CAT_SLUG_META_NAME ] = $slug; } return $post_body; @@ -138,7 +142,7 @@ public static function filter_pull_post_args( $post_array, $remote_id, $post ) { $slug = self::get_primary_category_slug( $post, true ); if ( $slug ) { - $post_array['meta_input']['newspack_network_primary_cat_slug'] = $slug; + $post_array['meta_input'][ self::PRIMARY_CAT_SLUG_META_NAME ] = $slug; } return $post_array; @@ -152,10 +156,10 @@ public static function filter_pull_post_args( $post_array, $remote_id, $post ) { */ public static function filter_subscription_post_args( $post_body, $post ) { $slug = self::get_primary_category_slug( $post ); - $post_body['post_data']['distributor_meta']['newspack_network_primary_cat_slug'] = $slug; + $post_body['post_data']['distributor_meta'][ self::PRIMARY_CAT_SLUG_META_NAME ] = $slug; // Attaching the post status only on updates (so not in filter_push_post_args). // By default, only published posts are distributable, so there's no need to attach the post status on new posts. - $post_body['post_data']['distributor_meta']['newspack_network_post_status'] = $post->post_status; + $post_body['post_data']['distributor_meta'][ self::POST_STATUS_META_NAME ] = $post->post_status; return $post_body; } From e7245ff567c0314b09fee8c212ae994f5045116c Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Fri, 9 Feb 2024 17:54:00 -0300 Subject: [PATCH 7/8] fix: namespace of yoast class --- includes/distributor-customizations/class-base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/distributor-customizations/class-base.php b/includes/distributor-customizations/class-base.php index f35fe127..2cde421d 100644 --- a/includes/distributor-customizations/class-base.php +++ b/includes/distributor-customizations/class-base.php @@ -71,7 +71,7 @@ function ( $category ) use ( $primary_category_id ) { } elseif ( class_exists( 'WPSEO_Primary_Term' ) ) { // When pushing, the post will be the post on this site. // The category exists on the site which executes this code, so it can be retrieved via Yoast. - $primary_term = new WPSEO_Primary_Term( 'category', $post->ID ); + $primary_term = new \WPSEO_Primary_Term( 'category', $post->ID ); $category_id = $primary_term->get_primary_term(); if ( $category_id ) { $category = get_term( $category_id ); From 84df4ce324c808ff561e1d8d97aad3e04f748a98 Mon Sep 17 00:00:00 2001 From: Adam Boro Date: Mon, 12 Feb 2024 20:39:00 +0100 Subject: [PATCH 8/8] feat: only handle publish and trash statuses --- includes/distributor-customizations/class-base.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/distributor-customizations/class-base.php b/includes/distributor-customizations/class-base.php index 2cde421d..95203d40 100644 --- a/includes/distributor-customizations/class-base.php +++ b/includes/distributor-customizations/class-base.php @@ -159,7 +159,10 @@ public static function filter_subscription_post_args( $post_body, $post ) { $post_body['post_data']['distributor_meta'][ self::PRIMARY_CAT_SLUG_META_NAME ] = $slug; // Attaching the post status only on updates (so not in filter_push_post_args). // By default, only published posts are distributable, so there's no need to attach the post status on new posts. - $post_body['post_data']['distributor_meta'][ self::POST_STATUS_META_NAME ] = $post->post_status; + $distributable_statuses = [ 'publish', 'trash' ]; + if ( in_array( $post->post_status, $distributable_statuses, true ) ) { + $post_body['post_data']['distributor_meta'][ self::POST_STATUS_META_NAME ] = $post->post_status; + } return $post_body; }