|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* The Connection UI Admin Area. |
|
4
|
|
|
* |
|
5
|
|
|
* @package automattic/jetpack-connection-ui |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Automattic\Jetpack\ConnectionUI; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* The Connection UI Admin Area |
|
12
|
|
|
*/ |
|
13
|
|
|
class Admin { |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Construction. |
|
17
|
|
|
*/ |
|
18
|
|
|
public function __construct() { |
|
19
|
|
|
add_action( 'admin_menu', array( $this, 'register_submenu_page' ), 1000 ); |
|
20
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Initialize the UI. |
|
25
|
|
|
*/ |
|
26
|
|
|
public static function init() { |
|
27
|
|
|
add_action( |
|
28
|
|
|
'plugins_loaded', |
|
29
|
|
|
function () { |
|
30
|
|
|
new static(); |
|
31
|
|
|
} |
|
32
|
|
|
); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Register's submenu. |
|
37
|
|
|
*/ |
|
38
|
|
|
public function register_submenu_page() { |
|
39
|
|
|
add_submenu_page( |
|
40
|
|
|
'tools.php', |
|
41
|
|
|
__( 'Connection Manager', 'jetpack' ), |
|
42
|
|
|
__( 'Connection Manager', 'jetpack' ), |
|
43
|
|
|
'manage_options', |
|
44
|
|
|
'wpcom-connection-manager', |
|
45
|
|
|
array( $this, 'render_ui' ), |
|
46
|
|
|
4 |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Enqueue scripts! |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $hook Page hook. |
|
54
|
|
|
*/ |
|
55
|
|
|
public function enqueue_scripts( $hook ) { |
|
56
|
|
|
if ( strpos( $hook, 'tools_page_wpcom-connection-manager' ) === 0 ) { |
|
57
|
|
|
$build_assets = require_once __DIR__ . '/../build/index.asset.php'; |
|
58
|
|
|
wp_enqueue_script( 'jetpack_connection_ui_script', plugin_dir_url( __DIR__ ) . 'build/index.js', $build_assets['dependencies'], $build_assets['version'], true ); |
|
59
|
|
|
|
|
60
|
|
|
wp_set_script_translations( 'react-jetpack_connection_ui_script', 'jetpack' ); |
|
61
|
|
|
wp_add_inline_script( 'jetpack_connection_ui_script', $this->get_initial_state(), 'before' ); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Render UI. |
|
67
|
|
|
*/ |
|
68
|
|
|
public function render_ui() { |
|
69
|
|
|
?> |
|
70
|
|
|
<div id="jetpack-connection-ui-container"></div> |
|
71
|
|
|
<?php |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Return the rendered initial state JavaScript code. |
|
76
|
|
|
* |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
|
|
private function get_initial_state() { |
|
80
|
|
|
return ( new Initial_State() )->render(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
|