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
|
|
|
* Make sure we only initialize the class once, as multiple plugins may call `init()` here. |
17
|
|
|
* |
18
|
|
|
* @var $is_initialized |
19
|
|
|
*/ |
20
|
|
|
public static $is_initialized = false; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Construction. |
24
|
|
|
*/ |
25
|
|
|
public function __construct() { |
26
|
|
|
add_action( 'admin_menu', array( $this, 'register_submenu_page' ), 1000 ); |
27
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Initialize the UI. |
32
|
|
|
*/ |
33
|
|
|
public static function init() { |
34
|
|
|
if ( false === self::$is_initialized ) { |
35
|
|
|
new static(); |
36
|
|
|
self::$is_initialized = true; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Register's submenu. |
42
|
|
|
*/ |
43
|
|
|
public function register_submenu_page() { |
44
|
|
|
add_submenu_page( |
45
|
|
|
'tools.php', |
46
|
|
|
__( 'Connection Manager', 'jetpack' ), |
47
|
|
|
__( 'Connection Manager', 'jetpack' ), |
48
|
|
|
'manage_options', |
49
|
|
|
'wpcom-connection-manager', |
50
|
|
|
array( $this, 'render_ui' ), |
51
|
|
|
4 |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Enqueue scripts! |
57
|
|
|
* |
58
|
|
|
* @param string $hook Page hook. |
59
|
|
|
*/ |
60
|
|
|
public function enqueue_scripts( $hook ) { |
61
|
|
|
if ( strpos( $hook, 'tools_page_wpcom-connection-manager' ) === 0 ) { |
62
|
|
|
$build_assets = require_once __DIR__ . '/../build/index.asset.php'; |
63
|
|
|
wp_enqueue_script( 'jetpack_connection_ui_script', plugin_dir_url( __DIR__ ) . 'build/index.js', $build_assets['dependencies'], $build_assets['version'], true ); |
64
|
|
|
|
65
|
|
|
wp_set_script_translations( 'react-jetpack_connection_ui_script', 'jetpack' ); |
66
|
|
|
wp_add_inline_script( 'jetpack_connection_ui_script', $this->get_initial_state(), 'before' ); |
67
|
|
|
|
68
|
|
|
wp_enqueue_style( 'jetpack_connection_ui_style', plugin_dir_url( __DIR__ ) . 'build/index.css', array( 'wp-components' ), $build_assets['version'] ); |
69
|
|
|
wp_style_add_data( 'jetpack_connection_ui_style', 'rtl', plugin_dir_url( __DIR__ ) . 'build/index.rtl.css' ); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Render UI. |
75
|
|
|
*/ |
76
|
|
|
public function render_ui() { |
77
|
|
|
?> |
78
|
|
|
<div id="jetpack-connection-ui-container"></div> |
79
|
|
|
<?php |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Return the rendered initial state JavaScript code. |
84
|
|
|
* |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
private function get_initial_state() { |
88
|
|
|
return ( new Initial_State() )->render(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|