1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
// Shared logic between Jetpack admin pages |
4
|
|
|
abstract class Jetpack_Admin_Page { |
5
|
|
|
// Add page specific actions given the page hook |
6
|
|
|
abstract function add_page_actions( $hook ); |
7
|
|
|
|
8
|
|
|
// Create a menu item for the page and returns the hook |
9
|
|
|
abstract function get_page_hook(); |
10
|
|
|
|
11
|
|
|
// Enqueue and localize page specific scripts |
12
|
|
|
abstract function page_admin_scripts(); |
13
|
|
|
|
14
|
|
|
// Render page specific HTML |
15
|
|
|
abstract function page_render(); |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Function called after admin_styles to load any additional needed styles. |
19
|
|
|
* |
20
|
|
|
* @since 4.3.0 |
21
|
|
|
*/ |
22
|
|
|
function additional_styles() {} |
23
|
|
|
|
24
|
|
|
function __construct() { |
25
|
|
|
$this->jetpack = Jetpack::init(); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function add_actions() { |
29
|
|
|
/** |
30
|
|
|
* Don't add in the modules page unless modules are available! |
31
|
|
|
*/ |
32
|
|
|
if ( $this->dont_show_if_not_active && ! Jetpack::is_active() && ! Jetpack::is_development_mode() ) { |
|
|
|
|
33
|
|
|
return; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
// Initialize menu item for the page in the admin |
37
|
|
|
$hook = $this->get_page_hook(); |
38
|
|
|
|
39
|
|
|
// Attach hooks common to all Jetpack admin pages based on the created |
40
|
|
|
// hook |
41
|
|
|
add_action( "load-$hook", array( $this, 'admin_help' ) ); |
42
|
|
|
add_action( "load-$hook", array( $this, 'admin_page_load' ) ); |
43
|
|
|
add_action( "admin_head-$hook", array( $this, 'admin_head' ) ); |
44
|
|
|
|
45
|
|
|
add_action( "admin_print_styles-$hook", array( $this, 'admin_styles' ) ); |
46
|
|
|
add_action( "admin_print_scripts-$hook", array( $this, 'admin_scripts' ) ); |
47
|
|
|
|
48
|
|
|
// Attach page specific actions in addition to the above |
49
|
|
|
$this->add_page_actions( $hook ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
function admin_head() { |
53
|
|
View Code Duplication |
if ( isset( $_GET['configure'] ) && Jetpack::is_module( $_GET['configure'] ) && current_user_can( 'manage_options' ) ) { |
54
|
|
|
/** |
55
|
|
|
* Fires in the <head> of a particular Jetpack configuation page. |
56
|
|
|
* |
57
|
|
|
* The dynamic portion of the hook name, `$_GET['configure']`, |
58
|
|
|
* refers to the slug of module, such as 'stats', 'sso', etc. |
59
|
|
|
* A complete hook for the latter would be |
60
|
|
|
* 'jetpack_module_configuation_head_sso'. |
61
|
|
|
* |
62
|
|
|
* @since 3.0.0 |
63
|
|
|
*/ |
64
|
|
|
do_action( 'jetpack_module_configuration_head_' . $_GET['configure'] ); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
// Render the page with a common top and bottom part, and page specific content |
69
|
|
|
function render() { |
70
|
|
|
$this->page_render(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
function admin_help() { |
74
|
|
|
$this->jetpack->admin_help(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
function admin_page_load() { |
78
|
|
|
// This is big. For the moment, just call the existing one. |
79
|
|
|
$this->jetpack->admin_page_load(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
function admin_page_top() { |
83
|
|
|
include_once( JETPACK__PLUGIN_DIR . '_inc/header.php' ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
function admin_page_bottom() { |
87
|
|
|
include_once( JETPACK__PLUGIN_DIR . '_inc/footer.php' ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// Add page specific scripts and jetpack stats for all menu pages |
91
|
|
|
function admin_scripts() { |
92
|
|
|
$this->page_admin_scripts(); // Delegate to inheriting class |
93
|
|
|
add_action( 'admin_footer', array( $this->jetpack, 'do_stats' ) ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// Enqueue the Jetpack admin stylesheet |
97
|
|
View Code Duplication |
function admin_styles() { |
98
|
|
|
$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
99
|
|
|
|
100
|
|
|
wp_enqueue_style( 'jetpack-admin', plugins_url( "css/jetpack-admin{$min}.css", JETPACK__PLUGIN_FILE ), array( 'genericons' ), JETPACK__VERSION . '-20121016' ); |
101
|
|
|
wp_style_add_data( 'jetpack-admin', 'rtl', 'replace' ); |
102
|
|
|
wp_style_add_data( 'jetpack-admin', 'suffix', $min ); |
103
|
|
|
|
104
|
|
|
$this->additional_styles(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
function is_wp_version_too_old() { |
108
|
|
|
global $wp_version; |
109
|
|
|
return ( ! function_exists( 'rest_api_init' ) || version_compare( $wp_version, '4.4-z', '<=' ) ); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: