|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Wordlift\Wordpress; |
|
4
|
|
|
|
|
5
|
|
|
abstract class Submenu_Page_Base implements Page { |
|
6
|
|
|
/** |
|
7
|
|
|
* @var string |
|
8
|
|
|
*/ |
|
9
|
|
|
private $menu_slug; |
|
10
|
|
|
/** |
|
11
|
|
|
* @var string |
|
12
|
|
|
*/ |
|
13
|
|
|
private $page_title; |
|
14
|
|
|
/** |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
private $capability; |
|
18
|
|
|
/** |
|
19
|
|
|
* @var string|null |
|
20
|
|
|
*/ |
|
21
|
|
|
private $parent_slug; |
|
22
|
|
|
/** |
|
23
|
|
|
* @var string|null |
|
24
|
|
|
*/ |
|
25
|
|
|
private $menu_title; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Abstract_Submenu_Page constructor. |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $menu_slug |
|
31
|
|
|
* @param string $page_title |
|
32
|
|
|
* @param string $capability |
|
33
|
|
|
* @param string|null $parent_slug |
|
34
|
|
|
* @param string|null $menu_title |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct( $menu_slug, $page_title, $capability = 'manage_options', $parent_slug = null, $menu_title = null ) { |
|
37
|
|
|
|
|
38
|
|
|
add_action( 'admin_menu', array( $this, 'admin_menu', ) ); |
|
39
|
|
|
|
|
40
|
|
|
$this->menu_slug = $menu_slug; |
|
41
|
|
|
$this->page_title = $page_title; |
|
42
|
|
|
$this->capability = $capability; |
|
43
|
|
|
$this->parent_slug = $parent_slug; |
|
44
|
|
|
$this->menu_title = isset( $menu_title ) ? $menu_title : $page_title; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function get_menu_slug() { |
|
48
|
|
|
|
|
49
|
|
|
return $this->menu_slug; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* The `admin_menu` callback. Will call {@link add_submenu_page} to add the |
|
54
|
|
|
* page to the admin menu. |
|
55
|
|
|
* |
|
56
|
|
|
* @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
57
|
|
|
* @since 1.0.0 |
|
58
|
|
|
* |
|
59
|
|
|
*/ |
|
60
|
|
|
public function admin_menu() { |
|
61
|
|
|
|
|
62
|
|
|
// Add the sub-menu page. |
|
63
|
|
|
// |
|
64
|
|
|
// See http://codex.wordpress.org/Function_Reference/add_submenu_page |
|
65
|
|
|
$page = add_submenu_page( |
|
66
|
|
|
$this->parent_slug, |
|
67
|
|
|
$this->page_title, |
|
68
|
|
|
$this->menu_title, |
|
69
|
|
|
$this->capability, |
|
70
|
|
|
$this->menu_slug, |
|
71
|
|
|
array( $this, 'render' ) |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
// Set a hook to enqueue scripts only when the settings page is displayed. |
|
75
|
|
|
add_action( 'admin_print_scripts-' . $page, array( $this, 'enqueue_scripts', ) ); |
|
76
|
|
|
|
|
77
|
|
|
// Finally return the page hook_suffix. |
|
78
|
|
|
return $page; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
abstract function enqueue_scripts(); |
|
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
abstract function render(); |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.