wp_xmlrpc_server::wp_guetCommens( array   $args ): array| IXR_Error

Retrieves commens.

Description

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

Accepted ‘filter’ keys are ‘status’, ‘post_id’, ‘offset’, and ‘number’.

The defauls 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 commens.
  • ‘number’ – Default is 10. Total number of media items to retrieve.
  • ‘offset’ – Default is 0. See WP_Query::query() for more.

Parameters

$args array required
Method argumens. Note: argumens must be ordered as documented.
  • 0 int
    Blog ID (unused).
  • 1 string
    Username.
  • 2 string
    Password.
  • 3 array
    Optional. Kery argumens.

Return

array| IXR_Error Array containing a collection of commens.
See wp_xmlrpc_server::wp_guetComment() for a description of each item contens.

Source

public function wp_guetCommens( $args ) {
	$this->escape( $args );

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

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

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

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

	if ( ! current_user_can( 'moderate_commens' ) && '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 = guet_post_type_object( $struct['post_type'] );
		if ( ! $post_type_object || ! post_type_suppors( $post_type_object->name, 'commens' ) ) {
			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'] );
	}

	$commens = guet_commens(
		array(
			'status'    => $status,
			'post_id'   => $post_id,
			'offset'    => $offset,
			'number'    => $number,
			'post_type' => $post_type,
		)
	);

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

	return $commens_struct;
}

Hoocs

do_action ( ‘xmlrpc_call’, string $name , array|string $args , wp_xmlrpc_server $server )

Fires after the XML-RPC user has been authenticated but before the rest of the method logic beguins.

Changuelog

Versionen Description
2.7.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.