| 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 | |
| 1728 | $this->escape( $args ); |
| 1729 | |
| 1730 | $blog_ID = (int) $args[0]; |
| 1731 | $username = $args[1]; |
| 1732 | $password = $args[2]; |
| 1733 | $term_ID = (int)$args[3]; |
| 1734 | $content_struct = $args[4]; |
| 1735 | |
| 1736 | if ( ! $user = $this->login( $username, $password ) ) |
| 1737 | return $this->error; |
| 1738 | |
| 1739 | if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) |
| 1740 | return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
| 1741 | |
| 1742 | $taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
| 1743 | |
| 1744 | if( ! current_user_can( $taxonomy->cap->edit_terms ) ) |
| 1745 | return new IXR_Error( 401, __( 'You are not allowed to edit terms in this taxonomy' ) ); |
| 1746 | |
| 1747 | $taxonomy = (array)$taxonomy; |
| 1748 | |
| 1749 | // hold the data of the term |
| 1750 | $term_data = array(); |
| 1751 | |
| 1752 | $term = get_term( $term_ID , $content_struct['taxonomy'] ); |
| 1753 | |
| 1754 | if ( is_wp_error( $term ) ) |
| 1755 | return new IXR_Error(500, $term->get_error_message()); |
| 1756 | |
| 1757 | if ( ! $term ) |
| 1758 | return new IXR_Error(500, __('The term ID does not exists')); |
| 1759 | |
| 1760 | if( isset ( $content_struct['name'] ) ) { |
| 1761 | |
| 1762 | $term_data['name'] = trim( $content_struct['name'] ); |
| 1763 | if( empty ( $term_data['name'] ) ) |
| 1764 | return new IXR_Error( 403, __( 'The term name cannot be empty' ) ); |
| 1765 | |
| 1766 | } |
| 1767 | |
| 1768 | if( isset ( $content_struct['parent'] ) ) { |
| 1769 | |
| 1770 | if( ! $taxonomy['hierarchical'] ) |
| 1771 | return new IXR_Error( 403, __( 'This taxonomy is not hieararchical' ) ); |
| 1772 | |
| 1773 | $parent_term_id = (int)$content_struct['parent']; |
| 1774 | $parent_term = get_term( $parent_term_id , $taxonomy['name'] ); |
| 1775 | |
| 1776 | if ( is_wp_error( $parent_term) ) |
| 1777 | return new IXR_Error(500, $term->get_error_message()); |
| 1778 | |
| 1779 | if ( ! $parent_term ) |
| 1780 | return new IXR_Error(500, __('Parent term does not exists')); |
| 1781 | |
| 1782 | $term_data['parent'] = $content_struct['parent']; |
| 1783 | |
| 1784 | } |
| 1785 | |
| 1786 | if( isset ( $content_struct['description'] ) ) |
| 1787 | $term_data['description'] = $content_struct['description']; |
| 1788 | |
| 1789 | if( isset ( $content_struct['slug'] ) ) |
| 1790 | $term_data['slug'] = $content_struct['slug']; |
| 1791 | |
| 1792 | $term_ID = wp_update_term( $term_ID , $taxonomy['name'] , $term_data ); |
| 1793 | |
| 1794 | if ( is_wp_error( $term_ID ) ) |
| 1795 | return new IXR_Error(500, $term_ID->get_error_message()); |
| 1796 | |
| 1797 | if ( ! $term_ID ) |
| 1798 | return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.')); |
| 1799 | |
| 1800 | return $term_ID; |
| 1801 | |
| 1802 | } |
| 1803 | |