^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_comment()用法示例

get_comment( WP_Comment|string|int $comment = null,  string $output = OBJECT )

Retrieves comment data given a comment ID or comment object.


描述

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.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包


参数

$comment

(WP_Comment|string|int)
(Optional)
Comment to retrieve.

Default value: null

$output

(string)
(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


返回值

(WP_Comment|array|null) Depends on $output value.


源代码

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 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;
}

更新日志

Version 描述
2.0.0 Introduced.

相关函数

Uses

  • wp-includes/class-wp-comment.php:
    WP_Comment::__construct()
  • wp-includes/class-wp-comment.php:
    WP_Comment::get_instance()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/comment.php:
    get_comment

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:
    WP_REST_Comments_Controller::get_comment()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:
    WP_REST_Comments_Controller::update_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:
    WP_REST_Comments_Controller::delete_item()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:
    WP_REST_Comments_Controller::create_item()
  • wp-includes/class-wp-comment-query.php:
    WP_Comment_Query::fill_descendants()
  • wp-includes/comment.php:
    wp_handle_comment_submission()
  • wp-includes/comment.php:
    wp_new_comment_notify_moderator()
  • wp-includes/comment.php:
    wp_new_comment_notify_postauthor()
  • wp-admin/includes/class-wp-comments-list-table.php:
    WP_Comments_List_Table::floated_admin_avatar()
  • wp-includes/class-wp-comment-query.php:
    WP_Comment_Query::get_comments()
  • wp-includes/link-template.php:
    get_avatar_data()
  • wp-admin/includes/template.php:
    touch_time()
  • wp-admin/includes/ajax-actions.php:
    _wp_ajax_delete_comment_response()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_delete_comment()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_dim_comment()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_get_comments()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_replyto_comment()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_edit_comment()
  • wp-admin/includes/class-wp-comments-list-table.php:
    WP_Comments_List_Table::column_comment()
  • wp-admin/includes/comment.php:
    get_comment_to_edit()
  • wp-admin/includes/comment.php:
    floated_admin_avatar()
  • wp-includes/capabilities.php:
    map_meta_cap()
  • wp-includes/pluggable.php:
    get_avatar()
  • wp-includes/pluggable.php:
    wp_notify_postauthor()
  • wp-includes/pluggable.php:
    wp_notify_moderator()
  • wp-includes/deprecated.php:
    get_commentdata()
  • wp-includes/functions.php:
    wp_scheduled_delete()
  • wp-includes/link-template.php:
    get_edit_comment_link()
  • wp-includes/link-template.php:
    edit_comment_link()
  • wp-includes/feed.php:
    get_comment_guid()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::wp_deleteComment()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::wp_editComment()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::wp_getComment()
  • wp-includes/comment-template.php:
    comment_form_title()
  • wp-includes/comment-template.php:
    get_comment_reply_link()
  • wp-includes/comment-template.php:
    get_comment_link()
  • wp-includes/comment-template.php:
    get_comment_text()
  • wp-includes/comment-template.php:
    comment_text()
  • wp-includes/comment-template.php:
    get_comment_time()
  • wp-includes/comment-template.php:
    get_comment_type()
  • wp-includes/comment-template.php:
    comment_author_url()
  • wp-includes/comment-template.php:
    get_comment_class()
  • wp-includes/comment-template.php:
    get_comment_date()
  • wp-includes/comment-template.php:
    get_comment_excerpt()
  • wp-includes/comment-template.php:
    comment_excerpt()
  • wp-includes/comment-template.php:
    get_comment_ID()
  • wp-includes/comment-template.php:
    get_comment_author()
  • wp-includes/comment-template.php:
    comment_author()
  • wp-includes/comment-template.php:
    get_comment_author_email()
  • wp-includes/comment-template.php:
    comment_author_email()
  • wp-includes/comment-template.php:
    get_comment_author_email_link()
  • wp-includes/comment-template.php:
    get_comment_author_link()
  • wp-includes/comment-template.php:
    get_comment_author_IP()
  • wp-includes/comment-template.php:
    get_comment_author_url()
  • wp-includes/comment.php:
    wp_set_comment_status()
  • wp-includes/comment.php:
    wp_update_comment()
  • wp-includes/comment.php:
    wp_spam_comment()
  • wp-includes/comment.php:
    wp_unspam_comment()
  • wp-includes/comment.php:
    wp_get_comment_status()
  • wp-includes/comment.php:
    wp_insert_comment()
  • wp-includes/comment.php:
    get_page_of_comment()
  • wp-includes/comment.php:
    wp_delete_comment()
  • wp-includes/comment.php:
    wp_trash_comment()
  • wp-includes/comment.php:
    wp_untrash_comment()
  • Show 59 more used by
    Hide more used by


  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Example
    To get the author’s name of a comment with ID 7:

    
    <?php
    $my_id = 7;
    $comment_id_7 = get_comment( $my_id ); 
    $name = $comment_id_7->comment_author;
    ?>
    
    Alternatively, specify the <code>$output</code> parameter:
    
    
    <?php
    $my_id = 7;
    $comment_id_7 = get_comment( $my_id, ARRAY_A );
    $name = $comment_id_7['comment_author'];
    ?>
    
    
    <?php
    //	Correct: pass a dummy variable as post_id
    $the_comment = & get_comment( $dummy_id = 7 );
    	
    //	Incorrect: literal integer as post_id
    $the_comment = & get_comment( 7 );
    //	Fatal error: 'Only variables can be passed for reference' or 'Cannot pass parameter 1 by reference'
    ?>
    
    
  2. Example
    To get the author’s name of a comment with ID 7:

    
    <?php
    $my_id = 7;
    $comment_id_7 = get_comment( $my_id ); 
    $name = $comment_id_7->comment_author;
    ?>
    

    Alternatively, specify the $output parameter:

    
    <?php
    $my_id = 7;
    $comment_id_7 = get_comment( $my_id, ARRAY_A );
    $name = $comment_id_7['comment_author'];
    ?>
    
    
    <?php
    //	Correct: pass a dummy variable as post_id
    $the_comment = & get_comment( $dummy_id = 7 );
    	
    //	Incorrect: literal integer as post_id
    $the_comment = & get_comment( 7 );
    //	Fatal error: 'Only variables can be passed for reference' or 'Cannot pass parameter 1 by reference'
    ?>
    
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈