Code Duplication    Length = 25-27 lines in 2 locations

class.jetpack.php 1 location

@@ 1709-1733 (lines=25) @@
1706
	/**
1707
	 * Get the wpcom user data of the current|specified connected user.
1708
	 */
1709
	public static function get_connected_user_data( $user_id = null ) {
1710
		// TODO: remove in favor of Connection_Manager->get_connected_user_data
1711
		if ( ! $user_id ) {
1712
			$user_id = get_current_user_id();
1713
		}
1714
1715
		$transient_key = "jetpack_connected_user_data_$user_id";
1716
1717
		if ( $cached_user_data = get_transient( $transient_key ) ) {
1718
			return $cached_user_data;
1719
		}
1720
1721
		Jetpack::load_xml_rpc_client();
1722
		$xml = new Jetpack_IXR_Client( array(
1723
			'user_id' => $user_id,
1724
		) );
1725
		$xml->query( 'wpcom.getUser' );
1726
		if ( ! $xml->isError() ) {
1727
			$user_data = $xml->getResponse();
1728
			set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS );
1729
			return $user_data;
1730
		}
1731
1732
		return false;
1733
	}
1734
1735
	/**
1736
	 * Get the wpcom email of the current|specified connected user.

packages/connection/src/Manager.php 1 location

@@ 78-104 (lines=27) @@
75
	 * @param Integer $user_id the user identifier.
76
	 * @return Object the user object.
77
	 */
78
	public function get_connected_user_data( $user_id = null ) {
79
		if ( ! $user_id ) {
80
			$user_id = get_current_user_id();
81
		}
82
83
		$transient_key    = "jetpack_connected_user_data_$user_id";
84
		$cached_user_data = get_transient( $transient_key );
85
86
		if ( $cached_user_data ) {
87
			return $cached_user_data;
88
		}
89
90
		\Jetpack::load_xml_rpc_client();
91
		$xml = new \Jetpack_IXR_Client(
92
			array(
93
				'user_id' => $user_id,
94
			)
95
		);
96
		$xml->query( 'wpcom.getUser' );
97
		if ( ! $xml->isError() ) {
98
			$user_data = $xml->getResponse();
99
			set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS );
100
			return $user_data;
101
		}
102
103
		return false;
104
	}
105
106
	/**
107
	 * Is the user the connection owner.