|
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
|
|
|
add_action( |
|
21
|
|
|
'admin_menu', |
|
22
|
|
|
function () { |
|
23
|
|
|
$page_suffix = $this->admin_menu(); |
|
24
|
|
|
add_action( 'load-' . $page_suffix, array( $this, 'admin_init' ) ); |
|
25
|
|
|
} |
|
26
|
|
|
); |
|
27
|
|
|
|
|
28
|
|
|
// Init ConnectionUI. |
|
29
|
|
|
add_action( |
|
30
|
|
|
'plugins_loaded', |
|
31
|
|
|
function () { |
|
32
|
|
|
Automattic\Jetpack\Connection\Manager::configure(); |
|
33
|
|
|
Automattic\Jetpack\ConnectionUI\Admin::init(); |
|
34
|
|
|
} |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Initialize the admin resources. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function admin_init() { |
|
42
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Enqueue plugin admin scripts and styles. |
|
47
|
|
|
*/ |
|
48
|
|
|
public function enqueue_admin_scripts() { |
|
49
|
|
|
$build_assets = require_once JETPACK_BACKUP_PLUGIN_DIR . '/build/index.asset.php'; |
|
50
|
|
|
|
|
51
|
|
|
// Main JS file. |
|
52
|
|
|
wp_register_script( |
|
53
|
|
|
'jetpack-backup-script', |
|
54
|
|
|
plugins_url( 'build/index.js', JETPACK_BACKUP_PLUGIN_ROOT_FILE ), |
|
55
|
|
|
$build_assets['dependencies'], |
|
56
|
|
|
$build_assets['version'], |
|
57
|
|
|
true |
|
58
|
|
|
); |
|
59
|
|
|
wp_enqueue_script( 'jetpack-backup-script' ); |
|
60
|
|
|
// Initial JS state including JP Connection data. |
|
61
|
|
|
wp_add_inline_script( 'jetpack-backup-script', $this->get_initial_state(), 'before' ); |
|
62
|
|
|
|
|
63
|
|
|
// Translation assets. |
|
64
|
|
|
wp_set_script_translations( 'jetpack-backup-script-translations', 'jetpack-backup' ); |
|
65
|
|
|
|
|
66
|
|
|
// Main CSS file. |
|
67
|
|
|
wp_enqueue_style( |
|
68
|
|
|
'jetpack-backup-style', |
|
69
|
|
|
plugins_url( 'build/index.css', JETPACK_BACKUP_PLUGIN_ROOT_FILE ), |
|
70
|
|
|
array( 'wp-components' ), |
|
71
|
|
|
$build_assets['version'] |
|
72
|
|
|
); |
|
73
|
|
|
// RTL CSS file. |
|
74
|
|
|
wp_style_add_data( |
|
75
|
|
|
'jetpack-backup-style', |
|
76
|
|
|
'rtl', |
|
77
|
|
|
plugins_url( 'build/index.rtl.css', JETPACK_BACKUP_PLUGIN_ROOT_FILE ) |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Plugin admin menu setup. |
|
83
|
|
|
* |
|
84
|
|
|
* @return string The toplevel plugin admin page hook_suffix. |
|
85
|
|
|
*/ |
|
86
|
|
|
public function admin_menu() { |
|
87
|
|
|
return add_menu_page( |
|
88
|
|
|
__( 'Jetpack Backup', 'jetpack-backup' ), |
|
89
|
|
|
__( 'Backup', 'jetpack-backup' ), |
|
90
|
|
|
'manage_options', |
|
91
|
|
|
'jetpack-backup', |
|
92
|
|
|
array( $this, 'plugin_settings_page' ), |
|
93
|
|
|
'dashicons-image-rotate', |
|
94
|
|
|
99 |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Main plugin settings page. |
|
100
|
|
|
*/ |
|
101
|
|
|
public function plugin_settings_page() { |
|
102
|
|
|
?> |
|
103
|
|
|
<div id="jetpack-backup-root"></div> |
|
104
|
|
|
<?php |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Return the rendered initial state JavaScript code. |
|
109
|
|
|
* |
|
110
|
|
|
* @return string |
|
111
|
|
|
*/ |
|
112
|
|
|
private function get_initial_state() { |
|
113
|
|
|
require_once JETPACK_BACKUP_PLUGIN_DIR . '/src//php/class-initial-state.php'; |
|
114
|
|
|
return ( new Initial_State() )->render(); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|