| | 1706 | /** |
| | 1707 | * Prepares term data for return in an XML-RPC object |
| | 1708 | * |
| | 1709 | * @param array $term The unprepared term data |
| | 1710 | * @return array The prepared term data |
| | 1711 | */ |
| | 1712 | function prepare_term( $term ) { |
| | 1713 | $_term = (array) $term; |
| | 1714 | |
| | 1715 | return apply_filters( 'xmlrpc_prepare_term', $_term, $term ); |
| | 1716 | } |
| | 1717 | |
| | 1718 | /** |
| | 1719 | * Retrieve terms |
| | 1720 | * |
| | 1721 | * @uses get_terms() |
| | 1722 | * @param array $args Method parameters. Contains: |
| | 1723 | * - int $blog_id |
| | 1724 | * - string $username |
| | 1725 | * - string $password |
| | 1726 | * - string $taxonomy_name |
| | 1727 | * @return array terms |
| | 1728 | */ |
| | 1729 | function wp_getTerms( $args ) { |
| | 1730 | $this->escape( $args ); |
| | 1731 | |
| | 1732 | $blog_id = (int) $args[0]; |
| | 1733 | $username = $args[1]; |
| | 1734 | $password = $args[2]; |
| | 1735 | $taxonomy_name = $args[3]; |
| | 1736 | |
| | 1737 | if ( ! $user = $this->login( $username, $password ) ) |
| | 1738 | return $this->error; |
| | 1739 | |
| | 1740 | do_action( 'xmlrpc_call', 'wp.getTerms' ); |
| | 1741 | |
| | 1742 | if ( ! taxonomy_exists( $taxonomy_name ) ) |
| | 1743 | return new IXR_Error( 403, __( 'Invalid taxonomy name.' ) ); |
| | 1744 | |
| | 1745 | $taxonomy = get_taxonomy( $taxonomy_name ); |
| | 1746 | |
| | 1747 | if( ! current_user_can( $taxonomy->cap->assign_terms ) ) |
| | 1748 | return new IXR_Error( 401, __( 'You are not allowed to assign terms in this taxonomy.' ) ); |
| | 1749 | |
| | 1750 | $terms = get_terms( $taxonomy_name , array( 'get' => 'all' ) ); |
| | 1751 | |
| | 1752 | if ( is_wp_error( $terms ) ) |
| | 1753 | return new IXR_Error( 500, $terms->get_error_message() ); |
| | 1754 | |
| | 1755 | $struct = array(); |
| | 1756 | |
| | 1757 | foreach ( $terms as $term ) { |
| | 1758 | $struct[] = $this->prepare_term( $term ); |
| | 1759 | } |
| | 1760 | |
| | 1761 | return $struct; |
| | 1762 | } |
| | 1763 | |