Code Duplication    Length = 25-26 lines in 2 locations

class.jetpack.php 1 location

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

packages/connection/src/Manager.php 1 location

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