| @@ 77-103 (lines=27) @@ | ||
| 74 | * @param Integer $user_id the user identifier. |
|
| 75 | * @return Object the user object. |
|
| 76 | */ |
|
| 77 | public function get_connected_user_data( $user_id = null ) { |
|
| 78 | if ( ! $user_id ) { |
|
| 79 | $user_id = get_current_user_id(); |
|
| 80 | } |
|
| 81 | ||
| 82 | $transient_key = "jetpack_connected_user_data_$user_id"; |
|
| 83 | $cached_user_data = get_transient( $transient_key ); |
|
| 84 | ||
| 85 | if ( $cached_user_data ) { |
|
| 86 | return $cached_user_data; |
|
| 87 | } |
|
| 88 | ||
| 89 | \Jetpack::load_xml_rpc_client(); |
|
| 90 | $xml = new \Jetpack_IXR_Client( |
|
| 91 | array( |
|
| 92 | 'user_id' => $user_id, |
|
| 93 | ) |
|
| 94 | ); |
|
| 95 | $xml->query( 'wpcom.getUser' ); |
|
| 96 | if ( ! $xml->isError() ) { |
|
| 97 | $user_data = $xml->getResponse(); |
|
| 98 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
|
| 99 | return $user_data; |
|
| 100 | } |
|
| 101 | ||
| 102 | return false; |
|
| 103 | } |
|
| 104 | ||
| 105 | /** |
|
| 106 | * Is the user the connection owner. |
|
| @@ 1710-1734 (lines=25) @@ | ||
| 1707 | /** |
|
| 1708 | * Get the wpcom user data of the current|specified connected user. |
|
| 1709 | */ |
|
| 1710 | public static function get_connected_user_data( $user_id = null ) { |
|
| 1711 | // TODO: remove in favor of Connection_Manager->get_connected_user_data |
|
| 1712 | if ( ! $user_id ) { |
|
| 1713 | $user_id = get_current_user_id(); |
|
| 1714 | } |
|
| 1715 | ||
| 1716 | $transient_key = "jetpack_connected_user_data_$user_id"; |
|
| 1717 | ||
| 1718 | if ( $cached_user_data = get_transient( $transient_key ) ) { |
|
| 1719 | return $cached_user_data; |
|
| 1720 | } |
|
| 1721 | ||
| 1722 | Jetpack::load_xml_rpc_client(); |
|
| 1723 | $xml = new Jetpack_IXR_Client( array( |
|
| 1724 | 'user_id' => $user_id, |
|
| 1725 | ) ); |
|
| 1726 | $xml->query( 'wpcom.getUser' ); |
|
| 1727 | if ( ! $xml->isError() ) { |
|
| 1728 | $user_data = $xml->getResponse(); |
|
| 1729 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
|
| 1730 | return $user_data; |
|
| 1731 | } |
|
| 1732 | ||
| 1733 | return false; |
|
| 1734 | } |
|
| 1735 | ||
| 1736 | /** |
|
| 1737 | * Get the wpcom email of the current|specified connected user. |
|