Code Duplication    Length = 24-26 lines in 2 locations

class.jetpack.php 1 location

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

packages/connection/src/Manager.php 1 location

@@ 509-534 (lines=26) @@
506
	 * @param Integer $user_id the user identifier.
507
	 * @return Object the user object.
508
	 */
509
	public function get_connected_user_data( $user_id = null ) {
510
		if ( ! $user_id ) {
511
			$user_id = get_current_user_id();
512
		}
513
514
		$transient_key    = "jetpack_connected_user_data_$user_id";
515
		$cached_user_data = get_transient( $transient_key );
516
517
		if ( $cached_user_data ) {
518
			return $cached_user_data;
519
		}
520
521
		$xml = new \Jetpack_IXR_Client(
522
			array(
523
				'user_id' => $user_id,
524
			)
525
		);
526
		$xml->query( 'wpcom.getUser' );
527
		if ( ! $xml->isError() ) {
528
			$user_data = $xml->getResponse();
529
			set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS );
530
			return $user_data;
531
		}
532
533
		return false;
534
	}
535
536
	/**
537
	 * Returns true if the provided user is the Jetpack connection owner.