| @@ 1684-1708 (lines=25) @@ | ||
| 1681 | /** |
|
| 1682 | * Get the wpcom user data of the current|specified connected user. |
|
| 1683 | */ |
|
| 1684 | public static function get_connected_user_data( $user_id = null ) { |
|
| 1685 | // TODO: remove in favor of Connection_Manager->get_connected_user_data |
|
| 1686 | if ( ! $user_id ) { |
|
| 1687 | $user_id = get_current_user_id(); |
|
| 1688 | } |
|
| 1689 | ||
| 1690 | $transient_key = "jetpack_connected_user_data_$user_id"; |
|
| 1691 | ||
| 1692 | if ( $cached_user_data = get_transient( $transient_key ) ) { |
|
| 1693 | return $cached_user_data; |
|
| 1694 | } |
|
| 1695 | ||
| 1696 | Jetpack::load_xml_rpc_client(); |
|
| 1697 | $xml = new Jetpack_IXR_Client( array( |
|
| 1698 | 'user_id' => $user_id, |
|
| 1699 | ) ); |
|
| 1700 | $xml->query( 'wpcom.getUser' ); |
|
| 1701 | if ( ! $xml->isError() ) { |
|
| 1702 | $user_data = $xml->getResponse(); |
|
| 1703 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
|
| 1704 | return $user_data; |
|
| 1705 | } |
|
| 1706 | ||
| 1707 | return false; |
|
| 1708 | } |
|
| 1709 | ||
| 1710 | /** |
|
| 1711 | * Get the wpcom email of the current|specified connected user. |
|
| @@ 509-535 (lines=27) @@ | ||
| 506 | * @param Integer $user_id the user identifier. |
|
| 507 | * @return Object the user object. |
|
| 508 | */ |
|
| 509 | public function get_connected_user_data( $user_id = null ) { |
|
| 510 | if ( ! $user_id ) { |
|
| 511 | $user_id = get_current_user_id(); |
|
| 512 | } |
|
| 513 | ||
| 514 | $transient_key = "jetpack_connected_user_data_$user_id"; |
|
| 515 | $cached_user_data = get_transient( $transient_key ); |
|
| 516 | ||
| 517 | if ( $cached_user_data ) { |
|
| 518 | return $cached_user_data; |
|
| 519 | } |
|
| 520 | ||
| 521 | \Jetpack::load_xml_rpc_client(); |
|
| 522 | $xml = new \Jetpack_IXR_Client( |
|
| 523 | array( |
|
| 524 | 'user_id' => $user_id, |
|
| 525 | ) |
|
| 526 | ); |
|
| 527 | $xml->query( 'wpcom.getUser' ); |
|
| 528 | if ( ! $xml->isError() ) { |
|
| 529 | $user_data = $xml->getResponse(); |
|
| 530 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
|
| 531 | return $user_data; |
|
| 532 | } |
|
| 533 | ||
| 534 | return false; |
|
| 535 | } |
|
| 536 | ||
| 537 | /** |
|
| 538 | * Returns true if the provided user is the Jetpack connection owner. |
|