Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comment type support to comments connector #558

Merged
merged 2 commits into from Jun 4, 2014
Merged

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.

@fjarrett
Copy link
Contributor

fjarrett commented Jun 3, 2014

@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.

*/
public static function get_comment_type_labels() {
return apply_filters(
'wp_stream_comment_type_labels',
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.

@fjarrett
Copy link
Contributor

fjarrett commented Jun 4, 2014

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

fjarrett added a commit that referenced this pull request Jun 4, 2014
Add comment type support to comments connector
@fjarrett fjarrett merged commit 515d270 into develop Jun 4, 2014
@fjarrett fjarrett 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.

None yet

2 participants