Created
March 19, 2020 16:06
-
-
Save wpmudev-sls/531d18a646e608094ecf5bcec3c0962f to your computer and use it in GitHub Desktop.
[SmartCrawl Pro] - Fix broken Yoast imported featured images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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