| @@ 601-626 (lines=26) @@ | ||
| 598 | * @param Integer $user_id the user identifier. |
|
| 599 | * @return Object the user object. |
|
| 600 | */ |
|
| 601 | public function get_connected_user_data( $user_id = null ) { |
|
| 602 | if ( ! $user_id ) { |
|
| 603 | $user_id = get_current_user_id(); |
|
| 604 | } |
|
| 605 | ||
| 606 | $transient_key = "jetpack_connected_user_data_$user_id"; |
|
| 607 | $cached_user_data = get_transient( $transient_key ); |
|
| 608 | ||
| 609 | if ( $cached_user_data ) { |
|
| 610 | return $cached_user_data; |
|
| 611 | } |
|
| 612 | ||
| 613 | $xml = new \Jetpack_IXR_Client( |
|
| 614 | array( |
|
| 615 | 'user_id' => $user_id, |
|
| 616 | ) |
|
| 617 | ); |
|
| 618 | $xml->query( 'wpcom.getUser' ); |
|
| 619 | if ( ! $xml->isError() ) { |
|
| 620 | $user_data = $xml->getResponse(); |
|
| 621 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
|
| 622 | return $user_data; |
|
| 623 | } |
|
| 624 | ||
| 625 | return false; |
|
| 626 | } |
|
| 627 | ||
| 628 | /** |
|
| 629 | * Returns a user object of the connection owner. |
|
| @@ 1777-1802 (lines=26) @@ | ||
| 1774 | /** |
|
| 1775 | * Get the wpcom user data of the current|specified connected user. |
|
| 1776 | */ |
|
| 1777 | public static function get_connected_user_data( $user_id = null ) { |
|
| 1778 | // TODO: remove in favor of Connection_Manager->get_connected_user_data |
|
| 1779 | if ( ! $user_id ) { |
|
| 1780 | $user_id = get_current_user_id(); |
|
| 1781 | } |
|
| 1782 | ||
| 1783 | $transient_key = "jetpack_connected_user_data_$user_id"; |
|
| 1784 | ||
| 1785 | if ( $cached_user_data = get_transient( $transient_key ) ) { |
|
| 1786 | return $cached_user_data; |
|
| 1787 | } |
|
| 1788 | ||
| 1789 | $xml = new Jetpack_IXR_Client( |
|
| 1790 | array( |
|
| 1791 | 'user_id' => $user_id, |
|
| 1792 | ) |
|
| 1793 | ); |
|
| 1794 | $xml->query( 'wpcom.getUser' ); |
|
| 1795 | if ( ! $xml->isError() ) { |
|
| 1796 | $user_data = $xml->getResponse(); |
|
| 1797 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
|
| 1798 | return $user_data; |
|
| 1799 | } |
|
| 1800 | ||
| 1801 | return false; |
|
| 1802 | } |
|
| 1803 | ||
| 1804 | /** |
|
| 1805 | * Get the wpcom email of the current|specified connected user. |
|