Code Duplication    Length = 25-27 lines in 2 locations

class.jetpack.php 1 location

@@ 1608-1632 (lines=25) @@
1605
	/**
1606
	 * Get the wpcom user data of the current|specified connected user.
1607
	 */
1608
	public static function get_connected_user_data( $user_id = null ) {
1609
		// TODO: remove in favor of Connection_Manager->get_connected_user_data
1610
		if ( ! $user_id ) {
1611
			$user_id = get_current_user_id();
1612
		}
1613
1614
		$transient_key = "jetpack_connected_user_data_$user_id";
1615
1616
		if ( $cached_user_data = get_transient( $transient_key ) ) {
1617
			return $cached_user_data;
1618
		}
1619
1620
		Jetpack::load_xml_rpc_client();
1621
		$xml = new Jetpack_IXR_Client( array(
1622
			'user_id' => $user_id,
1623
		) );
1624
		$xml->query( 'wpcom.getUser' );
1625
		if ( ! $xml->isError() ) {
1626
			$user_data = $xml->getResponse();
1627
			set_transient( $transient_key, $xml->getResponse(), DAY_IN_SECONDS );
1628
			return $user_data;
1629
		}
1630
1631
		return false;
1632
	}
1633
1634
	/**
1635
	 * Get the wpcom email of the current|specified connected user.

packages/connection/src/Manager.php 1 location

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