Code Duplication    Length = 24-26 lines in 2 locations

class.jetpack.php 1 location

@@ 1686-1709 (lines=24) @@
1683
	/**
1684
	 * Get the wpcom user data of the current|specified connected user.
1685
	 */
1686
	public static function get_connected_user_data( $user_id = null ) {
1687
		// TODO: remove in favor of Connection_Manager->get_connected_user_data
1688
		if ( ! $user_id ) {
1689
			$user_id = get_current_user_id();
1690
		}
1691
1692
		$transient_key = "jetpack_connected_user_data_$user_id";
1693
1694
		if ( $cached_user_data = get_transient( $transient_key ) ) {
1695
			return $cached_user_data;
1696
		}
1697
1698
		$xml = new Jetpack_IXR_Client( array(
1699
			'user_id' => $user_id,
1700
		) );
1701
		$xml->query( 'wpcom.getUser' );
1702
		if ( ! $xml->isError() ) {
1703
			$user_data = $xml->getResponse();
1704
			set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS );
1705
			return $user_data;
1706
		}
1707
1708
		return false;
1709
	}
1710
1711
	/**
1712
	 * Get the wpcom email of the current|specified connected user.

packages/connection/src/Manager.php 1 location

@@ 538-563 (lines=26) @@
535
	 * @param Integer $user_id the user identifier.
536
	 * @return Object the user object.
537
	 */
538
	public function get_connected_user_data( $user_id = null ) {
539
		if ( ! $user_id ) {
540
			$user_id = get_current_user_id();
541
		}
542
543
		$transient_key    = "jetpack_connected_user_data_$user_id";
544
		$cached_user_data = get_transient( $transient_key );
545
546
		if ( $cached_user_data ) {
547
			return $cached_user_data;
548
		}
549
550
		$xml = new \Jetpack_IXR_Client(
551
			array(
552
				'user_id' => $user_id,
553
			)
554
		);
555
		$xml->query( 'wpcom.getUser' );
556
		if ( ! $xml->isError() ) {
557
			$user_data = $xml->getResponse();
558
			set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS );
559
			return $user_data;
560
		}
561
562
		return false;
563
	}
564
565
	/**
566
	 * Returns true if the provided user is the Jetpack connection owner.