Skip to content

Add comment type support to comments connector#558

Merged
frankiejarrett merged 2 commits intodevelopfrom
comment-type
Jun 4, 2014
Merged

Add comment type support to comments connector#558
frankiejarrett merged 2 commits intodevelopfrom
comment-type

Conversation

@lukecarbis
Copy link
Contributor

This allows other comment types like:

  • pingbacks
  • trackbacks
  • any new comment types added by a theme or plugin

... to be accurately logged by Stream.

@frankiejarrett
Copy link
Contributor

@lukecarbis I'm not sure we should be using get_comment_type() alone, because that just gets the comment type slug (much like a post type slug) and not the comment type label which is a translatable string.

cf. https://github.com/WordPress/WordPress/blob/master/wp-includes/comment-template.php#L875-L877

Perhaps adding some new methods here is the answer, similar to what we do for attachment types in Media.

/**
 * Return translated comment type labels
 *
 * @return array Comment type label translations
 */
public static function get_comment_type_labels() {
    return array(
        'comment'   => __( 'Comment', 'default' ),
        'trackback' => __( 'Trackback', 'default' ),
        'pingback'  => __( 'Pingback', 'default' ),
    );
}

/**
 * Return the comment type label for a given comment ID
 *
 * @param  int    $comment_id  ID of the comment
 * @return string              The comment type label
 */
public static function get_comment_type_label( $comment_id ) {
    $comment_type = get_comment_type( $comment_id );

    if ( empty( $comment_type ) ) {
        $comment_type = 'comment';
    }

    $comment_type_labels = self::get_comment_type_labels();

    $label = isset( $comment_type_labels[ $comment_type ] ) ? $comment_type_labels[ $comment_type ] : $comment_type;

    return $label;
}

Then in the callbacks do:

$comment_type = mb_strtolower( self::get_comment_type_label( $comment_id ) );

@lukecarbis
Copy link
Contributor Author

/five thanks @fjarrett, great suggestion. WordPress core should have a better way of handling this.

See Trac #4916 and Trac #12668.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukecarbis Nice idea.

@frankiejarrett
Copy link
Contributor

This is working great. Nicely done, @lukecarbis! /five

frankiejarrett added a commit that referenced this pull request Jun 4, 2014
Add comment type support to comments connector
@frankiejarrett frankiejarrett merged commit 515d270 into develop Jun 4, 2014
@frankiejarrett frankiejarrett deleted the comment-type branch June 4, 2014 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants