get_comment( WP_Comment|string|int $comment = null, string $output = OBJECT )
Retrieves comment data given a comment ID or comment object.
Description
If an object is passed then the comment data will be cached and then returned after being passed through a filter. If the comment is empty, then the global comment variable will be used, if it is set.
Parameters
- $comment
-
(Optional) Comment to retrieve.
Default value: null
- $output
-
(Optional) The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to a WP_Comment object, an associative array, or a numeric array, respectively.
Default value: OBJECT
Return
(WP_Comment|array|null) Depends on $output value.
Source
File: wp-includes/comment.php
function get_comment( &$comment = null, $output = OBJECT ) {
if ( empty( $comment ) && isset( $GLOBALS['comment'] ) ) {
$comment = $GLOBALS['comment'];
}
if ( $comment instanceof WP_Comment ) {
$_comment = $comment;
} elseif ( is_object( $comment ) ) {
$_comment = new WP_Comment( $comment );
} else {
$_comment = WP_Comment::get_instance( $comment );
}
if ( ! $_comment ) {
return null;
}
/**
* Fires after a comment is retrieved.
*
* @since WP-2.3.0
*
* @param mixed $_comment Comment data.
*/
$_comment = apply_filters( 'get_comment', $_comment );
if ( $output == OBJECT ) {
return $_comment;
} elseif ( $output == ARRAY_A ) {
return $_comment->to_array();
} elseif ( $output == ARRAY_N ) {
return array_values( $_comment->to_array() );
}
return $_comment;
}
Related
Uses
Uses | Description |
---|---|
wp-includes/class-wp-comment.php: WP_Comment::__construct() |
Constructor. |
wp-includes/class-wp-comment.php: WP_Comment::get_instance() |
Retrieves a WP_Comment instance. |
wp-includes/comment.php: get_comment |
Fires after a comment is retrieved. |
wp-includes/plugin.php: apply_filters() |
Calls the callback functions that have been added to a filter hook. |
Used By
Used By | Description |
---|---|
wp-includes/comment.php: wp_get_unapproved_comment_author_email() |
Gets unapproved comment author’s email. |
wp-includes/comment-template.php: _get_comment_reply_id() |
Gets the comment’s reply to ID from the $_GET[‘replytocom’]. |
wp-includes/deprecated.php: get_commentdata() |
Retrieve an array of comment data about comment $comment_id. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::get_comment() |
Get the comment, if the ID is valid. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::create_item() |
Creates a comment. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::update_item() |
Updates a comment. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::delete_item() |
Deletes a comment. |
wp-includes/pluggable.php: get_avatar() |
Retrieves the avatar |
wp-includes/pluggable.php: wp_notify_postauthor() |
Notifies an author (and/or others) of a comment/trackback/pingback on a post. |
wp-includes/pluggable.php: wp_notify_moderator() |
Notifies the moderator of the site about a new comment that is awaiting approval. |
wp-includes/comment.php: wp_handle_comment_submission() |
Handles the submission of a comment, usually posted to wp-comments-post.php via a comment form. |
wp-includes/comment.php: wp_set_comment_status() |
Sets the status of a comment. |
wp-includes/comment.php: wp_update_comment() |
Updates an existing comment in the database. |
wp-includes/comment.php: wp_get_comment_status() |
Retrieves the status of a comment by comment ID. |
wp-includes/comment.php: wp_insert_comment() |
Inserts a comment into the database. |
wp-includes/comment.php: wp_new_comment_notify_moderator() |
Sends a comment moderation notification to the comment moderator. |
wp-includes/comment.php: wp_new_comment_notify_postauthor() |
Sends a notification of a new comment to the post author. |
wp-includes/comment.php: wp_delete_comment() |
Trashes or deletes a comment. |
wp-includes/comment.php: wp_trash_comment() |
Moves a comment to the Trash |
wp-includes/comment.php: wp_untrash_comment() |
Removes a comment from the Trash |
wp-includes/comment.php: wp_spam_comment() |
Marks a comment as Spam. |
wp-includes/comment.php: wp_unspam_comment() |
Removes a comment from the Spam. |
wp-includes/comment.php: get_page_of_comment() |
Calculates what page number a comment will appear on for comment paging. |
wp-includes/link-template.php: get_avatar_data() |
Retrieves default data about the avatar. |
wp-includes/link-template.php: get_edit_comment_link() |
Retrieves the edit comment link. |
wp-includes/link-template.php: edit_comment_link() |
Displays the edit comment link with formatting. |
wp-includes/capabilities.php: map_meta_cap() |
Maps a capability to the primitive capabilities required of the given user to satisfy the capability being checked. |
wp-includes/meta.php: get_object_subtype() |
Returns the object subtype for a given object ID of a specific type. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_getComment() |
Retrieves a comment. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_deleteComment() |
Deletes a comment. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_editComment() |
Edits a comment. |
wp-includes/feed.php: get_comment_guid() |
Retrieves the feed GUID for the current comment. |
wp-includes/class-wp-comment-query.php: WP_Comment_Query::get_comments() |
Get a list of comments matching the query vars. |
wp-includes/class-wp-comment-query.php: WP_Comment_Query::fill_descendants() |
Fetch descendants for located comments. |
wp-includes/comment-template.php: comment_form_title() |
Displays text based on comment reply status. |
wp-includes/comment-template.php: get_comment_reply_link() |
Retrieves HTML content for reply to comment link. |
wp-includes/comment-template.php: get_comment_time() |
Retrieves the comment time of the current comment. |
wp-includes/comment-template.php: get_comment_type() |
Retrieves the comment type of the current comment. |
wp-includes/comment-template.php: get_comment_ID() |
Retrieves the comment ID of the current comment. |
wp-includes/comment-template.php: get_comment_link() |
Retrieves the link to a given comment. |
wp-includes/comment-template.php: get_comment_text() |
Retrieves the text of the current comment. |
wp-includes/comment-template.php: comment_text() |
Displays the text of the current comment. |
wp-includes/comment-template.php: get_comment_class() |
Returns the classes for the comment div as an array. |
wp-includes/comment-template.php: get_comment_date() |
Retrieves the comment date of the current comment. |
wp-includes/comment-template.php: get_comment_excerpt() |
Retrieves the excerpt of the given comment. |
wp-includes/comment-template.php: comment_excerpt() |
Displays the excerpt of the current comment. |
wp-includes/comment-template.php: get_comment_author_url() |
Retrieves the URL of the author of the current comment, not linked. |
wp-includes/comment-template.php: comment_author_url() |
Displays the URL of the author of the current comment, not linked. |
wp-includes/comment-template.php: get_comment_author() |
Retrieves the author of the current comment. |
wp-includes/comment-template.php: comment_author() |
Displays the author of the current comment. |
wp-includes/comment-template.php: get_comment_author_email() |
Retrieves the email of the author of the current comment. |
wp-includes/comment-template.php: comment_author_email() |
Displays the email of the author of the current global $comment. |
wp-includes/comment-template.php: get_comment_author_email_link() |
Returns the HTML email link to the author of the current comment. |
wp-includes/comment-template.php: get_comment_author_link() |
Retrieves the HTML link to the URL of the author of the current comment. |
wp-includes/comment-template.php: get_comment_author_IP() |
Retrieves the IP address of the author of the current comment. |
wp-includes/functions.php: wp_scheduled_delete() |
Permanently deletes comments or posts of any type that have held a status of ‘trash’ for the number of days defined in EMPTY_TRASH_DAYS. |
wp-admin/includes/class-wp-comments-list-table.php: WP_Comments_List_Table::floated_admin_avatar() |
Adds avatars to comment author names. |
wp-admin/includes/class-wp-comments-list-table.php: WP_Comments_List_Table::column_comment() | |
wp-admin/includes/template.php: touch_time() |
Prints out HTML form date elements for editing post or comment publish date. |
wp-admin/includes/comment.php: get_comment_to_edit() |
Returns a WP_Comment object based on comment ID. |
wp-admin/includes/comment.php: floated_admin_avatar() |
Adds avatars to relevant places in admin. |
wp-admin/includes/ajax-actions.php: wp_ajax_replyto_comment() |
Ajax handler for replying to a comment. |
wp-admin/includes/ajax-actions.php: wp_ajax_edit_comment() |
Ajax handler for editing a comment. |
wp-admin/includes/ajax-actions.php: wp_ajax_get_comments() |
Ajax handler for getting comments. |
wp-admin/includes/ajax-actions.php: wp_ajax_delete_comment() |
Ajax handler for deleting a comment. |
wp-admin/includes/ajax-actions.php: wp_ajax_dim_comment() |
Ajax handler to dim a comment. |
wp-admin/includes/ajax-actions.php: _wp_ajax_delete_comment_response() |
Sends back current comment total and new page links if they need to be updated. |
Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |