On this page
wp_xmlrpc_server::mw_getRecentPosts( array $args ): array|IXR_Error
Retrieve list of recent posts.
Parameters
$argsarray Required-
Method arguments. Note: arguments must be ordered as documented.
- int
Blog ID (unused).
1stringUsername.2stringPassword.3intOptional. Number of posts.
- int
Return
array|IXR_Error
Source
File: wp-includes/class-wp-xmlrpc-server.php. View all references
public function mw_getRecentPosts( $args ) {
$this->escape( $args );
$username = $args[1];
$password = $args[2];
if ( isset( $args[3] ) ) {
$query = array( 'numberposts' => absint( $args[3] ) );
} 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', 'metaWeblog.getRecentPosts', $args, $this );
$posts_list = wp_get_recent_posts( $query );
if ( ! $posts_list ) {
return array();
}
$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'] );
$post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] );
$post_modified = $this->_convert_date( $entry['post_modified'] );
$post_modified_gmt = $this->_convert_date_gmt( $entry['post_modified_gmt'], $entry['post_modified'] );
$categories = array();
$catids = wp_get_post_categories( $entry['ID'] );
foreach ( $catids as $catid ) {
$categories[] = get_cat_name( $catid );
}
$tagnames = array();
$tags = wp_get_post_tags( $entry['ID'] );
if ( ! empty( $tags ) ) {
foreach ( $tags as $tag ) {
$tagnames[] = $tag->name;
}
$tagnames = implode( ', ', $tagnames );
} else {
$tagnames = '';
}
$post = get_extended( $entry['post_content'] );
$link = get_permalink( $entry['ID'] );
// Get the post author info.
$author = get_userdata( $entry['post_author'] );
$allow_comments = ( 'open' === $entry['comment_status'] ) ? 1 : 0;
$allow_pings = ( 'open' === $entry['ping_status'] ) ? 1 : 0;
// Consider future posts as published.
if ( 'future' === $entry['post_status'] ) {
$entry['post_status'] = 'publish';
}
// Get post format.
$post_format = get_post_format( $entry['ID'] );
if ( empty( $post_format ) ) {
$post_format = 'standard';
}
$recent_posts[] = array(
'dateCreated' => $post_date,
'userid' => $entry['post_author'],
'postid' => (string) $entry['ID'],
'description' => $post['main'],
'title' => $entry['post_title'],
'link' => $link,
'permaLink' => $link,
// Commented out because no other tool seems to use this.
// 'content' => $entry['post_content'],
'categories' => $categories,
'mt_excerpt' => $entry['post_excerpt'],
'mt_text_more' => $post['extended'],
'wp_more_text' => $post['more_text'],
'mt_allow_comments' => $allow_comments,
'mt_allow_pings' => $allow_pings,
'mt_keywords' => $tagnames,
'wp_slug' => $entry['post_name'],
'wp_password' => $entry['post_password'],
'wp_author_id' => (string) $author->ID,
'wp_author_display_name' => $author->display_name,
'date_created_gmt' => $post_date_gmt,
'post_status' => $entry['post_status'],
'custom_fields' => $this->get_custom_fields( $entry['ID'] ),
'wp_post_format' => $post_format,
'date_modified' => $post_modified,
'date_modified_gmt' => $post_modified_gmt,
'sticky' => ( 'post' === $entry['post_type'] && is_sticky( $entry['ID'] ) ),
'wp_post_thumbnail' => get_post_thumbnail_id( $entry['ID'] ),
);
}
return $recent_posts;
}
Hooks
- 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 begins.
Related
Uses
| Uses | Description |
|---|---|
| wp_xmlrpc_server::get_custom_fields() wp-includes/class-wp-xmlrpc-server.php | Retrieve custom fields for post. |
| wp_get_recent_posts() wp-includes/post.php | Retrieves a number of recent posts. |
| wp_xmlrpc_server::_convert_date_gmt() wp-includes/class-wp-xmlrpc-server.php | Convert a WordPress GMT date string to an IXR_Date object. |
| wp_xmlrpc_server::_convert_date() wp-includes/class-wp-xmlrpc-server.php | Convert a WordPress date string to an IXR_Date object. |
| get_post_format() wp-includes/post-formats.php | Retrieve the format slug for a post |
| get_extended() wp-includes/post.php | Gets extended entry info ( |
| is_sticky() wp-includes/post.php | Determines whether a post is sticky. |
| wp_get_post_tags() wp-includes/post.php | Retrieves the tags for a post. |
| wp_get_post_categories() wp-includes/post.php | Retrieves the list of categories for a post. |
| get_post_thumbnail_id() wp-includes/post-thumbnail-template.php | Retrieves the post thumbnail ID. |
| get_cat_name() wp-includes/category.php | Retrieves the name of a category from its ID. |
| current_user_can() wp-includes/capabilities.php | Returns whether the current user has the specified capability. |
| do_action() wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. |
| get_permalink() wp-includes/link-template.php | Retrieves the full permalink for the current post or post ID. |
| absint() wp-includes/functions.php | Converts a value to non-negative integer. |
| get_userdata() wp-includes/pluggable.php | Retrieves user info by user ID. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| wp_xmlrpc_server::escape() wp-includes/class-wp-xmlrpc-server.php | Escape string or array of strings for database. |
| wp_xmlrpc_server::login() wp-includes/class-wp-xmlrpc-server.php | Log user in. |
| IXR_Error::__construct() wp-includes/IXR/class-IXR-error.php | PHP5 constructor. |
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/mw_getrecentposts