I run a fan site, and so does a friend of mine. Liv and I were chatting about wishlists in WordPress for fansites, and she mentioned this:
I also like seeing who has linked to my site from other WP blogs because that helps me create fandom connections with other bloggers. I wish there was a quick button I could hit that would allow me to email those bloggers with a quick note of thanks for the connection
When you’re running a fan website, communicating and connecting with those other sites is a killer feature. We network and that’s how we make our communities bloom, after all, since most of us can’t afford a budget for ‘real’ advertising, and it’s probably not entirely legal for us to do that anyway. So outside of spending days tracking everyone down, what about using the power of ping-backs for ourselves?
I’m sure Liv has an unshakable confidence in my ability to code her things (and I love the requests she makes, they stretch my brain) but this one kicked my patootie a lot. Getting a list of pingbacks isn’t all that hard. There’s a plugin called Commenter Emails by Scott, which nicely lists all the email addresses used to make comments. Using that logic, it’s pretty easy to list all the pingbacks. I mean, hey, we can already do that!
If you go to /wp-admin/edit-comments.php?s&comment_status=all&comment_type=pings
you’ll see all your pings:
Just looking at that, however, made me notice a horrible problem. There are no emails listed in pingbacks. This makes perfect sense. The emails aren’t (generally) listed on a page that links to your site. That means without doing some serious site-scraping, there’s no way to get that email.
Putting that aside, the other option is to, perhaps, list the ‘parent’ domain that pinged you. So I went back to Scott’s plugin and forked it into this:
<?php /* Plugin Name: Pingers List License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Description: List all pingbacks with links to their main domain. Quasi fork of http://wordpress.org/plugins/commenter-pings/ Copyright (c) 2007-2014 by Scott Reilly (aka coffee2code) Copyright (c) 2014 by Mika Epstein (aka ipstenu) */ defined( 'ABSPATH' ) or die(); if ( is_admin() && ! class_exists( 'PingersList' ) ) : class PingersList { private static $plugin_basename = ''; private static $plugin_page = ''; /** * Returns version of the plugin. * * @since 2.1 */ public static function version() { return '2.2.1'; } /** * Constructor */ public static function init() { self::$plugin_basename = plugin_basename( __FILE__ ); // Register hooks add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ) ); add_action( 'admin_menu', array( __CLASS__, 'do_init' ), 11 ); } /** * Initialize hooks and data */ public static function do_init() { // Currently empty } /** * Query database to obtain the list of commenter email addresses. * Only checks comments that are approved, have a author email, and are * of the comment_type 'comment' (or ''). * * Only one entry is returned per email address. If a given email address * has multiple instances in the database, each with different names, then * the most recent comment will be used to obtain any additional field data * such as comment_author, etc. * * @param array $fields The fields to obtain from each comment * @param string $output (optional) Any of ARRAY_A | ARRAY_N | OBJECT | OBJECT_K constants. See WP docs for wpdb::get_results() for more info * @return mixed List of email addresses */ public static function get_pings( $fields = array( 'comment_post_ID', 'comment_author', 'comment_author_url' ), $output = ARRAY_N ) { global $wpdb; // comment_author_url must be one of the fields if ( ! in_array( 'comment_author_url', $fields ) ) array_unshift( $fields, 'comment_author_url' ); $fields = implode( ', ', $fields ); $sql = "SELECT $fields FROM {$wpdb->comments} t1 INNER JOIN ( SELECT MAX(comment_ID) AS id FROM {$wpdb->comments} GROUP BY comment_author_url ) t2 ON t1.comment_ID = t2.id WHERE comment_approved = '1' AND comment_type = 'pingback' GROUP BY comment_author_url ORDER BY comment_author_url ASC"; $pings = $wpdb->get_results( $sql, $output ); return $pings; } /** * Creates the admin menu. * * @return void */ public static function admin_menu() { add_filter( 'plugin_action_links_' . self::$plugin_basename, array( __CLASS__, 'plugin_action_links' ) ); // Add menu under Comments self::$plugin_page = add_comments_page( __( 'Pinger List', 'pinger-list' ), __( 'Pinger List', 'pinger-list' ), apply_filters( 'manage_commenter_pings_options', 'manage_options' ), self::$plugin_basename, array( __CLASS__, 'admin_page' ) ); } /** * Adds a 'Settings' link to the plugin action links. * * @param array $action_links The current action links * @return array The action links */ public static function plugin_action_links( $action_links ) { $settings_link = '<a href="edit-comments.php?page=' . self::$plugin_basename.'" title="">' . __( 'Listing', 'pinger-list' ) . '</a>'; array_unshift( $action_links, $settings_link ); return $action_links; } /** * Outputs the contents of the plugin's admin page. * * @return void */ public static function admin_page() { $pings = self::get_pings(); $pings_count = count( $pings ); echo '<div class="wrap">'; echo '<h2>' . __( 'Ping List', 'pinger-list' ) . '</h2>'; echo '<p>' . sprintf( __( 'There are %s unique ping locations for this site.', 'pinger-list' ), $pings_count ) . '</p>'; echo '</div>'; echo '<div class="wrap">'; echo '<h2>' . __( 'All Pings', 'pinger-list' ) . '</h2>'; echo '<table padding=2>'; echo '<tr><th>' . __( 'Post', 'pinger-list' ) . '</th><th>' . __( 'Source', 'pinger-list' ) . '</th><th>' . __( 'Direct Link', 'pinger-list' ) . '</th></tr>'; foreach ( $pings as $item ) { $pings_url = parse_url(esc_html( $item[2] )); $ping_url = $pings_url[scheme].'://'. $pings_url[host]; echo '<tr width="20%"><td><a href="' . get_permalink( $item[0] ) . '">'. get_the_title($item[0]) .'</a></td>'; echo '<td width="20%">' . make_clickable($ping_url).'</td>'; echo '<td><a href="'.esc_html( $item[2] ).'">'. esc_html( $item[1] ) . '</a></td></tr>'; } echo '</table>'; echo '<p>' . sprintf( __( '%s pings listed.', 'pinger-list' ), $pings_count ) . '</p>'; echo '</div>'; } } // end PingersList PingersList::init(); endif; // end if ! class_exists()
The plugin’s crazy basic. It simply checks for unique ping sources and lists them. So if the same ‘main’ site links to you 10 times from 10 separate posts, it lists that. Probably a nice tweak would be to order them by domain, list the posts they link to and from where, and have a group by sort of list, but I didn’t get that far into it. Forks welcome, as are full blown plugins!