20/5/20174

#

Looks like I have finally worked out how to re-add the webmention 'comment_type' to replies meaning I won't have to edit them in the WordPress database. Just need some more testing to be sure.

Status
#

After getting the directory page to display all replies, I thought:

"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?"

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 );
Status