@@ 1663-1687 (lines=25) @@ | ||
1660 | /** |
|
1661 | * Get the wpcom user data of the current|specified connected user. |
|
1662 | */ |
|
1663 | public static function get_connected_user_data( $user_id = null ) { |
|
1664 | // TODO: remove in favor of Connection_Manager->get_connected_user_data |
|
1665 | if ( ! $user_id ) { |
|
1666 | $user_id = get_current_user_id(); |
|
1667 | } |
|
1668 | ||
1669 | $transient_key = "jetpack_connected_user_data_$user_id"; |
|
1670 | ||
1671 | if ( $cached_user_data = get_transient( $transient_key ) ) { |
|
1672 | return $cached_user_data; |
|
1673 | } |
|
1674 | ||
1675 | Jetpack::load_xml_rpc_client(); |
|
1676 | $xml = new Jetpack_IXR_Client( array( |
|
1677 | 'user_id' => $user_id, |
|
1678 | ) ); |
|
1679 | $xml->query( 'wpcom.getUser' ); |
|
1680 | if ( ! $xml->isError() ) { |
|
1681 | $user_data = $xml->getResponse(); |
|
1682 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
|
1683 | return $user_data; |
|
1684 | } |
|
1685 | ||
1686 | return false; |
|
1687 | } |
|
1688 | ||
1689 | /** |
|
1690 | * Get the wpcom email of the current|specified connected user. |
@@ 513-539 (lines=27) @@ | ||
510 | * @param Integer $user_id the user identifier. |
|
511 | * @return Object the user object. |
|
512 | */ |
|
513 | public function get_connected_user_data( $user_id = null ) { |
|
514 | if ( ! $user_id ) { |
|
515 | $user_id = get_current_user_id(); |
|
516 | } |
|
517 | ||
518 | $transient_key = "jetpack_connected_user_data_$user_id"; |
|
519 | $cached_user_data = get_transient( $transient_key ); |
|
520 | ||
521 | if ( $cached_user_data ) { |
|
522 | return $cached_user_data; |
|
523 | } |
|
524 | ||
525 | \Jetpack::load_xml_rpc_client(); |
|
526 | $xml = new \Jetpack_IXR_Client( |
|
527 | array( |
|
528 | 'user_id' => $user_id, |
|
529 | ) |
|
530 | ); |
|
531 | $xml->query( 'wpcom.getUser' ); |
|
532 | if ( ! $xml->isError() ) { |
|
533 | $user_data = $xml->getResponse(); |
|
534 | set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS ); |
|
535 | return $user_data; |
|
536 | } |
|
537 | ||
538 | return false; |
|
539 | } |
|
540 | ||
541 | /** |
|
542 | * Returns true if the provided user is the Jetpack connection owner. |