|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Admin Page Framework |
|
4
|
|
|
* |
|
5
|
|
|
* http://en.michaeluno.jp/admin-page-framework/ |
|
6
|
|
|
* Copyright (c) 2013-2016 Michael Uno; Licensed MIT |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* The factory class that creates network admin pages. |
|
12
|
|
|
* |
|
13
|
|
|
* @abstract |
|
14
|
|
|
* @since 3.1.0 |
|
15
|
|
|
* @remark This class stems from several abstract classes. |
|
16
|
|
|
* @extends AdminPageFramework |
|
17
|
|
|
* @package AdminPageFramework |
|
18
|
|
|
* @subpackage NetworkAdmin |
|
19
|
|
|
*/ |
|
20
|
|
|
abstract class AdminPageFramework_NetworkAdmin extends AdminPageFramework { |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Defines the class object structure type. |
|
24
|
|
|
* |
|
25
|
|
|
* @since 3.7.12 |
|
26
|
|
|
* @internal |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $_sStructureType = 'network_admin_page'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Used to refer the built-in root menu slugs. |
|
32
|
|
|
* |
|
33
|
|
|
* @since 3.1.0 |
|
34
|
|
|
* @remark Not for the user. |
|
35
|
|
|
* @var array Holds the built-in root menu slugs. |
|
36
|
|
|
* @internal |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $_aBuiltInRootMenuSlugs = array( |
|
39
|
|
|
// All keys must be lower case to support case insensitive look-ups. |
|
40
|
|
|
'dashboard' => 'index.php', |
|
41
|
|
|
'sites' => 'sites.php', // not work |
|
42
|
|
|
'themes' => 'themes.php', // not work |
|
43
|
|
|
'plugins' => 'plugins.php', |
|
44
|
|
|
'users' => 'users.php', |
|
45
|
|
|
'settings' => 'settings.php', |
|
46
|
|
|
'updates' => 'update-core.php', // does not work |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Registers necessary callbacks ans sets up internal components including properties. |
|
51
|
|
|
* |
|
52
|
|
|
* <h4>Example</h4> |
|
53
|
|
|
* <code>if ( is_admin() ) |
|
54
|
|
|
* new MyAdminPageClass( 'my_custom_option_key', __FILE__ );</code> |
|
55
|
|
|
* |
|
56
|
|
|
* @access public |
|
57
|
|
|
* @since 3.1.0 |
|
58
|
|
|
* @see http://codex.wordpress.org/Roles_and_Capabilities |
|
59
|
|
|
* @see http://codex.wordpress.org/I18n_for_WordPress_Developers#Text_Domains |
|
60
|
|
|
* @param string $sOptionKey (optional) specifies the option key name to store in the options table. If this is not set, the instantiated class name will be used. |
|
61
|
|
|
* @param string $sCallerPath (optional) used to retrieve the plugin/theme details to auto-insert the information into the page footer. |
|
62
|
|
|
* @param string $sCapability (optional) sets the overall access level to the admin pages created by the framework. The used capabilities are listed <a href="http://codex.wordpress.org/Roles_and_Capabilities">here</a>. The capability can be set per page, tab, setting section, setting field. Default: `manage_options.` |
|
63
|
|
|
* @param string $sTextDomain (optional) the <a href="http://codex.wordpress.org/I18n_for_WordPress_Developers#Text_Domains" target="_blank">text domain</a> used for the framework's system messages. Default: `admin-page-framework`. |
|
64
|
|
|
* @return void returns nothing. |
|
|
|
|
|
|
65
|
|
|
*/ |
|
66
|
|
|
public function __construct( $sOptionKey=null, $sCallerPath=null, $sCapability='manage_network', $sTextDomain='admin-page-framework' ){ |
|
67
|
|
|
|
|
68
|
|
|
if ( ! $this->_isInstantiatable() ) { |
|
69
|
|
|
return; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$sCallerPath = $sCallerPath |
|
73
|
|
|
? $sCallerPath |
|
74
|
|
|
: AdminPageFramework_Utility::getCallerScriptPath( __FILE__ ); // this is important to attempt to find the caller script path here when separating the library into multiple files. |
|
75
|
|
|
|
|
76
|
|
|
// $_sProprtyClassName = $this->aSubClassNames[ 'oProp' ] |
|
77
|
|
|
// ? $this->aSubClassNames[ 'oProp' ] |
|
78
|
|
|
// : 'AdminPageFramework_Property_' . $this->_sStructureType; |
|
79
|
|
|
|
|
80
|
|
|
// $this->oProp = new $_sProprtyClassName( |
|
81
|
|
|
// $this, |
|
82
|
|
|
// $sCallerPath, |
|
83
|
|
|
// get_class( $this ), |
|
84
|
|
|
// $sOptionKey, |
|
85
|
|
|
// $sCapability, |
|
86
|
|
|
// $sTextDomain, |
|
87
|
|
|
// $this->_sStructureType |
|
88
|
|
|
// ); |
|
89
|
|
|
|
|
90
|
|
|
parent::__construct( $sOptionKey, $sCallerPath, $sCapability, $sTextDomain ); |
|
91
|
|
|
|
|
92
|
|
|
new AdminPageFramework_Model_Menu__RegisterMenu( $this, 'network_admin_menu' ); |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Instantiates a link object based on the type. |
|
98
|
|
|
* |
|
99
|
|
|
* @since 3.7.10 |
|
100
|
|
|
* @internal |
|
101
|
|
|
* @return null|object |
|
102
|
|
|
*/ |
|
103
|
|
|
protected function _getLinkObject() { |
|
104
|
|
|
$_sClassName = $this->aSubClassNames[ 'oLink' ]; |
|
105
|
|
|
return new $_sClassName( $this->oProp, $this->oMsg ); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Instantiates a link object based on the type. |
|
110
|
|
|
* |
|
111
|
|
|
* @since 3.7.10 |
|
112
|
|
|
* @internal |
|
113
|
|
|
* @return null|object |
|
114
|
|
|
*/ |
|
115
|
|
|
protected function _getPageLoadObject() { |
|
116
|
|
|
$_sClassName = $this->aSubClassNames[ 'oPageLoadInfo' ]; |
|
117
|
|
|
return new $_sClassName( $this->oProp, $this->oMsg ); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Checks whether the class should be instantiated. |
|
122
|
|
|
* |
|
123
|
|
|
* @since 3.1.0 |
|
124
|
|
|
* @internal |
|
125
|
|
|
*/ |
|
126
|
|
|
protected function _isInstantiatable() { |
|
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
if ( isset( $GLOBALS['pagenow'] ) && 'admin-ajax.php' === $GLOBALS['pagenow'] ) { |
|
129
|
|
|
return false; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
// Nothing to do in the non-network admin area. |
|
133
|
|
|
if ( is_network_admin() ) { |
|
134
|
|
|
return true; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
return false; |
|
138
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Retrieves the saved option value from the given option key and the dimensional array key representation. |
|
144
|
|
|
* |
|
145
|
|
|
* <h4>Example</h4> |
|
146
|
|
|
* <code> |
|
147
|
|
|
* $aData = AdminPageFramework::getOption( 'APF' ); |
|
148
|
|
|
* $aSection = AdminPageFramework::getOption( 'APF', 'my_section' ); |
|
149
|
|
|
* $sText = AdminPageFramework::getOption( 'APF', array( 'my_section', 'my_text_field' ), 'foo' ); |
|
150
|
|
|
* $sColor = AdminPageFramework::getOption( 'APF', 'my_color_field', '#FFF' ); |
|
151
|
|
|
* </code> |
|
152
|
|
|
* |
|
153
|
|
|
* @since 3.1.0 |
|
154
|
|
|
* @param string $sOptionKey the option key of the options table. |
|
155
|
|
|
* @param string $asKey the representation of dimensional array keys. If the returning option structure is like the following, |
|
156
|
|
|
* <code> |
|
157
|
|
|
* array( |
|
158
|
|
|
* 'a' => array( |
|
159
|
|
|
* 'b' => array( |
|
160
|
|
|
* 'c' => 'ccc', |
|
161
|
|
|
* ), |
|
162
|
|
|
* ), |
|
163
|
|
|
* ) |
|
164
|
|
|
* </code> |
|
165
|
|
|
* then the value 'ccc' can be retrieved with the key representation array of |
|
166
|
|
|
* <code> |
|
167
|
|
|
* array( 'a', 'b', 'c' ) |
|
168
|
|
|
* </code> |
|
169
|
|
|
* @param mixed $vDefault the default value that will be returned if nothing is stored. |
|
170
|
|
|
* @return mixed If the field ID is not specified. |
|
171
|
|
|
*/ |
|
172
|
|
|
static public function getOption( $sOptionKey, $asKey=null , $vDefault=null ) { |
|
|
|
|
|
|
173
|
|
|
return AdminPageFramework_WPUtility::getSiteOption( $sOptionKey, $asKey, $vDefault ); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
} |
|
177
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.