Created
July 25, 2013 04:58
-
-
Save WerdsWords/6077012 to your computer and use it in GitHub Desktop.
#19: delete_{$meta_type}_metadata
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 | |
/** | |
* Keep posts' featured images | |
* | |
* @see delete_metadata() | |
* | |
* @param bool $bool Default is null, anything else short-circuits delete_metadata(). | |
* @param int $object_id The post, user, or comment object id. | |
* @param string $meta_key The meta key to delete. | |
* @param string $meta_value The meta value to delete. | |
* @param bool $delete_all Whether to delete all regardless of $object_id in delete_metadata(). Default is false. | |
* | |
* @return bool|null Null to continue, true for success, false for failure. | |
*/ | |
function wpdocs_keep_featured_images( $bool, $object_id, $meta_key, $meta_value, $delete_all ) { | |
// If user isn't an admin and is trying to remove the featured image key | |
if ( ! current_user_can( 'manage_options' ) && '_thumbnail_id' == $meta_key ) | |
return false; | |
return null; | |
} | |
add_filter( 'delete_post_metadata', 'wpdocs_keep_featured_images', 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment