Completed
Push — clean/php-inc/lib ( 3d8350...a85902 )
by
unknown
90:45 queued 81:07
created

Jetpack_Admin_Page::admin_page_bottom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
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 content
64
	function render() {
65
		$this->page_render();
66
	}
67
68
	function admin_help() {
69
		$this->jetpack->admin_help();
70
	}
71
72
	function admin_page_load() {
73
		// This is big.  For the moment, just call the existing one.
74
		$this->jetpack->admin_page_load();
75
	}
76
77
	function admin_page_top() {
78
		include_once( JETPACK__PLUGIN_DIR . '_inc/header.php' );
79
	}
80
81
	function admin_page_bottom() {
82
		include_once( JETPACK__PLUGIN_DIR . '_inc/footer.php' );
83
	}
84
85
	// Add page specific scripts and jetpack stats for all menu pages
86
	function admin_scripts() {
87
		$this->page_admin_scripts(); // Delegate to inheriting class
88
		add_action( 'admin_footer', array( $this->jetpack, 'do_stats' ) );
89
	}
90
91
	// Enqueue the Jetpack admin stylesheet
92 View Code Duplication
	function admin_styles() {
93
		$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
94
95
		wp_enqueue_style( 'jetpack-admin', plugins_url( "css/jetpack-admin{$min}.css", JETPACK__PLUGIN_FILE ), array( 'genericons' ), JETPACK__VERSION . '-20121016' );
96
		wp_style_add_data( 'jetpack-admin', 'rtl', 'replace' );
97
		wp_style_add_data( 'jetpack-admin', 'suffix', $min );
98
	}
99
100
	function is_wp_version_too_old() {
101
		global $wp_version;
102
		return ( ! function_exists( 'rest_api_init' ) || version_compare( $wp_version, '4.4-z', '<=' ) );
103
	}
104
}
105