Forums

[SOLVED] Show comment meta in iOS app

  1. I do use the "city" and "state" custom fields in the comment form of my site. But I didn't know (until today) how to show these extra fields in the iOS app when moderating comments. I need to check this fields contents before approving a comment.

    I've found the answer and I want to share.

    There's an (undocumented, AFAIK) WP filter called xmlrpc_prepare_comment, which is called in the server right before sending the comment data as requested by the iPhone app.

    Using this filter in functions.php, I could insert the comment meta right after the comment contents:

    add_filter('xmlrpc_prepare_comment', 'ios_comment_meta');
    
    function ios_comment_meta($comment_array) {
    
      $city  = get_comment_meta($comment_array['comment_id'], 'city', true);
      $state = get_comment_meta($comment_array['comment_id'], 'state', true);
    
      $comment_array['content'] .= "\n\nCity: $city - $state";
    
      return $comment_array;
    }

    See function _prepare_comment() in file wp-includes/class-wp-xmlrpc-server.php for more info about the $comment_array.

Leave a Reply

You must log in to post.


About this Topic