Completed
Push — add/magic-link-for-mobile ( a67c5b...4ebb52 )
by
unknown
13:24 queued 06:01
created

REST_Connector::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
/**
3
 * Sets up the Connection REST API endpoints.
4
 *
5
 * @package jetpack-connection
6
 */
7
8
namespace Automattic\Jetpack\Connection;
9
10
/**
11
 * Registers the REST routes for Connections.
12
 */
13
class REST_Connector {
14
	/**
15
	 * The Connection Manager.
16
	 *
17
	 * @var Manager
18
	 */
19
	private $connection;
20
21
	/**
22
	 * Constructor.
23
	 *
24
	 * @param Manager $connection The Connection Manager.
25
	 */
26
	public function __construct( Manager $connection ) {
27
		$this->connection = $connection;
28
29
		// Register a site.
30
		register_rest_route(
31
			'jetpack/v4',
32
			'/verify_registration',
33
			array(
34
				'methods'  => \WP_REST_Server::EDITABLE,
35
				'callback' => array( $this, 'verify_registration' ),
36
			)
37
		);
38
	}
39
40
	/**
41
	 * Handles verification that a site is registered.
42
	 *
43
	 * @since 5.4.0
44
	 *
45
	 * @param \WP_REST_Request $request The request sent to the WP REST API.
46
	 *
47
	 * @return string|WP_Error
48
	 */
49
	public function verify_registration( \WP_REST_Request $request ) {
50
		$registration_data = array( $request['secret_1'], $request['state'] );
51
52
		return $this->connection->handle_registration( $registration_data );
53
	}
54
}
55