Completed
Push — renovate/octokit-rest-18.x ( 2bdfe3...d8558e )
by
unknown
137:32 queued 127:02
created

Admin   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 71
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A init() 0 8 1
A register_submenu_page() 0 11 1
A enqueue_scripts() 0 9 2
A render_ui() 0 5 1
A get_initial_state() 0 3 1
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