| @@ 570-595 (lines=26) @@ | ||
| 567 | * @param Integer $user_id the user identifier. |
|
| 568 | * @return Object the user object. |
|
| 569 | */ |
|
| 570 | public function get_connected_user_data( $user_id = null ) { |
|
| 571 | if ( ! $user_id ) { |
|
| 572 | $user_id = get_current_user_id(); |
|
| 573 | } |
|
| 574 | ||
| 575 | $transient_key = "jetpack_connected_user_data_$user_id"; |
|
| 576 | $cached_user_data = get_transient( $transient_key ); |
|
| 577 | ||
| 578 | if ( $cached_user_data ) { |
|
| 579 | return $cached_user_data; |
|
| 580 | } |
|
| 581 | ||
| 582 | $xml = new \Jetpack_IXR_Client( |
|
| 583 | array( |
|
| 584 | 'user_id' => $user_id, |
|
| 585 | ) |
|
| 586 | ); |
|
| 587 | $xml->query( 'wpcom.getUser' ); |
|
| 588 | if ( ! $xml->isError() ) { |
|
| 589 | $user_data = $xml->getResponse(); |
|
| 590 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
|
| 591 | return $user_data; |
|
| 592 | } |
|
| 593 | ||
| 594 | return false; |
|
| 595 | } |
|
| 596 | ||
| 597 | /** |
|
| 598 | * Returns a user object of the connection owner. |
|
| @@ 1664-1689 (lines=26) @@ | ||
| 1661 | /** |
|
| 1662 | * Get the wpcom user data of the current|specified connected user. |
|
| 1663 | */ |
|
| 1664 | public static function get_connected_user_data( $user_id = null ) { |
|
| 1665 | // TODO: remove in favor of Connection_Manager->get_connected_user_data |
|
| 1666 | if ( ! $user_id ) { |
|
| 1667 | $user_id = get_current_user_id(); |
|
| 1668 | } |
|
| 1669 | ||
| 1670 | $transient_key = "jetpack_connected_user_data_$user_id"; |
|
| 1671 | ||
| 1672 | if ( $cached_user_data = get_transient( $transient_key ) ) { |
|
| 1673 | return $cached_user_data; |
|
| 1674 | } |
|
| 1675 | ||
| 1676 | $xml = new Jetpack_IXR_Client( |
|
| 1677 | array( |
|
| 1678 | 'user_id' => $user_id, |
|
| 1679 | ) |
|
| 1680 | ); |
|
| 1681 | $xml->query( 'wpcom.getUser' ); |
|
| 1682 | if ( ! $xml->isError() ) { |
|
| 1683 | $user_data = $xml->getResponse(); |
|
| 1684 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
|
| 1685 | return $user_data; |
|
| 1686 | } |
|
| 1687 | ||
| 1688 | return false; |
|
| 1689 | } |
|
| 1690 | ||
| 1691 | /** |
|
| 1692 | * Get the wpcom email of the current|specified connected user. |
|