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

Conversation

Projects
None yet
2 participants
@lukecarbis
Copy link
Contributor

commented Jun 3, 2014

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor Author

commented Jun 4, 2014

/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',

This comment has been minimized.

Copy link
@fjarrett

fjarrett Jun 4, 2014

Contributor

@lukecarbis Nice idea.

@fjarrett

This comment has been minimized.

Copy link
Contributor

commented Jun 4, 2014

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

fjarrett added a commit that referenced this pull request Jun 4, 2014

Merge pull request #558 from x-team/comment-type
Add comment type support to comments connector

@fjarrett fjarrett merged commit 515d270 into develop Jun 4, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details

@fjarrett fjarrett deleted the comment-type branch Jun 4, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.