wp_xmlrpc_server::blogger_getRecentPosts()publicWP 1.5.0

Retrieves the list of recent posts.

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

Хуки из метода

Возвращает

Массив|IXR_Error.

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

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

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

  • 0(строка)
    App key (unused).

  • 1(int)
    Blog ID (unused).

  • 2(строка)
    Username.

  • 3(строка)
    Password.

  • 4(int)
    Optional. Number of posts.

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

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

Код wp_xmlrpc_server::blogger_getRecentPosts() WP 6.6.2

public function blogger_getRecentPosts( $args ) {

	$this->escape( $args );

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

	$user = $this->login( $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', 'blogger.getRecentPosts', $args, $this );

	$posts_list = wp_get_recent_posts( $query );

	if ( ! $posts_list ) {
		$this->error = new IXR_Error( 500, __( 'Either there are no posts, or something went wrong.' ) );
		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_get_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;
}