Improving the webmentions directory
When creating my webmentions author directory I originally wanted to avoid any reliance on the #indieweb Semantic Linkbacks plugin, as not everyone will be using it, and I wanted to keep things fairly self-contained.
It also meant that if you are not using webmentions you could just remove that argument from the initial query and just use the template for any comments.
Unfortunately, WordPress doesn't provide proper support for comment types as it does post types.
So, when a webmention reply is received (as opposed to likes or RSVPs etc.) WordPress the plugin converts it to a normal comment, removing its 'comment_type' value. This means it doesn't get caught if filtering for only webmentions. (Thanks to Michael for the full lowdown.)
In order to catch these replies I am forced to add a check against the 'semantic_linkbacks_type'
for each comment to see if it is actually a reply.
$wmreply = get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_type', true );
then check if
$wmreply == 'reply'
The original query included 'type' => 'webmention'
but this, obviously, had to be removed so that the linkbacks check could be performed against all comments.
Combining the two type checks gives the desired result but, for my purposes, there is a caveat.
I wanted the directory to list those engaging via directly from their own sites but the above also lists replies send from Micro.blog as the service supports webmentions. I have, therefore, added it to the list of exceptions not to return authors for - I had already excluded my own domains and blank urls.
The current (sanitised) version of the directory page template is available on GitHub.
Lightbulb moment
After making these changes I realised there should actually be an easier way, or a more streamlined one at least.
What if when a comment is received we immediately perform the linkbacks type check and, if true, rewrite the comment_type value back to the comments table in the database?
But that's a project for another time.
After getting the directory page to display all replies, I thought:
How to do this? WordPress has a ‘comment_post’ hook and actions added to this fire immediately after a comment is posted. So, I just needed to hook in a function which checks comments as soon as they are posted and, if they are webmention replies, update their comment_type field in the database. The below seems to work using the same linkbacks type check and then
$wpdb->update
to write back to the database:function wm_comment_type( $comment_ID ) {
$wmreply = get_comment_meta( $comment_ID, 'semantic_linkbacks_type', true ); global $wpdb;
if ( $wmreply == 'reply' ) {
$result = $wpdb->update( $wpdb->comments,
array( 'comment_type' => 'webmention' ),
array( 'comment_ID' => $comment_ID ),
array( '%s' ) );
} }
add_action( 'comment_post', 'wm_comment_type', 100, 1 );
Share this:
Twitter Facebook
<a href="https://colinwalker.blog/2017/05/20/20052017-1632/">→ May 20th, 2017</a>
Thanks Richard, this reminds me that I've been meaning to delve back into some of the blogroll functionality hiding within my WordPress install. It's not as updated as it should be, but you can find mine at http://boffosocko.com/wp-links-opml.php including a few subcategories of Indieweb (or related) folks, as well as an "open education" list which consists of people who are aware of or actively practicing Indieweb principles in the education space. You're also sure to find a handful of interesting tidbits at http://indieweb.org/blogroll. It may take some more manual labor, but you might find it useful to scrape for indieweb sites in one of these three locations (in decreasing order): http://indieweb.org/IRC_People, http://indieweb.org/Special:ActiveUsers, or http://indieweb.org/wiki/index.php?title=Special%3AListUsers&username=&group=&creationSort=1&limit=50. If you're looking for a relatively full-featured RSS reader for WordPress, I highly recommend the PressForward [http://pressforward.org/] plugin. It doesn't have some of the niceties I mentioned in Feed Reader Revolution [http://altplatform.org/2017/06/09/feed-reader-revolution/], but it's a pretty good start for the integration piece, and it's open. I'd written some thoughts about it here: http://boffosocko.com/2016/12/31/pressforward-as-an-indieweb-wordpress-based-rss-feed-reader-pocketinstapaper-replacement/ I don't think he'd linked to it, but Colin Walker has a "beta" webmention plugin he built for his functionality which is on Github: https://github.com/colin-walker/webmention-directory