Skip to content

Commit

Permalink
Merge pull request #162 from BeAPI/issue/76888
Browse files Browse the repository at this point in the history
Ensures variables are not empty arrays before use
  • Loading branch information
tyffany-robbes authored Nov 29, 2024
2 parents 507933e + d50f1ea commit 10d84ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
23 changes: 12 additions & 11 deletions classes/addons/gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,18 @@ private function translate_block_attributes( array $attributes, string $block_na
break;
case 'core/gallery':
$image_ids = [];
foreach ( $attributes['ids'] as $image_id ) {
$local_id = BEA_CSF_Relations::get_object_for_any(
'attachment',
$emitter_blog_id,
$receiver_blog_id,
$image_id,
$image_id
);

if ( ! empty( $local_id ) ) {
$image_ids[] = $local_id;
if ( ! empty( $attributes['ids'] ) ) {
foreach ( $attributes['ids'] as $image_id ) {
$local_id = BEA_CSF_Relations::get_object_for_any(
'attachment',
$emitter_blog_id,
$receiver_blog_id,
$image_id,
$image_id
);
if ( ! empty( $local_id ) ) {
$image_ids[] = $local_id;
}
}
}
$attributes['ids'] = $image_ids;
Expand Down
20 changes: 12 additions & 8 deletions classes/addons/yoast-seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,22 @@ 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 ( is_array( $fb_image_meta ) ) {
$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 ( is_array( $twitter_image_meta ) ) {
$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;
}

}

0 comments on commit 10d84ec

Please sign in to comment.