@@ 1679-1703 (lines=25) @@ | ||
1676 | /** |
|
1677 | * Get the wpcom user data of the current|specified connected user. |
|
1678 | */ |
|
1679 | public static function get_connected_user_data( $user_id = null ) { |
|
1680 | // TODO: remove in favor of Connection_Manager->get_connected_user_data |
|
1681 | if ( ! $user_id ) { |
|
1682 | $user_id = get_current_user_id(); |
|
1683 | } |
|
1684 | ||
1685 | $transient_key = "jetpack_connected_user_data_$user_id"; |
|
1686 | ||
1687 | if ( $cached_user_data = get_transient( $transient_key ) ) { |
|
1688 | return $cached_user_data; |
|
1689 | } |
|
1690 | ||
1691 | Jetpack::load_xml_rpc_client(); |
|
1692 | $xml = new Jetpack_IXR_Client( array( |
|
1693 | 'user_id' => $user_id, |
|
1694 | ) ); |
|
1695 | $xml->query( 'wpcom.getUser' ); |
|
1696 | if ( ! $xml->isError() ) { |
|
1697 | $user_data = $xml->getResponse(); |
|
1698 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
|
1699 | return $user_data; |
|
1700 | } |
|
1701 | ||
1702 | return false; |
|
1703 | } |
|
1704 | ||
1705 | /** |
|
1706 | * Get the wpcom email of the current|specified connected user. |
@@ 525-551 (lines=27) @@ | ||
522 | * @param Integer $user_id the user identifier. |
|
523 | * @return Object the user object. |
|
524 | */ |
|
525 | public function get_connected_user_data( $user_id = null ) { |
|
526 | if ( ! $user_id ) { |
|
527 | $user_id = get_current_user_id(); |
|
528 | } |
|
529 | ||
530 | $transient_key = "jetpack_connected_user_data_$user_id"; |
|
531 | $cached_user_data = get_transient( $transient_key ); |
|
532 | ||
533 | if ( $cached_user_data ) { |
|
534 | return $cached_user_data; |
|
535 | } |
|
536 | ||
537 | \Jetpack::load_xml_rpc_client(); |
|
538 | $xml = new \Jetpack_IXR_Client( |
|
539 | array( |
|
540 | 'user_id' => $user_id, |
|
541 | ) |
|
542 | ); |
|
543 | $xml->query( 'wpcom.getUser' ); |
|
544 | if ( ! $xml->isError() ) { |
|
545 | $user_data = $xml->getResponse(); |
|
546 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
|
547 | return $user_data; |
|
548 | } |
|
549 | ||
550 | return false; |
|
551 | } |
|
552 | ||
553 | /** |
|
554 | * Returns true if the provided user is the Jetpack connection owner. |