AnsPress_Comment_Hooks::comments_data( integer $post_id, boolean $editing = false,  $offset )

Description #

Comment data.

Parameters #

  • $post_id
    integer (Required) Post ID.
  • $editing
    boolean (Optional) Editing mode. Default value: false

Source #

File: includes/comments.php

	public static function comments_data( $post_id, $editing = false, $offset = 0 ) {
		$user_id = get_current_user_id();

		$args = array(
			'post_id' => $post_id,
			'order'   => 'ASC',
			'status'  => 'approve',
			'number' 	=> ap_opt( 'comment_number' ),
			'offset' 	=> $offset,
		);

		// Always include current user comments.
		if ( ! empty( $user_id ) && $user_id > 0 ) {
			$args['include_unapproved'] = [ $user_id ];
		}

		if ( ap_user_can_approve_comment( ) ) {
			$args['status'] = 'all';
		}

		$comments = get_comments( $args );

		$comments_arr = array();
		foreach ( (array) $comments as $c ) {
			$comments_arr[] = ap_comment_ajax_data( $c );
		}

		if ( ! empty( $comments_arr ) ) {
			return $comments_arr;
		}

		return [];
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment