Completed
Push — update/backup-plugin-add-conne... ( 17c076 )
by
unknown
145:05 queued 134:28
created

Jetpack_Backup   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 91
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A admin_init() 0 14 2
A enqueue_admin_scripts() 0 27 1
A admin_menu() 0 11 1
A plugin_settings_page() 0 5 1
A get_initial_state() 0 4 1
1
<?php
2
/**
3
 * Primary class file for the Jetpack Backup plugin.
4
 *
5
 * @package automattic/jetpack-backup
6
 */
7
8
if ( ! defined( 'ABSPATH' ) ) {
9
	exit;
10
}
11
12
/**
13
 * Class Jetpack_Backup
14
 */
15
class Jetpack_Backup {
16
	/**
17
	 * Constructor.
18
	 */
19
	public function __construct() {
20
		self::admin_init();
21
	}
22
23
	/**
24
	 * Initialize the admin resources.
25
	 */
26
	private function admin_init() {
27
		if ( ! is_admin() ) {
28
			return;
29
		}
30
31
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
32
		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
33
		add_action(
34
			'plugins_loaded',
35
			function () {
36
				Automattic\Jetpack\ConnectionUI\Admin::init();
37
			}
38
		);
39
	}
40
41
	/**
42
	 * Enqueue plugin admin scripts and styles.
43
	 */
44
	public function enqueue_admin_scripts() {
45
		$build_assets = require_once JETPACK_BACKUP_PLUGIN_DIR . '/build/index.asset.php';
46
		wp_register_script(
47
			'jetpack-backup-script',
48
			plugins_url( 'build/index.js', JETPACK_BACKUP_PLUGIN_ROOT_FILE ),
49
			$build_assets['dependencies'],
50
			$build_assets['version'],
51
			true
52
		);
53
		wp_enqueue_script( 'jetpack-backup-script' );
54
55
		wp_add_inline_script( 'jetpack-backup-script', $this->get_initial_state(), 'before' );
56
57
		wp_set_script_translations( 'react-jetpack-backup-script', 'jetpack', 'jetpack-backup' );
58
59
		wp_enqueue_style(
60
			'jetpack-backup-style',
61
			plugins_url( 'build/index.css', JETPACK_BACKUP_PLUGIN_ROOT_FILE ),
62
			array( 'wp-components' ),
63
			$build_assets['version']
64
		);
65
		wp_style_add_data(
66
			'jetpack-backup-style',
67
			'rtl',
68
			plugins_url( 'build/index.rtl.css', JETPACK_BACKUP_PLUGIN_ROOT_FILE )
69
		);
70
	}
71
72
	/**
73
	 * Plugin admin menu setup.
74
	 */
75
	public function admin_menu() {
76
		add_menu_page(
77
			__( 'Jetpack Backup', 'jetpack-backup' ),
78
			__( 'Backup', 'jetpack-backup' ),
79
			'manage_options',
80
			'jetpack-backup',
81
			array( $this, 'plugin_settings_page' ),
82
			'dashicons-image-rotate',
83
			99
84
		);
85
	}
86
87
	/**
88
	 * Main plugin settings page.
89
	 */
90
	public function plugin_settings_page() {
91
		?>
92
			<div id="jetpack-backup-root"></div>
93
		<?php
94
	}
95
96
	/**
97
	 * Return the rendered initial state JavaScript code.
98
	 *
99
	 * @return string
100
	 */
101
	private function get_initial_state() {
102
		require_once JETPACK_BACKUP_PLUGIN_DIR . '/src//php/class-initial-state.php';
103
		return ( new Initial_State() )->render();
104
	}
105
}
106