From 41f099461e12cae2349a961ce4e52440e469ba1c Mon Sep 17 00:00:00 2001 From: Juanma Rodriguez Escriche Date: Thu, 10 Oct 2024 16:43:46 +0200 Subject: [PATCH] Added null check post status obj in sal site class (#39727) * Add null check for post_status_obj to avoid PHP Warnings * changelog * Ensure we only assign get_post_status_object to the parent status in case the parent exists --- .../update-added-null-check-post-status-obj-in-sal-site-class | 4 ++++ projects/plugins/jetpack/sal/class.json-api-site-base.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/update-added-null-check-post-status-obj-in-sal-site-class diff --git a/projects/plugins/jetpack/changelog/update-added-null-check-post-status-obj-in-sal-site-class b/projects/plugins/jetpack/changelog/update-added-null-check-post-status-obj-in-sal-site-class new file mode 100644 index 0000000000000..84cfd9c0cd835 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-added-null-check-post-status-obj-in-sal-site-class @@ -0,0 +1,4 @@ +Significance: minor +Type: other + +SAL_Site class: Added null check to posts_status_obj to avoid Warnings diff --git a/projects/plugins/jetpack/sal/class.json-api-site-base.php b/projects/plugins/jetpack/sal/class.json-api-site-base.php index 8109037452d83..ea2342955e33f 100644 --- a/projects/plugins/jetpack/sal/class.json-api-site-base.php +++ b/projects/plugins/jetpack/sal/class.json-api-site-base.php @@ -758,8 +758,8 @@ private function user_can_view_post( $post ) { if ( ! $post || is_wp_error( $post ) ) { return false; } - - if ( 'inherit' === $post->post_status ) { + // If the post is of status inherit, check if the parent exists ( different to 0 ) to check for the parent status object. + if ( 'inherit' === $post->post_status && 0 !== (int) $post->post_parent ) { $parent_post = get_post( $post->post_parent ); $post_status_obj = get_post_status_object( $parent_post->post_status ); } else {