wp_xmlrpc_server::mw_getPost( array $args )

Retrieve post.


Description Description


Parameters Parameters

$args

(array) (Required) Method arguments. Note: arguments must be ordered as documented.

  • 'blog_id'
    (int) (unused)
  • 'post_ID'
    (int)
  • 'username'
    (string)
  • 'password'
    (string)


Top ↑

Return Return

(array|IXR_Error)


Top ↑

Source Source

File: wp-includes/class-wp-xmlrpc-server.php

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

		$post_ID  = (int) $args[0];
		$username = $args[1];
		$password = $args[2];

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

		$postdata = get_post($post_ID, ARRAY_A);
		if ( ! $postdata )
			return new IXR_Error( 404, __( 'Invalid post ID.' ) );

		if ( !current_user_can( 'edit_post', $post_ID ) )
			return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );

		/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
		do_action( 'xmlrpc_call', 'metaWeblog.getPost' );

		if ($postdata['post_date'] != '') {
			$post_date = $this->_convert_date( $postdata['post_date'] );
			$post_date_gmt = $this->_convert_date_gmt( $postdata['post_date_gmt'],  $postdata['post_date'] );
			$post_modified = $this->_convert_date( $postdata['post_modified'] );
			$post_modified_gmt = $this->_convert_date_gmt( $postdata['post_modified_gmt'], $postdata['post_modified'] );

			$categories = array();
			$catids = wp_get_post_categories($post_ID);
			foreach ($catids as $catid)
				$categories[] = get_cat_name($catid);

			$tagnames = array();
			$tags = wp_get_post_tags( $post_ID );
			if ( !empty( $tags ) ) {
				foreach ( $tags as $tag )
					$tagnames[] = $tag->name;
				$tagnames = implode( ', ', $tagnames );
			} else {
				$tagnames = '';
			}

			$post = get_extended($postdata['post_content']);
			$link = get_permalink($postdata['ID']);

			// Get the author info.
			$author = get_userdata($postdata['post_author']);

			$allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0;
			$allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0;

			// Consider future posts as published
			if ( $postdata['post_status'] === 'future' )
				$postdata['post_status'] = 'publish';

			// Get post format
			$post_format = get_post_format( $post_ID );
			if ( empty( $post_format ) )
				$post_format = 'standard';

			$sticky = false;
			if ( is_sticky( $post_ID ) )
				$sticky = true;

			$enclosure = array();
			foreach ( (array) get_post_custom($post_ID) as $key => $val) {
				if ($key == 'enclosure') {
					foreach ( (array) $val as $enc ) {
						$encdata = explode("\n", $enc);
						$enclosure['url'] = trim(htmlspecialchars($encdata[0]));
						$enclosure['length'] = (int) trim($encdata[1]);
						$enclosure['type'] = trim($encdata[2]);
						break 2;
					}
				}
			}

			$resp = array(
				'dateCreated' => $post_date,
				'userid' => $postdata['post_author'],
				'postid' => $postdata['ID'],
				'description' => $post['main'],
				'title' => $postdata['post_title'],
				'link' => $link,
				'permaLink' => $link,
				// commented out because no other tool seems to use this
				//	      'content' => $entry['post_content'],
				'categories' => $categories,
				'mt_excerpt' => $postdata['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' => $postdata['post_name'],
				'wp_password' => $postdata['post_password'],
				'wp_author_id' => (string) $author->ID,
				'wp_author_display_name' => $author->display_name,
				'date_created_gmt' => $post_date_gmt,
				'post_status' => $postdata['post_status'],
				'custom_fields' => $this->get_custom_fields($post_ID),
				'wp_post_format' => $post_format,
				'sticky' => $sticky,
				'date_modified' => $post_modified,
				'date_modified_gmt' => $post_modified_gmt
			);

			if ( !empty($enclosure) ) $resp['enclosure'] = $enclosure;

			$resp['wp_post_thumbnail'] = get_post_thumbnail_id( $postdata['ID'] );

			return $resp;
		} else {
			return new IXR_Error(404, __('Sorry, no such post.'));
		}
	}

Top ↑

Changelog Changelog

Changelog
Version Description
1.5.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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