+ // now validate terms specified by name
+ if ( isset( $post_data['terms_names'] ) && is_array( $post_data['terms_names'] ) ) {
+ $taxonomies = array_keys( $post_data['terms_names'] );
+
+ foreach ( $taxonomies as $taxonomy ) {
+ if ( ! array_key_exists( $taxonomy , $post_type_taxonomies ) )
+ return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) );
+
+ if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->assign_terms ) )
+ return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) );
+
+ // for hierarchical taxonomies, we can't assign a term when multiple terms in the hierarchy share the same name
+ $ambiguous_terms = array();
+ if ( is_taxonomy_hierarchical( $taxonomy ) ) {
+ $tax_term_names = get_terms( $taxonomy, array( 'fields' => 'names', 'hide_empty' => false ) );
+
+ // count the number of terms with the same name
+ $tax_term_names_count = array_count_values( $tax_term_names );
+
+ // filter out non-ambiguous term names
+ $ambiguous_tax_term_counts = array_filter( $tax_term_names_count, array( $this, '_is_greater_than_one') );
+
+ $ambiguous_terms = array_keys( $ambiguous_tax_term_counts );
+ }
+
+ $term_names = $post_data['terms_names'][$taxonomy];
+ foreach ( $term_names as $term_name ) {
+ if ( in_array( $term_name, $ambiguous_terms ) )
+ return new IXR_Error( 401, __( 'Ambiguous term name used in a hierarchical taxonomy. Please use term ID instead.' ) );
+
+ $term = get_term_by( 'name', $term_name, $taxonomy );
+
+ if ( ! $term ) {
+ // term doesn't exist, so check that the user is allowed to create new terms
+ if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->edit_terms ) )
+ return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a term to one of the given taxonomies.' ) );
+
+ // create the new term
+ $term_info = wp_insert_term( $term_name, $taxonomy );
+ if ( is_wp_error( $term_info ) )
+ return new IXR_Error( 500, $term_info->get_error_message() );
+
+ $terms[$taxonomy][] = (int) $term_info['term_id'];
+ } else {
+ $terms[$taxonomy][] = (int) $term->term_id;
+ }
+ }
+ }
+ }
+
+ $post_data['tax_input'] = $terms;
+ unset( $post_data['terms'], $post_data['terms_names'] );
+ } else {
+ // do not allow direct submission of 'tax_input', clients must use 'terms' and/or 'terms_names'
+ unset( $post_data['tax_input'], $post_data['post_category'], $post_data['tags_input'] );
+ }
+
+ if ( isset( $post_data['post_format'] ) ) {
+ $format = set_post_format( $post_ID, $post_data['post_format'] );
+
+ if ( is_wp_error( $format ) )
+ return new IXR_Error( 500, $format->get_error_message() );
+
+ unset( $post_data['post_format'] );
+ }
+
+ // Handle enclosures
+ $enclosure = isset( $post_data['enclosure'] ) ? $post_data['enclosure'] : null;
+ $this->add_enclosure_if_new( $post_ID, $enclosure );
+
+ $this->attach_uploads( $post_ID, $post_data['post_content'] );
+
+ $post_data = apply_filters( 'xmlrpc_wp_insert_post_data', $post_data, $content_struct );
+
+ $post_ID = wp_insert_post( $post_data, true );
+ if ( is_wp_error( $post_ID ) )
+ return new IXR_Error( 500, $post_ID->get_error_message() );
+
+ if ( ! $post_ID )
+ return new IXR_Error( 401, __( 'Sorry, your entry could not be posted. Something wrong happened.' ) );
+
+ return strval( $post_ID );
+ }
+
+ /**
+ * Edit a post for any registered post type.
+ *
+ * The $content_struct parameter only needs to contain fields that
+ * should be changed. All other fields will retain their existing values.
+ *
+ * @since 3.4.0
+ *
+ * @param array $args Method parameters. Contains:
+ * - int $blog_id
+ * - string $username
+ * - string $password
+ * - int $post_id
+ * - array $content_struct
+ * @return true on success
+ */
+ function wp_editPost( $args ) {
+ if ( ! $this->minimum_args( $args, 5 ) )
+ return $this->error;
+
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $post_id = (int) $args[3];
+ $content_struct = $args[4];
+
+ if ( ! $user = $this->login( $username, $password ) )
+ return $this->error;
+
+ do_action( 'xmlrpc_call', 'wp.editPost' );
+
+ $post = get_post( $post_id, ARRAY_A );
+
+ if ( empty( $post['ID'] ) )
+ return new IXR_Error( 404, __( 'Invalid post ID.' ) );
+
+ // convert the date field back to IXR form
+ $post['post_date'] = $this->_convert_date( $post['post_date'] );
+
+ // ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct,
+ // since _insert_post will ignore the non-GMT date if the GMT date is set
+ if ( $post['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) )
+ unset( $post['post_date_gmt'] );
+ else
+ $post['post_date_gmt'] = $this->_convert_date( $post['post_date_gmt'] );
+
+ $this->escape( $post );
+ $merged_content_struct = array_merge( $post, $content_struct );
+
+ $retval = $this->_insert_post( $user, $merged_content_struct );
+ if ( $retval instanceof IXR_Error )
+ return $retval;
+
+ return true;
+ }
+
+ /**
+ * Delete a post for any registered post type.
+ *
+ * @since 3.4.0
+ *
+ * @uses wp_delete_post()
+ * @param array $args Method parameters. Contains:
+ * - int $blog_id
+ * - string $username
+ * - string $password
+ * - int $post_id
+ * @return true on success
+ */
+ function wp_deletePost( $args ) {
+ if ( ! $this->minimum_args( $args, 4 ) )
+ return $this->error;
+
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $post_id = (int) $args[3];
+
+ if ( ! $user = $this->login( $username, $password ) )
+ return $this->error;
+
+ do_action( 'xmlrpc_call', 'wp.deletePost' );
+
+ $post = wp_get_single_post( $post_id, ARRAY_A );
+ if ( empty( $post['ID'] ) )
+ return new IXR_Error( 404, __( 'Invalid post ID.' ) );
+
+ $post_type = get_post_type_object( $post['post_type'] );
+ if ( ! current_user_can( $post_type->cap->delete_post, $post_id ) )
+ return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this post.' ) );
+
+ $result = wp_delete_post( $post_id );
+
+ if ( ! $result )
+ return new IXR_Error( 500, __( 'The post cannot be deleted.' ) );
+
+ return true;
+ }
+
+ /**
+ * Retrieve a post.
+ *
+ * @since 3.4.0
+ *
+ * The optional $fields parameter specifies what fields will be included
+ * in the response array. This should be a list of field names. 'post_id' will
+ * always be included in the response regardless of the value of $fields.
+ *
+ * Instead of, or in addition to, individual field names, conceptual group
+ * names can be used to specify multiple fields. The available conceptual
+ * groups are 'post' (all basic fields), 'taxonomies', 'custom_fields',
+ * and 'enclosure'.
+ *
+ * @uses wp_get_single_post()
+ * @param array $args Method parameters. Contains:
+ * - int $post_id
+ * - string $username
+ * - string $password
+ * - array $fields optional
+ * @return array contains (based on $fields parameter):
+ * - 'post_id'
+ * - 'post_title'
+ * - 'post_date'
+ * - 'post_date_gmt'
+ * - 'post_modified'
+ * - 'post_modified_gmt'
+ * - 'post_status'
+ * - 'post_type'
+ * - 'post_name'
+ * - 'post_author'
+ * - 'post_password'
+ * - 'post_excerpt'
+ * - 'post_content'
+ * - 'link'
+ * - 'comment_status'
+ * - 'ping_status'
+ * - 'sticky'
+ * - 'custom_fields'
+ * - 'terms'
+ * - 'categories'
+ * - 'tags'
+ * - 'enclosure'
+ */
+ function wp_getPost( $args ) {
+ if ( ! $this->minimum_args( $args, 4 ) )
+ return $this->error;
+
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $post_id = (int) $args[3];
+
+ if ( isset( $args[4] ) )
+ $fields = $args[4];
+ else
+ $fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPost' );
+
+ if ( ! $user = $this->login( $username, $password ) )
+ return $this->error;
+
+ do_action( 'xmlrpc_call', 'wp.getPost' );
+
+ $post = wp_get_single_post( $post_id, ARRAY_A );
+
+ if ( empty( $post['ID'] ) )
+ return new IXR_Error( 404, __( 'Invalid post ID.' ) );
+
+ $post_type = get_post_type_object( $post['post_type'] );
+ if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) )
+ return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) );
+
+ return $this->_prepare_post( $post, $fields );
+ }
+
+ /**
+ * Retrieve posts.
+ *
+ * @since 3.4.0
+ *
+ * The optional $filter parameter modifies the query used to retrieve posts.
+ * Accepted keys are 'post_type', 'post_status', 'number', 'offset',
+ * 'orderby', and 'order'.
+ *
+ * The optional $fields parameter specifies what fields will be included
+ * in the response array.
+ *
+ * @uses wp_get_recent_posts()
+ * @see wp_getPost() for more on $fields
+ * @see get_posts() for more on $filter values
+ *
+ * @param array $args Method parameters. Contains:
+ * - int $blog_id
+ * - string $username
+ * - string $password
+ * - array $filter optional
+ * - array $fields optional
+ * @return array contains a collection of posts.
+ */
+ function wp_getPosts( $args ) {
+ if ( ! $this->minimum_args( $args, 3 ) )
+ return $this->error;
+
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $filter = isset( $args[3] ) ? $args[3] : array();
+
+ if ( isset( $args[4] ) )
+ $fields = $args[4];
+ else
+ $fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPosts' );
+
+ if ( ! $user = $this->login( $username, $password ) )
+ return $this->error;
+
+ do_action( 'xmlrpc_call', 'wp.getPosts' );
+
+ $query = array();
+
+ if ( isset( $filter['post_type'] ) ) {
+ $post_type = get_post_type_object( $filter['post_type'] );
+ if ( ! ( (bool) $post_type ) )
+ return new IXR_Error( 403, __( 'The post type specified is not valid' ) );
+ } else {
+ $post_type = get_post_type_object( 'post' );
+ }
+
+ if ( ! current_user_can( $post_type->cap->edit_posts ) )
+ return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type' ));
+
+ $query['post_type'] = $post_type->name;
+
+ if ( isset( $filter['post_status'] ) )
+ $query['post_status'] = $filter['post_status'];
+
+ if ( isset( $filter['number'] ) )
+ $query['numberposts'] = absint( $filter['number'] );
+
+ if ( isset( $filter['offset'] ) )
+ $query['offset'] = absint( $filter['offset'] );
+
+ if ( isset( $filter['orderby'] ) ) {
+ $query['orderby'] = $filter['orderby'];
+
+ if ( isset( $filter['order'] ) )
+ $query['order'] = $filter['order'];
+ }
+
+ $posts_list = wp_get_recent_posts( $query );
+
+ if ( ! $posts_list )
+ return array();
+
+ // holds all the posts data
+ $struct = array();
+
+ foreach ( $posts_list as $post ) {
+ $post_type = get_post_type_object( $post['post_type'] );
+ if ( ! current_user_can( $post_type->cap->edit_post, $post['ID'] ) )
+ continue;
+
+ $struct[] = $this->_prepare_post( $post, $fields );
+ }
+
+ return $struct;
+ }
+
+ /**
+ * Create a new term.
+ *
+ * @since 3.4.0
+ *
+ * @uses wp_insert_term()
+ * @param array $args Method parameters. Contains:
+ * - int $blog_id
+ * - string $username
+ * - string $password
+ * - array $content_struct
+ * The $content_struct must contain:
+ * - 'name'
+ * - 'taxonomy'
+ * Also, it can optionally contain:
+ * - 'parent'
+ * - 'description'
+ * - 'slug'
+ * @return string term_id
+ */
+ function wp_newTerm( $args ) {
+ if ( ! $this->minimum_args( $args, 4 ) )
+ return $this->error;
+
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $content_struct = $args[3];
+
+ if ( ! $user = $this->login( $username, $password ) )
+ return $this->error;
+
+ do_action( 'xmlrpc_call', 'wp.newTerm' );
+
+ if ( ! taxonomy_exists( $content_struct['taxonomy'] ) )
+ return new IXR_Error( 403, __( 'Invalid taxonomy' ) );
+
+ $taxonomy = get_taxonomy( $content_struct['taxonomy'] );
+
+ if ( ! current_user_can( $taxonomy->cap->manage_terms ) )
+ return new IXR_Error( 401, __( 'You are not allowed to create terms in this taxonomy.' ) );
+
+ $taxonomy = (array) $taxonomy;
+
+ // hold the data of the term
+ $term_data = array();
+
+ $term_data['name'] = trim( $content_struct['name'] );
+ if ( empty( $term_data['name'] ) )
+ return new IXR_Error( 403, __( 'The term name cannot be empty.' ) );
+
+ if ( isset( $content_struct['parent'] ) ) {
+ if ( ! $taxonomy['hierarchical'] )
+ return new IXR_Error( 403, __( 'This taxonomy is not hierarchical.' ) );
+
+ $parent_term_id = (int) $content_struct['parent'];
+ $parent_term = get_term( $parent_term_id , $taxonomy['name'] );
+
+ if ( is_wp_error( $parent_term ) )
+ return new IXR_Error( 500, $parent_term->get_error_message() );
+
+ if ( ! $parent_term )
+ return new IXR_Error( 403, __( 'Parent term does not exist.' ) );
+
+ $term_data['parent'] = $content_struct['parent'];
+ }
+
+ if ( isset( $content_struct['description'] ) )
+ $term_data['description'] = $content_struct['description'];
+
+ if ( isset( $content_struct['slug'] ) )
+ $term_data['slug'] = $content_struct['slug'];
+
+ $term = wp_insert_term( $term_data['name'] , $taxonomy['name'] , $term_data );
+
+ if ( is_wp_error( $term ) )
+ return new IXR_Error( 500, $term->get_error_message() );
+
+ if ( ! $term )
+ return new IXR_Error( 500, __( 'Sorry, your term could not be created. Something wrong happened.' ) );
+
+ return strval( $term['term_id'] );
+ }
+
+ /**
+ * Edit a term.
+ *
+ * @since 3.4.0
+ *
+ * @uses wp_update_term()
+ * @param array $args Method parameters. Contains:
+ * - int $blog_id
+ * - string $username
+ * - string $password
+ * - string $term_id
+ * - array $content_struct
+ * The $content_struct must contain:
+ * - 'taxonomy'
+ * Also, it can optionally contain:
+ * - 'name'
+ * - 'parent'
+ * - 'description'
+ * - 'slug'
+ * @return bool True, on success.
+ */
+ function wp_editTerm( $args ) {
+ if ( ! $this->minimum_args( $args, 5 ) )
+ return $this->error;
+
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $term_id = (int) $args[3];
+ $content_struct = $args[4];
+
+ if ( ! $user = $this->login( $username, $password ) )
+ return $this->error;
+
+ do_action( 'xmlrpc_call', 'wp.editTerm' );
+
+ if ( ! taxonomy_exists( $content_struct['taxonomy'] ) )
+ return new IXR_Error( 403, __( 'Invalid taxonomy' ) );
+
+ $taxonomy = get_taxonomy( $content_struct['taxonomy'] );
+
+ if ( ! current_user_can( $taxonomy->cap->edit_terms ) )
+ return new IXR_Error( 401, __( 'You are not allowed to edit terms in this taxonomy.' ) );
+
+ $taxonomy = (array) $taxonomy;
+
+ // hold the data of the term
+ $term_data = array();
+
+ $term = get_term( $term_id , $content_struct['taxonomy'] );
+
+ if ( is_wp_error( $term ) )
+ return new IXR_Error( 500, $term->get_error_message() );
+
+ if ( ! $term )
+ return new IXR_Error( 404, __( 'Invalid term ID' ) );
+
+ if ( isset( $content_struct['name'] ) ) {
+ $term_data['name'] = trim( $content_struct['name'] );
+
+ if ( empty( $term_data['name'] ) )
+ return new IXR_Error( 403, __( 'The term name cannot be empty.' ) );
+ }
+
+ if ( isset( $content_struct['parent'] ) ) {
+ if ( ! $taxonomy['hierarchical'] )
+ return new IXR_Error( 403, __( "This taxonomy is not hierarchical so you can't set a parent." ) );
+
+ $parent_term_id = (int) $content_struct['parent'];
+ $parent_term = get_term( $parent_term_id , $taxonomy['name'] );
+
+ if ( is_wp_error( $parent_term ) )
+ return new IXR_Error( 500, $parent_term->get_error_message() );
+
+ if ( ! $parent_term )
+ return new IXR_Error( 403, __( 'Parent term does not exist.' ) );
+
+ $term_data['parent'] = $content_struct['parent'];
+ }
+
+ if ( isset( $content_struct['description'] ) )
+ $term_data['description'] = $content_struct['description'];
+
+ if ( isset( $content_struct['slug'] ) )
+ $term_data['slug'] = $content_struct['slug'];
+
+ $term = wp_update_term( $term_id , $taxonomy['name'] , $term_data );
+
+ if ( is_wp_error( $term ) )
+ return new IXR_Error( 500, $term->get_error_message() );
+
+ if ( ! $term )
+ return new IXR_Error( 500, __( 'Sorry, editing the term failed.' ) );
+
+ return true;
+ }
+
+ /**
+ * Delete a term.
+ *
+ * @since 3.4.0
+ *
+ * @uses wp_delete_term()
+ * @param array $args Method parameters. Contains:
+ * - int $blog_id
+ * - string $username
+ * - string $password
+ * - string $taxnomy_name
+ * - string $term_id
+ * @return boolean|IXR_Error If it suceeded true else a reason why not
+ */
+ function wp_deleteTerm( $args ) {
+ if ( ! $this->minimum_args( $args, 5 ) )
+ return $this->error;
+
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $taxonomy = $args[3];
+ $term_id = (int) $args[4];
+
+ if ( ! $user = $this->login( $username, $password ) )
+ return $this->error;
+
+ do_action( 'xmlrpc_call', 'wp.deleteTerm' );
+
+ if ( ! taxonomy_exists( $taxonomy ) )
+ return new IXR_Error( 403, __( 'Invalid taxonomy' ) );
+
+ $taxonomy = get_taxonomy( $taxonomy );
+
+ if ( ! current_user_can( $taxonomy->cap->delete_terms ) )
+ return new IXR_Error( 401, __( 'You are not allowed to delete terms in this taxonomy.' ) );
+
+ $term = get_term( $term_id, $taxonomy->name );
+
+ if ( is_wp_error( $term ) )
+ return new IXR_Error( 500, $term->get_error_message() );
+
+ if ( ! $term )
+ return new IXR_Error( 404, __( 'Invalid term ID' ) );
+
+ $result = wp_delete_term( $term_id, $taxonomy->name );
+
+ if ( is_wp_error( $result ) )
+ return new IXR_Error( 500, $term->get_error_message() );
+
+ if ( ! $result )
+ return new IXR_Error( 500, __( 'Sorry, deleting the term failed.' ) );
+
+ return $result;
+ }
+
+ /**
+ * Retrieve a term.
+ *
+ * @since 3.4.0
+ *
+ * @uses get_term()
+ * @param array $args Method parameters. Contains:
+ * - int $blog_id
+ * - string $username
+ * - string $password
+ * - string $taxonomy
+ * - string $term_id
+ * @return array contains:
+ * - 'term_id'
+ * - 'name'
+ * - 'slug'
+ * - 'term_group'
+ * - 'term_taxonomy_id'
+ * - 'taxonomy'
+ * - 'description'
+ * - 'parent'
+ * - 'count'
+ */
+ function wp_getTerm( $args ) {
+ if ( ! $this->minimum_args( $args, 5 ) )
+ return $this->error;
+
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $taxonomy = $args[3];
+ $term_id = (int) $args[4];
+
+ if ( ! $user = $this->login( $username, $password ) )
+ return $this->error;
+
+ do_action( 'xmlrpc_call', 'wp.getTerm' );
+
+ if ( ! taxonomy_exists( $taxonomy ) )
+ return new IXR_Error( 403, __( 'Invalid taxonomy' ) );
+
+ $taxonomy = get_taxonomy( $taxonomy );
+
+ if ( ! current_user_can( $taxonomy->cap->assign_terms ) )
+ return new IXR_Error( 401, __( 'You are not allowed to assign terms in this taxonomy.' ) );
+
+ $term = get_term( $term_id , $taxonomy->name, ARRAY_A );
+
+ if ( is_wp_error( $term ) )
+ return new IXR_Error( 500, $term->get_error_message() );
+
+ if ( ! $term )
+ return new IXR_Error( 404, __( 'Invalid term ID' ) );
+
+ return $this->_prepare_term( $term );
+ }
+
+ /**
+ * Retrieve all terms for a taxonomy.
+ *
+ * @since 3.4.0
+ *
+ * The optional $filter parameter modifies the query used to retrieve terms.
+ * Accepted keys are 'number', 'offset', 'orderby', 'order', 'hide_empty', and 'search'.
+ *
+ * @uses get_terms()
+ * @param array $args Method parameters. Contains:
+ * - int $blog_id
+ * - string $username
+ * - string $password
+ * - string $taxonomy
+ * - array $filter optional
+ * @return array terms
+ */
+ function wp_getTerms( $args ) {
+ if ( ! $this->minimum_args( $args, 4 ) )
+ return $this->error;
+
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $taxonomy = $args[3];
+ $filter = isset( $args[4] ) ? $args[4] : array();
+
+ if ( ! $user = $this->login( $username, $password ) )
+ return $this->error;
+
+ do_action( 'xmlrpc_call', 'wp.getTerms' );
+
+ if ( ! taxonomy_exists( $taxonomy ) )
+ return new IXR_Error( 403, __( 'Invalid taxonomy' ) );
+
+ $taxonomy = get_taxonomy( $taxonomy );
+
+ if ( ! current_user_can( $taxonomy->cap->assign_terms ) )
+ return new IXR_Error( 401, __( 'You are not allowed to assign terms in this taxonomy.' ) );
+
+ $query = array();
+
+ if ( isset( $filter['number'] ) )
+ $query['number'] = absint( $filter['number'] );
+
+ if ( isset( $filter['offset'] ) )
+ $query['offset'] = absint( $filter['offset'] );
+
+ if ( isset( $filter['orderby'] ) ) {
+ $query['orderby'] = $filter['orderby'];
+
+ if ( isset( $filter['order'] ) )
+ $query['order'] = $filter['order'];
+ }
+
+ if ( isset( $filter['hide_empty'] ) )
+ $query['hide_empty'] = $filter['hide_empty'];
+ else
+ $query['get'] = 'all';
+
+ if ( isset( $filter['search'] ) )
+ $query['search'] = $filter['search'];
+
+ $terms = get_terms( $taxonomy->name, $query );
+
+ if ( is_wp_error( $terms ) )
+ return new IXR_Error( 500, $terms->get_error_message() );
+
+ $struct = array();
+
+ foreach ( $terms as $term ) {
+ $struct[] = $this->_prepare_term( $term );
+ }
+
+ return $struct;
+ }
+
+ /**
+ * Retrieve a taxonomy.
+ *
+ * @since 3.4.0
+ *
+ * @uses get_taxonomy()
+ * @param array $args Method parameters. Contains:
+ * - int $blog_id
+ * - string $username
+ * - string $password
+ * - string $taxonomy
+ * @return array (@see get_taxonomy())
+ */
+ function wp_getTaxonomy( $args ) {
+ if ( ! $this->minimum_args( $args, 4 ) )
+ return $this->error;
+
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $taxonomy = $args[3];
+
+ if ( isset( $args[4] ) )
+ $fields = $args[4];
+ else
+ $fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomy' );
+
+ if ( ! $user = $this->login( $username, $password ) )
+ return $this->error;
+
+ do_action( 'xmlrpc_call', 'wp.getTaxonomy' );
+
+ if ( ! taxonomy_exists( $taxonomy ) )
+ return new IXR_Error( 403, __( 'Invalid taxonomy' ) );
+
+ $taxonomy = get_taxonomy( $taxonomy );
+
+ if ( ! current_user_can( $taxonomy->cap->assign_terms ) )
+ return new IXR_Error( 401, __( 'You are not allowed to assign terms in this taxonomy.' ) );
+
+ return $this->_prepare_taxonomy( $taxonomy, $fields );
+ }
+
+ /**
+ * Retrieve all taxonomies.
+ *
+ * @since 3.4.0
+ *
+ * @uses get_taxonomies()
+ * @param array $args Method parameters. Contains:
+ * - int $blog_id
+ * - string $username
+ * - string $password
+ * @return array taxonomies
+ */
+ function wp_getTaxonomies( $args ) {
+ if ( ! $this->minimum_args( $args, 3 ) )
+ return $this->error;
+
+ $this->escape( $args );
+
+ $blog_id = (int) $args[0];
+ $username = $args[1];
+ $password = $args[2];
+ $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true );
+
+ if ( isset( $args[4] ) )
+ $fields = $args[4];
+ else
+ $fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomies' );
+
+ if ( ! $user = $this->login( $username, $password ) )
+ return $this->error;
+
+ do_action( 'xmlrpc_call', 'wp.getTaxonomies' );
+
+ $taxonomies = get_taxonomies( $filter, 'objects' );
+
+ // holds all the taxonomy data
+ $struct = array();
+
+ foreach ( $taxonomies as $taxonomy ) {
+ // capability check for post_types
+ if ( ! current_user_can( $taxonomy->cap->assign_terms ) )
+ continue;
+
+ $struct[] = $this->_prepare_taxonomy( $taxonomy, $fields );
+ }
+
+ return $struct;
+ }
+
+ /**
+ * Retrieve page.
+ *
+ * @since 2.2.0
+ *
+ * @param array $args Method parameters. Contains:
+ * - blog_id
+ * - page_id
+ * - username
+ * - password
+ * @return array
+ */
+ function wp_getPage($args) {
+ $this->escape($args);
+
+ $blog_id = (int) $args[0];
+ $page_id = (int) $args[1];
+ $username = $args[2];
+ $password = $args[3];
+
+ if ( !$user = $this->login($username, $password) ) {
+ return $this->error;
+ }
+
+ $page = get_page($page_id);
+ if ( ! $page )
+ return new IXR_Error( 404, __( 'Invalid post ID.' ) );
+
+ if ( !current_user_can( 'edit_page', $page_id ) )
+ return new IXR_Error( 401, __( 'Sorry, you cannot edit this page.' ) );
+
+ do_action('xmlrpc_call', 'wp.getPage');