Completed
Push — update/conversation-remove-par... ( 498b22...5ced53 )
by
unknown
18:38 queued 07:08
created

Admin::enqueue_scripts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
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