Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/531d18a646e608094ecf5bcec3c0962f to your computer and use it in GitHub Desktop.
Save wpmudev-sls/531d18a646e608094ecf5bcec3c0962f to your computer and use it in GitHub Desktop.
[SmartCrawl Pro] - Fix broken Yoast imported featured images
<?php
/**
* Plugin Name: [SmartCrawl Pro] - Fix broken Yoast imported featured images
* Plugin URI: https://premium.wpmudev.org/
* Description: Fix broken featured images when migrating from Yoast (as of 2.6.1)
* Author: Alessandro Kaounas @ WPMUDEV
* Author URI: https://premium.wpmudev.org/
* Task: 0/1135022585412927/1166540338383954
* License: GPLv2 or later
*/
add_action( "added_post_meta", function( $mid, $object_id, $meta_key, $_meta_value ){
if( ! in_array( $meta_key, array( '_wds_opengraph', '_wds_twitter' ) ) || ! wp_doing_ajax() || ! is_admin() ){
return;
}
if( is_array( $_meta_value['images'] ) ){
foreach( $_meta_value['images'] as $index => $image ){
if( ! $image ){
unset( $_meta_value['images'][$index] );
}
}
}
update_post_meta( $object_id, $meta_key, $_meta_value );
}, 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment