Skip to content

Commit

Permalink
add yoast seo compat for images
Browse files Browse the repository at this point in the history
  • Loading branch information
asadowski10 committed Aug 22, 2023
1 parent bf841ae commit a8307b3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ If you really like what we do or want to thank us for our quick work, feel free

## Changelog

### 3.12.0

* Added : Add compatibility with Yoast SEO meta images.

### 3.11.0

* Fixed : Delete content one uncheck manual admin metabox
Expand Down
6 changes: 4 additions & 2 deletions bea-content-sync-fusion.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: BEA - Content Sync Fusion
Plugin URI: https://beapi.fr
Description: Manage content synchronization across a WordPress multisite.
Version: 3.11.0
Version: 3.12.0
Author: Be API
Author URI: http://beapi.fr
Network: true
Expand All @@ -14,7 +14,7 @@

// Plugin constants

define( 'BEA_CSF_VERSION', '3.11.0' );
define( 'BEA_CSF_VERSION', '3.12.0' );
define( 'BEA_CSF_DB_VERSION', '1649671234' );
define( 'BEA_CSF_OPTION', 'bea-content-sync-fusion' );
define( 'BEA_CSF_CRON_QTY', 500 );
Expand Down Expand Up @@ -76,6 +76,7 @@
require BEA_CSF_DIR . 'classes/addons/multisite-clone-duplicator.php';
require BEA_CSF_DIR . 'classes/addons/woocommerce.php';
require BEA_CSF_DIR . 'classes/addons/gutenberg.php';
require BEA_CSF_DIR . 'classes/addons/yoast-seo.php';

// Functions various
require BEA_CSF_DIR . 'functions/api.php';
Expand Down Expand Up @@ -146,6 +147,7 @@ function init_bea_content_sync_fusion() {
new BEA_CSF_Addon_WooCommerce();
new BEA_CSF_Addon_Polylang();
new BEA_CSF_Addon_Gutenberg();
new BEA_CSF_Addon_Yoast_Seo();

// Admin
if ( is_admin() ) {
Expand Down
40 changes: 40 additions & 0 deletions classes/addons/yoast-seo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

class BEA_CSF_Addon_Yoast_Seo {
/**
* BEA_CSF_Addon_Yoast_Seo constructor.
*/
public function __construct() {
if ( ! defined( 'WPSEO_FILE' ) ) {
return;
}

add_filter( 'bea_csf.client.posttype.merge', [ $this, 'bea_set_yoast_seo_meta' ], 20, 3 );
}

/**
* Update image meta for synchronised sites on yoast custom table
*
* @param $data
* @param $sync_fields
* @param $receiver_post
*
* @return mixed
* @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 );
}

$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 );
}

return $data;
}

}

0 comments on commit a8307b3

Please sign in to comment.