From 95f6ff7a411f3c258946d2f7ee2ff558a196afb0 Mon Sep 17 00:00:00 2001 From: tyffany-robbes Date: Fri, 22 Nov 2024 10:12:56 +0100 Subject: [PATCH] 76888 - fix error 11 'Warning: Trying to access array offset on value of type null' --- classes/addons/yoast-seo.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/classes/addons/yoast-seo.php b/classes/addons/yoast-seo.php index bb64db8..0705031 100644 --- a/classes/addons/yoast-seo.php +++ b/classes/addons/yoast-seo.php @@ -23,18 +23,24 @@ public function __construct() { * @author Alexandre Sadowski */ public function bea_set_yoast_seo_meta( array $data, $sync_fields, WP_Post $new_post ) { - - $fb_seo_id = (int) BEA_CSF_Relations::get_object_for_any( 'attachment', $data['blogid'], $sync_fields['_current_receiver_blog_id'], $data['meta_data']['_yoast_wpseo_opengraph-image-id'][0], $data['meta_data']['_yoast_wpseo_opengraph-image-id'][0] ); - if ( ! empty( $fb_seo_id ) && (int) $fb_seo_id > 0 ) { - update_post_meta( $new_post->ID, '_yoast_wpseo_opengraph-image-id', (string)$fb_seo_id ); + $fb_image_meta = isset($data['meta_data']['_yoast_wpseo_opengraph-image-id']) ? $data['meta_data']['_yoast_wpseo_opengraph-image-id'] : null; + if ( ! empty( $fb_image_meta ) && isset( $fb_image_meta[0] ) ) { + $fb_seo_id = (int) BEA_CSF_Relations::get_object_for_any( 'attachment', $data['blogid'], $sync_fields['_current_receiver_blog_id'], $fb_image_meta[0], $fb_image_meta[0] ); + + if ( ! empty( $fb_seo_id ) && (int) $fb_seo_id > 0 ) { + update_post_meta( $new_post->ID, '_yoast_wpseo_opengraph-image-id', (string) $fb_seo_id ); + } } - $twitter_seo_id = (int) BEA_CSF_Relations::get_object_for_any( 'attachment', $data['blogid'], $sync_fields['_current_receiver_blog_id'], $data['meta_data']['_yoast_wpseo_twitter-image-id'][0], $data['meta_data']['_yoast_wpseo_twitter-image-id'][0] ); - if ( ! empty( $twitter_seo_id ) && (int) $twitter_seo_id > 0 ) { - update_post_meta( $new_post->ID, '_yoast_wpseo_twitter-image-id', (string)$twitter_seo_id ); + $twitter_image_meta = isset($data['meta_data']['_yoast_wpseo_twitter-image-id']) ? $data['meta_data']['_yoast_wpseo_twitter-image-id'] : null; + if ( ! empty( $twitter_image_meta ) && isset( $twitter_image_meta[0] ) ) { + $twitter_seo_id = (int) BEA_CSF_Relations::get_object_for_any( 'attachment', $data['blogid'], $sync_fields['_current_receiver_blog_id'], $twitter_image_meta[0], $twitter_image_meta[0] ); + + if ( ! empty( $twitter_seo_id ) && (int) $twitter_seo_id > 0 ) { + update_post_meta( $new_post->ID, '_yoast_wpseo_twitter-image-id', (string) $twitter_seo_id ); + } } return $data; } - }