WordPress Filter for Pingbacks

My team and I have been working on a plugin to enable a better UI for post formats in the WordPress admin (more on this later, but feel free to grab the code and play with it). One of the things we’ve done is standardize on some custom field names for various bits of data that are needed to support the different post formats. For link posts, we’re storing the link URL in a post meta field so that we can output it instead of the default post permalink in various spots in the theme and feeds.

This works great, but we discovered that moving the URL out of the post body :air: breaks :/air: another feature: pingbacks.

Pingbacks currently work in a very specific way. The post content is parsed for external URLs, then a ping is sent for each of these URLs letting them know they were referenced. Unfortunately, in the current version of WordPress there was no way to get any additional URLs into this list (and we aren’t storing the URL in the post content where it would be found automatically).

I created a very small patch to add a filter into the pingback process. With this, I’m able to add a few lines of code that takes the URL from the custom field and add it to the list of URLs that need to be pinged.


<?php
function pingback_format_link_url($post_links, $post_id) {
$url = get_post_meta($post_id, '_format_link_url', true);
if (!empty($url) && !in_array($url, $post_links)) {
$post_links[] = $url;
}
return $post_links;
}
add_filter('pre_ping_post_links', 'pingback_format_link_url', 10, 2);

I’m adamantly against making changes to WordPress core code in almost all circumstances, but the exception is patches that look like they’re on track for inclusion in the next release. Early indications for this one appear positive (thanks Nacin!). If you need this feature before it makes it into core, you can grab the patch. I’m running it here so that my link posts send pings as I feel is appropriate.