Completed
Push — add/cli-generate ( 009ccb...e6a636 )
by
unknown
271:23 queued 260:39
created

Admin   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

5 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 8 2
A render_ui() 0 5 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
		}
62
	}
63
64
	/**
65
	 * Render UI.
66
	 */
67
	public function render_ui() {
68
		?>
69
		<div id="jetpack-connection-ui-container"></div>
70
		<?php
71
	}
72
73
}
74