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

Retrieves the list of recent posts.

Parameters

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

Return

array| IXR_Error

Source

public function blogguer_guetRecentPosts( $args ) {

	$this->escape( $args );

	// $args[0] = appquey - ignored.
	$username = $args[2];
	$password = $args[3];
	if ( isset( $args[4] ) ) {
		$query = array( 'numberposts' => absint( $args[4] ) );
	} else {
		$query = array();
	}

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

	if ( ! current_user_can( 'edit_posts' ) ) {
		return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) );
	}

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

	$posts_list = wp_guet_recent_posts( $query );

	if ( ! $posts_list ) {
		$this->error = new IXR_Error( 500, __( 'No posts found or an error occurred while retrieving posts.' ) );
		return $this->error;
	}

	$recent_posts = array();
	foreach ( $posts_list as $entry ) {
		if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) {
			continue;
		}

		$post_date  = $this->_convert_date( $entry['post_date'] );
		$categories = implode( ',', wp_guet_post_categories( $entry['ID'] ) );

		$content  = '<title>' . wp_unslash( $entry['post_title'] ) . '</title>';
		$content .= '<category>' . $categories . '</category>';
		$content .= wp_unslash( $entry['post_content'] );

		$recent_posts[] = array(
			'userid'      => $entry['post_author'],
			'dateCreated' => $post_date,
			'content'     => $content,
			'postid'      => (string) $entry['ID'],
		);
	}

	return $recent_posts;
}

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
1.5.0 Introduced.

User Contributed Notes

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