Completed
Push — master ( 48986a...95c69f )
by David
06:07
created

Wordlift_Admin_Page::admin_menu()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Created by PhpStorm.
5
 * User: david
6
 * Date: 20/02/2017
7
 * Time: 17:12
8
 */
9
abstract class Wordlift_Admin_Page {
10
11
	/**
12
	 * Get the parent slug.
13
	 *
14
	 * @since 3.11.0
15
	 *
16
	 * @return string The parent slug
17
	 */
18
	abstract function get_parent_slug();
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
19
20
	/**
21
	 * Get the required capability
22
	 *
23
	 * @since 3.11.0
24
	 *
25
	 * @return string The capability.
26
	 */
27
	abstract function get_capability();
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
28
29
	/**
30
	 * Get the page title. Will be translated.
31
	 *
32
	 * @since 3.11.0
33
	 *
34
	 * @return string The page title.
35
	 */
36
	abstract function get_page_title();
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
37
38
	/**
39
	 * Get the menu title. Will be translated.
40
	 *
41
	 * @since 3.11.0
42
	 *
43
	 * @return string The menu title.
44
	 */
45
	abstract function get_menu_title();
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
46
47
	/**
48
	 * Get the menu slug.
49
	 *
50
	 * @since 3.11.0
51
	 *
52
	 * @return string The menu slug.
53
	 */
54
	abstract function get_menu_slug();
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
55
56
	/**
57
	 * Get the partial file name, used in the {@link render} function.
58
	 *
59
	 * @since 3.11.0
60
	 *
61
	 * @return string The partial file name.
62
	 */
63
	abstract function get_partial_name();
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
64
65
	/**
66
	 * The `admin_menu` callback. Will call {@link add_submenu_page} to add the
67
	 * page to the admin menu.
68
	 *
69
	 * @since 3.11.0
70
	 *
71
	 * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required.
72
	 */
73
	public function admin_menu() {
74
75
		// Add the sub-menu page.
76
		//
77
		// See http://codex.wordpress.org/Function_Reference/add_submenu_page
78
		$page = add_submenu_page(
79
			$this->get_parent_slug(),
80
			$this->get_page_title(),
81
			$this->get_menu_title(),
82
			$this->get_capability(),                   // The required capability, provided by the calling hook.
83
			$this->get_menu_slug(),
84
			array( $this, 'render' )
85
		);
86
87
		// Set a hook to enqueue scripts only when the settings page is displayed.
88
		add_action( 'admin_print_scripts-' . $page, array(
89
			$this,
90
			'enqueue_scripts',
91
		) );
92
93
		// Finally return the page hook_suffix.
94
		return $page;
95
	}
96
97
	/**
98
	 * Enqueue scripts for the specific page. Subclasses can override this function
99
	 * to provide their own styles/scripts.
100
	 *
101
	 * @since 3.11.0
102
	 */
103
	public function enqueue_scripts() {
104
	}
105
106
	/**
107
	 * Render the page.
108
	 */
109
	public function render() {
110
111
		// Include the partial.
112
		include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name() );
113
114
	}
115
116
}
117