Completed
Push — update/admin-module-options-im... ( 75e9da...bb6abb )
by
unknown
10:07
created

Jetpack_Admin_Page::is_wp_version_too_old()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 3
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 4
rs 10
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
	function __construct() {
18
		$this->jetpack = Jetpack::init();
0 ignored issues
show
Bug introduced by
The property jetpack does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
	}
20
21
	function add_actions() {
22
		/**
23
		 * Don't add in the modules page unless modules are available!
24
		 */
25
		if ( $this->dont_show_if_not_active && ! Jetpack::is_active() && ! Jetpack::is_development_mode() ) {
0 ignored issues
show
Bug introduced by
The property dont_show_if_not_active does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26
			return;
27
		}
28
29
		// Initialize menu item for the page in the admin
30
		$hook = $this->get_page_hook();
31
32
		// Attach hooks common to all Jetpack admin pages based on the created
33
		// hook
34
		add_action( "load-$hook",                array( $this, 'admin_help'      ) );
35
		add_action( "load-$hook",                array( $this, 'admin_page_load' ) );
36
		add_action( "admin_head-$hook",          array( $this, 'admin_head'      ) );
37
38
		add_action( "admin_footer-$hook",        array( $this, 'module_modal_js_template' ) );
39
40
		add_action( "admin_print_styles-$hook",  array( $this, 'admin_styles'    ) );
41
		add_action( "admin_print_scripts-$hook", array( $this, 'admin_scripts'   ) );
42
43
		// Attach page specific actions in addition to the above
44
		$this->add_page_actions( $hook );
45
	}
46
47
	function admin_head() {
48 View Code Duplication
		if ( isset( $_GET['configure'] ) && Jetpack::is_module( $_GET['configure'] ) && current_user_can( 'manage_options' ) ) {
49
			/**
50
			 * Fires in the <head> of a particular Jetpack configuation page.
51
			 *
52
			 * The dynamic portion of the hook name, `$_GET['configure']`,
53
			 * refers to the slug of module, such as 'stats', 'sso', etc.
54
			 * A complete hook for the latter would be
55
			 * 'jetpack_module_configuation_head_sso'.
56
			 *
57
			 * @since 3.0.0
58
			 */
59
			do_action( 'jetpack_module_configuration_head_' . $_GET['configure'] );
60
		}
61
	}
62
63
	// Render the page with a common top and bottom part, and page specific
64
	// content
65
	function render() {
66
//		$this->admin_page_top();
67
		$this->page_render();
68
//		$this->admin_page_bottom();
69
	}
70
71
	function admin_help() {
72
		$this->jetpack->admin_help();
73
	}
74
75
	function admin_page_load() {
76
		// This is big.  For the moment, just call the existing one.
77
		$this->jetpack->admin_page_load();
78
	}
79
80
	// Load underscore template for the landing page and settings page modal
81
	function module_modal_js_template() {
82
		Jetpack::init()->load_view( 'admin/module-modal-template.php' );
83
	}
84
85
	function admin_page_top() {
86
		include_once( JETPACK__PLUGIN_DIR . '_inc/header.php' );
87
	}
88
89
	function admin_page_bottom() {
90
		include_once( JETPACK__PLUGIN_DIR . '_inc/footer.php' );
91
	}
92
93
	// Add page specific scripts and jetpack stats for all menu pages
94
	function admin_scripts() {
95
		$this->page_admin_scripts(); // Delegate to inheriting class
96
		add_action( 'admin_footer', array( $this->jetpack, 'do_stats' ) );
97
	}
98
99
	// Enqueue the Jetpack admin stylesheet
100 View Code Duplication
	function admin_styles() {
101
		$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
102
103
		wp_enqueue_style( 'jetpack-admin', plugins_url( "css/jetpack-admin{$min}.css", JETPACK__PLUGIN_FILE ), array( 'genericons' ), JETPACK__VERSION . '-20121016' );
104
		wp_style_add_data( 'jetpack-admin', 'rtl', 'replace' );
105
		wp_style_add_data( 'jetpack-admin', 'suffix', $min );
106
	}
107
108
	function is_wp_version_too_old() {
109
		global $wp_version;
110
		return ( ! function_exists( 'rest_api_init' ) || version_compare( $wp_version, '4.4-z', '<=' ) );
111
	}
112
}
113