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