WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

wp_xmlrpc_server::wp_getComments() public WP 2.7.0

Retrieve comments.

Besides the common blog_id (unused), username, and password arguments, it takes a filter array as last argument.

Accepted 'filter' keys are 'status', 'post_id', 'offset', and 'number'.

The defaults are as follows:

  • 'status' - Default is ''. Filter by status (e.g., 'approve', 'hold')
  • 'post_id' - Default is ''. The post where the comment is posted. Empty string shows all comments.
  • 'number' - Default is 10. Total number of media items to retrieve.
  • 'offset' - Default is 0. See WP_Query::query() for more.

Это метод класса: wp_xmlrpc_server{}

Хуки из метода
Возвращает

Массив/IXR_Error. Contains a collection of comments. See wp_xmlrpc_server::wp_getComment() for a description of each item contents

Использование

$wp_xmlrpc_server = new wp_xmlrpc_server();
$wp_xmlrpc_server->wp_getComments( $args );
$args(массив) (обязательный)

Method arguments. Note: arguments must be ordered as documented.

  • blog_id(число)
    (unused)

  • username(строка)

  • password(строка)

  • struct(массив)

Список изменений

С версии 2.7.0 Введена.

Код wp_xmlrpc_server::wp_getComments() WP 5.5.1

wp-includes/class-wp-xmlrpc-server.php
<?php
public function wp_getComments( $args ) {
	$this->escape( $args );

	$username = $args[1];
	$password = $args[2];
	$struct   = isset( $args[3] ) ? $args[3] : array();

	$user = $this->login( $username, $password );
	if ( ! $user ) {
		return $this->error;
	}

	/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
	do_action( 'xmlrpc_call', 'wp.getComments' );

	if ( isset( $struct['status'] ) ) {
		$status = $struct['status'];
	} else {
		$status = '';
	}

	if ( ! current_user_can( 'moderate_comments' ) && 'approve' !== $status ) {
		return new IXR_Error( 401, __( 'Invalid comment status.' ) );
	}

	$post_id = '';
	if ( isset( $struct['post_id'] ) ) {
		$post_id = absint( $struct['post_id'] );
	}

	$post_type = '';
	if ( isset( $struct['post_type'] ) ) {
		$post_type_object = get_post_type_object( $struct['post_type'] );
		if ( ! $post_type_object || ! post_type_supports( $post_type_object->name, 'comments' ) ) {
			return new IXR_Error( 404, __( 'Invalid post type.' ) );
		}
		$post_type = $struct['post_type'];
	}

	$offset = 0;
	if ( isset( $struct['offset'] ) ) {
		$offset = absint( $struct['offset'] );
	}

	$number = 10;
	if ( isset( $struct['number'] ) ) {
		$number = absint( $struct['number'] );
	}

	$comments = get_comments(
		array(
			'status'    => $status,
			'post_id'   => $post_id,
			'offset'    => $offset,
			'number'    => $number,
			'post_type' => $post_type,
		)
	);

	$comments_struct = array();
	if ( is_array( $comments ) ) {
		foreach ( $comments as $comment ) {
			$comments_struct[] = $this->_prepare_comment( $comment );
		}
	}

	return $comments_struct;
}