Primary

API

Decent Comments provides a convenient function that you can use to render comments in PHP templates. It also provides several actions and filters which are outlined below.

Rendering Comments in PHP Templates

Use this function to render comments in PHP templates:

Decent_Comments_Renderer::get_comments( $options = array() )

Example 1

Render comments using default options:

echo Decent_Comments_Renderer::get_comments();

Example 2

Render comments showing up to the 10 first words without displaying an avatar:

echo Decent_Comments_Renderer::get_comments(
    array(
        'max_excerpt_words' => 10,
        'show_avatar' => false
    )
);

Parameters

$options is an array that supports the following parameters, defaults are shown for each:

ellipsis
Default : “…”

excerpt
Default : true

max_excerpt_words
Default : 20

strip_tags
Default : true

avatar_size
Default : 24

number
Default : 5

order
Default : “DESC”
Possible values: “ASC”, “DESC”

orderby
Default : “comment_date_gmt”
Possible values:
“comment_author_email” : Author Email
“comment_author_url” : Author URL
“comment_content” : Content
“comment_date_gmt” : Date
“comment_karma” : Karma
“comment_post_ID” : Post

show_author
Default : true

show_avatar
Default : true

show_link
Default : true

show_comment
Default : true

Actions

The Decent Comments plugin invokes the following action hooks.

pre_get_comments

This action is invoked before comments are retrieved. See also pre_get_comments.

The action provides one parameter, a Decent_Comment object similar to the WP_Comment_Query object.

Filters

The Decent Comments plugin provides and invokes the following filter hooks.

comments_clauses

This filter allows to alter the comment query clauses. See also comments_clauses.

The parameters passed are:

  • $pieces (array) A compacted array of comment query clauses.
  • $decent_comment (Decent_Comment) A Decent_Comment object similar to the WP_Comment_Query object.

Return

  • (array) A compacted array of comment query clauses.

the_comments

This hook is used to filter the comment query results. See also the_comments.

The filter receives the following parameters:

  • $comments (array) An array of comments.
  • $decent_comment (Decent_Comment) A Decent_Comment object similar to the WP_Comment_Query object.

Return

  • $(array) An array of comments.

decent_comments_comment_output

This is used to filter the output produced for a single comment. The following parameters are passed upon invocation of the filter hook:

  • $output (string) The rendered comment.
  • $comment_ID (int) The ID of the comment.
  • $options (array) The options provided to specify rendering settings. This includes ellipsis, excerpt, max_excerpt_words, max_excerpt_characters and strip_tags.

Return

  • (string) The rendered comment.

decent_comments_comments_output

This filter is used to modify the output for a list of comments. These are its parameters:

  • $output (string) The rendered output for the included comments.
  • $comments (array) An array of comment objects including all comments to render.
  • $options (array) The options provided that specify particular rendering options. This includes: number, order, orderby, post_id, post_type, terms, term_ids, taxonomy, pingback, trackback, exclude_post_author, avatar_size, excerpt, max_excerpt_words, max_excerpt_characters, ellipsis, show_author, show_date, link_author, show_avatar, show_link, show_comment, and strip_tags.

Return

  • (string) The rendered output for the included comments.

widget_title

This allows to filter the title of a widget (including the Decent Comments widget). See also widget_title.

This filter is invoked when the Decent Comments widget is rendered but currently only provides the first parameter, i.e. the $title.

Return

  • $title (string) The title of the widget.