Can you make the blacklist hookable so other plugins can maximize compatibility
-
In the plugin, you use the following function to stop it from duplicating certain meta fields that are in a blacklist. Our plugin stores social share counts in meta fields as a means of caching them to reduce how often we need to make the share count API requests. As such, it would be great to be able to hook directly into your plugin and add our fields to the blacklist because many of our mutual users are asking that these fields not be duplicated.
function duplicate_post_copy_post_meta_info($new_id, $post) {
$post_meta_keys = get_post_custom_keys($post->ID);
if (empty($post_meta_keys)) return;
$meta_blacklist = explode(“,”,get_option(‘duplicate_post_blacklist’));
if ($meta_blacklist == “”) $meta_blacklist = array();
$meta_blacklist = array_map(‘trim’, $meta_blacklist);
$meta_blacklist[] = ‘_wpas_done_all’; //Jetpack Publicize
$meta_blacklist[] = ‘_wpas_done_’; //Jetpack Publicize
$meta_blacklist[] = ‘_wpas_mess’; //Jetpack Publicize
$meta_blacklist[] = ‘_edit_lock’; // edit lock
$meta_blacklist[] = ‘_edit_last’; // edit lock
$meta_keys = array_diff($post_meta_keys, $meta_blacklist);foreach ($meta_keys as $meta_key) {
$meta_values = get_post_custom_values($meta_key, $post->ID);
foreach ($meta_values as $meta_value) {
$meta_value = maybe_unserialize($meta_value);
add_post_meta($new_id, $meta_key, $meta_value);
}
}
}If you add a custom filter hook in there, then any plugin in the world could access it easily and stop our fields from being duplicated. Could you just add something like this in there right before the array_diff() function?
$meta_blacklist = apply_filters( ‘duplicate_post_blacklist_filter’ , $meta_blacklist );
And of course, if nobody is hooking into it, it won’t modify your blacklist array in any way. But with this in place, then I could add something like this to my own plugin:
add_filter( ‘duplicate_post_blacklist_filter’ , ‘swp_our_duplicate_blacklist_items’ );
function swp_our_duplicate_blacklist_items( $meta_blacklist ) {
$meta_blacklist[] = ‘_our_first_field’;
$meta_blacklist[] = ‘_our_second_field’;
return $meta_blacklist;
}What do you think?
- The topic ‘Can you make the blacklist hookable so other plugins can maximize compatibility’ is closed to new replies.