| 1706 | /** |
| 1707 | * Edit a term |
| 1708 | * |
| 1709 | * @uses wp_update_term() |
| 1710 | * @param array $args Method parameters. Contains: |
| 1711 | * - int $blog_id |
| 1712 | * - string $username |
| 1713 | * - string $password |
| 1714 | * - int $term_id |
| 1715 | * - array $content_struct. |
| 1716 | * The $content_struct must contain: |
| 1717 | * - 'taxonomy' |
| 1718 | * Also, it can optionally contain: |
| 1719 | * - 'name' |
| 1720 | * - 'parent' |
| 1721 | * - 'description' |
| 1722 | * - 'slug' |
| 1723 | * - boolean $send_mail optional. Defaults to false |
| 1724 | * @return int term_id |
| 1725 | */ |
| 1726 | function wp_editTerm( $args ) { |
| 1727 | $this->escape( $args ); |
| 1728 | |
| 1729 | $blog_id = (int) $args[0]; |
| 1730 | $username = $args[1]; |
| 1731 | $password = $args[2]; |
| 1732 | $term_id = (int) $args[3]; |
| 1733 | $content_struct = $args[4]; |
| 1734 | |
| 1735 | if ( ! $user = $this->login( $username, $password ) ) |
| 1736 | return $this->error; |
| 1737 | |
| 1738 | do_action( 'xmlrpc_call', 'wp.editTerm' ); |
| 1739 | |
| 1740 | if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) |
| 1741 | return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
| 1742 | |
| 1743 | $taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
| 1744 | |
| 1745 | if( ! current_user_can( $taxonomy->cap->edit_terms ) ) |
| 1746 | return new IXR_Error( 401, __( 'You are not allowed to edit terms in this taxonomy.' ) ); |
| 1747 | |
| 1748 | $taxonomy = (array) $taxonomy; |
| 1749 | |
| 1750 | // hold the data of the term |
| 1751 | $term_data = array(); |
| 1752 | |
| 1753 | $term = get_term( $term_id , $content_struct['taxonomy'] ); |
| 1754 | |
| 1755 | if ( is_wp_error( $term ) ) |
| 1756 | return new IXR_Error( 500, $term->get_error_message() ); |
| 1757 | |
| 1758 | if ( ! $term ) |
| 1759 | return new IXR_Error( 404, __('Invalid term ID.') ); |
| 1760 | |
| 1761 | if( isset ( $content_struct['name'] ) ) { |
| 1762 | $term_data['name'] = trim( $content_struct['name'] ); |
| 1763 | |
| 1764 | if( empty ( $term_data['name'] ) ) |
| 1765 | return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); |
| 1766 | } |
| 1767 | |
| 1768 | if( isset ( $content_struct['parent'] ) ) { |
| 1769 | if( ! $taxonomy['hierarchical'] ) |
| 1770 | return new IXR_Error( 403, __( 'This taxonomy is not hierarchical.' ) ); |
| 1771 | |
| 1772 | $parent_term_id = (int) $content_struct['parent']; |
| 1773 | $parent_term = get_term( $parent_term_id , $taxonomy['name'] ); |
| 1774 | |
| 1775 | if ( is_wp_error( $parent_term) ) |
| 1776 | return new IXR_Error( 500, $term->get_error_message() ); |
| 1777 | |
| 1778 | if ( ! $parent_term ) |
| 1779 | return new IXR_Error( 403, __('Invalid parent term ID.') ); |
| 1780 | |
| 1781 | $term_data['parent'] = $content_struct['parent']; |
| 1782 | } |
| 1783 | |
| 1784 | if( isset ( $content_struct['description'] ) ) |
| 1785 | $term_data['description'] = $content_struct['description']; |
| 1786 | |
| 1787 | if( isset ( $content_struct['slug'] ) ) |
| 1788 | $term_data['slug'] = $content_struct['slug']; |
| 1789 | |
| 1790 | $term = wp_update_term( $term_id , $taxonomy['name'] , $term_data ); |
| 1791 | |
| 1792 | if ( is_wp_error( $term ) ) |
| 1793 | return new IXR_Error( 500, $term->get_error_message() ); |
| 1794 | |
| 1795 | if ( ! $term ) |
| 1796 | return new IXR_Error( 500, __('Sorry, editing the term failed.') ); |
| 1797 | |
| 1798 | return $term['term_id']; |
| 1799 | } |
| 1800 | |