wp_xmlrpc_server::mw_getRecentPosts() – Retrieve list of recent posts.

You appear to be a bot. Output may be restricted

Description

Retrieve list of recent posts.

Usage

$array|IXR_Error = wp_xmlrpc_server::mw_getRecentPosts( $args );

Parameters

$args
( array ) required – { Method arguments. Note: arguments must be ordered as documented.
$0
( int ) required – Blog ID (unused).
$1
( string ) required – Username.
$2
( string ) required – Password.
$3
( int ) required – Optional. Number of posts. }

Returns

array|IXR_Error

Source

File name: wordpress/wp-includes/class-wp-xmlrpc-server.php
Lines:

1 to 100 of 111
  public function mw_getRecentPosts( $args ) {
    $this->wp_xmlrpc_server::escape( $args );

    $username = $args[1];
    $password = $args[2];
    if ( isset( $args[3] ) ) {
      $query = array( 'numberposts' => absint( $args[3] ) );
    } else {
      $query = array();
    }

    $user = $this->wp_xmlrpc_server::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->wp_xmlrpc_server::_convert_date( $entry['post_date'] );
      $post_date_gmt     = $this->wp_xmlrpc_server::_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] );
      $post_modified     = $this->wp_xmlrpc_server::_convert_date( $entry['post_modified'] );
      $post_modified_gmt = $this->wp_xmlrpc_server::_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'],
 

 View on GitHub View on Trac