From dc6e89911495b9e5f38b27a92b8d0a58982eef75 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Thu, 6 Feb 2025 16:49:53 +0300 Subject: [PATCH 1/4] Added a safeguard for the post object in Sharing. --- .../plugins/jetpack/modules/sharedaddy/sharing-service.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php b/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php index db9a37dac1216..ac693dd843f08 100644 --- a/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php +++ b/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php @@ -1046,6 +1046,11 @@ function_exists( '\Activitypub\is_activitypub_request' ) */ $show = apply_filters( 'sharing_show', $show, $post ); + // We require the post to remain an object after all filters. If it's not - we just return. + if ( ! is_object( $post ) || ! isset( $post->ID ) ) { + return $text; + } + // Disabled for this post? $switched_status = get_post_meta( $post->ID, 'sharing_disabled', false ); From f615e24a7ee6f1bf74ed5605e045ebe2793a3d47 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Thu, 6 Feb 2025 16:59:43 +0300 Subject: [PATCH 2/4] changelog --- projects/plugins/jetpack/changelog/add-sharing-safeguard-post | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/add-sharing-safeguard-post diff --git a/projects/plugins/jetpack/changelog/add-sharing-safeguard-post b/projects/plugins/jetpack/changelog/add-sharing-safeguard-post new file mode 100644 index 0000000000000..c8ba163b65325 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-sharing-safeguard-post @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +Sharing: Fix possible warnings related to plugin compatibility. From 1e13890ef7cd5d782e4c6d4a4186b9745ae3f5a2 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Fri, 7 Feb 2025 15:04:50 +0300 Subject: [PATCH 3/4] Moved the check upwards and changed it to instance detection, h/t @jeherve. --- .../jetpack/modules/sharedaddy/sharing-service.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php b/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php index ac693dd843f08..b188810580110 100644 --- a/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php +++ b/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php @@ -960,6 +960,11 @@ function sharing_display( $text = '', $echo = false ) { return $text; } + // We require the post to not be empty and be an actual WordPress post object. If it's not - we just return. + if ( empty( $post ) || ! $post instanceof \WP_Post ) { + return $text; + } + if ( empty( $post ) ) { return $text; } @@ -1046,11 +1051,6 @@ function_exists( '\Activitypub\is_activitypub_request' ) */ $show = apply_filters( 'sharing_show', $show, $post ); - // We require the post to remain an object after all filters. If it's not - we just return. - if ( ! is_object( $post ) || ! isset( $post->ID ) ) { - return $text; - } - // Disabled for this post? $switched_status = get_post_meta( $post->ID, 'sharing_disabled', false ); From 1262c0639efdca1f6ac60100f05f3f905a97c2ff Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Fri, 7 Feb 2025 15:27:23 +0300 Subject: [PATCH 4/4] Removed accidental duplication. --- .../plugins/jetpack/modules/sharedaddy/sharing-service.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php b/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php index b188810580110..d726ec387adc3 100644 --- a/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php +++ b/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php @@ -965,10 +965,6 @@ function sharing_display( $text = '', $echo = false ) { return $text; } - if ( empty( $post ) ) { - return $text; - } - if ( ( is_preview() || is_admin() ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { return $text; }