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() |
Call the functions added to a filter hook. |
Used By
Used By | Description |
---|---|
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() |
Retrieve the avatar |
wp-includes/pluggable.php: wp_notify_postauthor() |
Notify 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() |
The status of a comment by ID. |
wp-includes/comment.php: wp_insert_comment() |
Inserts a comment into the database. |
wp-includes/comment.php: wp_new_comment_notify_moderator() |
Send a comment moderation notification to the comment moderator. |
wp-includes/comment.php: wp_new_comment_notify_postauthor() |
Send 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() |
Calculate 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() |
Map meta capabilities to primitive capabilities. |
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() |
Retrieve comment. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_deleteComment() |
Delete a comment. |
wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_editComment() |
Edit comment. |
wp-includes/feed.php: get_comment_guid() |
Retrieve 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() |
Display text based on comment reply status. |
wp-includes/comment-template.php: get_comment_reply_link() |
Retrieve HTML content for reply to comment link. |
wp-includes/comment-template.php: get_comment_time() |
Retrieve the comment time of the current comment. |
wp-includes/comment-template.php: get_comment_type() |
Retrieve the comment type of the current comment. |
wp-includes/comment-template.php: get_comment_ID() |
Retrieve the comment id of the current comment. |
wp-includes/comment-template.php: get_comment_link() |
Retrieve the link to a given comment. |
wp-includes/comment-template.php: get_comment_text() |
Retrieve the text of the current comment. |
wp-includes/comment-template.php: comment_text() |
Display 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() |
Retrieve the comment date of the current comment. |
wp-includes/comment-template.php: get_comment_excerpt() |
Retrieve the excerpt of the current comment. |
wp-includes/comment-template.php: comment_excerpt() |
Display the excerpt of the current comment. |
wp-includes/comment-template.php: get_comment_author_url() |
Retrieve the url of the author of the current comment. |
wp-includes/comment-template.php: comment_author_url() |
Display the url of the author of the current comment. |
wp-includes/comment-template.php: get_comment_author() |
Retrieve 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() |
Retrieve the email of the author of the current comment. |
wp-includes/comment-template.php: comment_author_email() |
Display the email of the author of the current global $comment. |
wp-includes/comment-template.php: get_comment_author_email_link() |
Return the html email link to the author of the current comment. |
wp-includes/comment-template.php: get_comment_author_link() |
Retrieve the HTML link to the URL of the author of the current comment. |
wp-includes/comment-template.php: get_comment_author_IP() |
Retrieve the IP address of the author of the current comment. |
wp-includes/functions.php: wp_scheduled_delete() |
Permanently delete 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() | |
wp-admin/includes/class-wp-comments-list-table.php: WP_Comments_List_Table::column_comment() | |
wp-admin/includes/template.php: touch_time() |
Print 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() |
Add avatars to relevant places in admin, or try to. |
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 |
---|---|
WP-2.0.0 | Introduced. |