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 main class of the framework to be extended to create admin pages and forms. |
12
|
|
|
* |
13
|
|
|
* <p>The user defines their own class by extending this class with the `setUp()` method overridden to define admin pages.</p> |
14
|
|
|
* |
15
|
|
|
* @abstract |
16
|
|
|
* @since 2.0.0 |
17
|
|
|
* @extends AdminPageFramework_Controller |
18
|
|
|
* @package AdminPageFramework |
19
|
|
|
* @subpackage Factory/AdminPage |
20
|
|
|
* @remark Most of the internal methods are prefixed with the underscore like `_getSomething()` and callback methods are prefixed with `_reply`. |
21
|
|
|
* The methods for the users are public and do not have those prefixes. |
22
|
|
|
*/ |
23
|
|
|
abstract class AdminPageFramework extends AdminPageFramework_Controller { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Defines the class object structure type. |
27
|
|
|
* |
28
|
|
|
* This is used to create a property object as well as to define the form element structure. |
29
|
|
|
* |
30
|
|
|
* @since 3.0.0 |
31
|
|
|
* @since 3.7.0 Changed the name from `$_sFieldsType`. |
32
|
|
|
* @since 3.7.12 Moved from `AdminPageFrmework_Model_Form`. Removed the static scope. |
33
|
|
|
* @internal |
34
|
|
|
*/ |
35
|
|
|
protected $_sStructureType = 'admin_page'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Registers necessary callbacks and sets up internal components including properties. |
39
|
|
|
* |
40
|
|
|
* <h4>Example</h4> |
41
|
|
|
* <code> |
42
|
|
|
* new MyAdminPageClass( 'my_custom_option_key', __FILE__ ); |
43
|
|
|
* </code> |
44
|
|
|
* |
45
|
|
|
* @access public |
46
|
|
|
* @since 2.0.0 |
47
|
|
|
* @see http://codex.wordpress.org/Roles_and_Capabilities |
48
|
|
|
* @see http://codex.wordpress.org/I18n_for_WordPress_Developers#Text_Domains |
49
|
|
|
* @param array|integer|string $aisOptionKey (optional) specifies the option key name to store in the options table. If this is not set, the instantiated class name will be used as default. |
|
|
|
|
50
|
|
|
* [3.5.9+] If an integer is given, a transient will be used. If an array of option key arguments is given, the argument values will be set to the framework properties. |
51
|
|
|
* - type - either `options_table` or `transient`. |
52
|
|
|
* - key - the option key or the transient key |
53
|
|
|
* - duration - when the option type is transient, this value will be used for the time span to store the value in the database. |
54
|
|
|
* ` |
55
|
|
|
* array( |
56
|
|
|
* 'type' => 'options_table', |
57
|
|
|
* 'key' => 'my_admin_options', |
58
|
|
|
* ) |
59
|
|
|
* ` |
60
|
|
|
* ` |
61
|
|
|
* array( |
62
|
|
|
* 'type' => 'transient', |
63
|
|
|
* 'key' => $sTransientKeyDefinedSomewhereInYourProgram, |
64
|
|
|
* 'duration' => 60*60*24*2 // two days |
65
|
|
|
* ) |
66
|
|
|
* ` |
67
|
|
|
* @param string $sCallerPath (optional) used to retrieve the plugin/theme details to auto-insert the information into the page footer. |
68
|
|
|
* @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` |
69
|
|
|
* @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. |
70
|
|
|
*/ |
71
|
|
|
public function __construct( $isOptionKey=null, $sCallerPath=null, $sCapability='manage_options', $sTextDomain='admin-page-framework' ){ |
72
|
|
|
|
73
|
|
|
if ( ! $this->_isInstantiatable() ) { |
74
|
|
|
return; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
parent::__construct( |
78
|
|
|
$isOptionKey, |
79
|
|
|
$this->_getCallerPath( $sCallerPath ), |
80
|
|
|
$sCapability, |
81
|
|
|
$sTextDomain |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
/** |
86
|
|
|
* Returns the script caller path. |
87
|
|
|
* @remark It is important to find the caller script path here when separating the library into multiple files. |
88
|
|
|
* @return null|string |
89
|
|
|
* @since 3.8.2 |
90
|
|
|
*/ |
91
|
|
|
private function _getCallerPath( $sCallerPath ) { |
|
|
|
|
92
|
|
|
|
93
|
|
|
if ( $sCallerPath ) { |
94
|
|
|
return trim( $sCallerPath ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
if ( ! is_admin() ) { |
98
|
|
|
return null; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
if ( ! isset( $GLOBALS[ 'pagenow' ] ) ) { |
102
|
|
|
return null; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$_sCalllerPath = in_array( $GLOBALS[ 'pagenow' ], array( 'plugins.php', ) ) || isset( $_GET[ 'page' ] ) |
106
|
|
|
? AdminPageFramework_Utility::getCallerScriptPath( __FILE__ ) // not using $oUtil as this method is caller earlier than the base constructor. |
107
|
|
|
: null; |
108
|
|
|
|
109
|
|
|
return $_sCalllerPath; |
110
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.