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
|
|
|
* Provides methods for creating meta boxes in pages added by the framework. |
12
|
|
|
* |
13
|
|
|
* @abstract |
14
|
|
|
* @since 3.0.0 |
15
|
|
|
* @package AdminPageFramework |
16
|
|
|
* @subpackage PageMetaBox |
17
|
|
|
*/ |
18
|
|
|
abstract class AdminPageFramework_PageMetaBox extends AdminPageFramework_PageMetaBox_Controller { |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Defines the class object structure type. |
22
|
|
|
* |
23
|
|
|
* This is used to create a property object as well as to define the form element structure. |
24
|
|
|
* |
25
|
|
|
* @since 3.0.0 |
26
|
|
|
* @since 3.7.0 Changed the name from `$_sPropertyType`. |
27
|
|
|
* @since 3.7.12 Moved from `AdminPageFramework_PageMetaBox_Model`. |
28
|
|
|
* @internal |
29
|
|
|
*/ |
30
|
|
|
protected $_sStructureType = 'page_meta_box'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Registers necessary hooks and internal properties. |
34
|
|
|
* |
35
|
|
|
* <h4>Examples</h4> |
36
|
|
|
* <code> |
37
|
|
|
* new APF_MetaBox_For_Pages_Normal( |
38
|
|
|
* 'apf_metabox_for_pages_normal', // meta box id |
39
|
|
|
* __( 'Sample Meta Box For Admin Pages Inserted in Normal Area' ), // title |
40
|
|
|
* 'apf_first_page', // page slugs |
41
|
|
|
* 'normal', // context |
42
|
|
|
* 'default' // priority |
43
|
|
|
* ); |
44
|
|
|
* include( APFDEMO_DIRNAME . '/example/APF_MetaBox_For_Pages_Advanced.php' ); |
45
|
|
|
* new APF_MetaBox_For_Pages_Advanced( |
46
|
|
|
* 'apf_metabox_for_pages_advanced', // meta box id |
47
|
|
|
* __( 'Sample Meta Box For Admin Pages Inserted in Advanced Area' ), // title |
48
|
|
|
* 'apf_first_page', // page slugs |
49
|
|
|
* 'advanced', // context |
50
|
|
|
* 'default' // priority |
51
|
|
|
* ); |
52
|
|
|
* include( APFDEMO_DIRNAME . '/example/APF_MetaBox_For_Pages_Side.php' ); |
53
|
|
|
* new APF_MetaBox_For_Pages_Side( |
54
|
|
|
* 'apf_metabox_for_pages_side', // meta box id |
55
|
|
|
* __( 'Sample Meta Box For Admin Pages Inserted in Advanced Area' ), // title |
56
|
|
|
* array( 'apf_first_page', 'apf_second_page' ), // page slugs - setting multiple slugs is possible |
57
|
|
|
* 'side', // context |
58
|
|
|
* 'default' // priority |
59
|
|
|
* ); |
60
|
|
|
* </code> |
61
|
|
|
* @since 3.0.0 |
62
|
|
|
* |
63
|
|
|
* @param string $sMetaBoxID The meta box ID to be created. |
64
|
|
|
* @param string $sTitle The meta box title. |
65
|
|
|
* @param array|string $asPageSlugs the page slug(s) that the meta box belongs to. If the element is an array, it will be considered as a tab array. |
66
|
|
|
* <code> |
67
|
|
|
* $asPageSlugs = array( |
68
|
|
|
* 'settings' => array( // if the key is not numeric and the value is an array, it will be considered as a tab array. |
69
|
|
|
* 'help', // enabled in the tab whose slug is 'help' which belongs to the page whose slug is 'settings' |
70
|
|
|
* 'about', // enabled in the tab whose slug is 'about' which belongs to the page whose slug is 'settings' |
71
|
|
|
* 'general', // enabled in the tab whose slug is 'general' which belongs to the page whose slug is 'settings' |
72
|
|
|
* ), |
73
|
|
|
* 'manage', // if the numeric key with a string value is given, the condition applies to the page slug of this string value. |
74
|
|
|
* ); |
75
|
|
|
* </code> |
76
|
|
|
* @param string $sContext The context, either `normal`, `advanced`, or `side`. |
77
|
|
|
* @param string $sPriority The priority, either `high`, `core`, `default` or `low`. |
78
|
|
|
* @param string $sCapability The capability. See <a href="https://codex.wordpress.org/Roles_and_Capabilities" target="_blank">Roles and Capabilities</a>. |
79
|
|
|
*/ |
80
|
|
|
public function __construct( $sMetaBoxID, $sTitle, $asPageSlugs=array(), $sContext='normal', $sPriority='default', $sCapability='manage_options', $sTextDomain='admin-page-framework' ) { |
81
|
|
|
|
82
|
|
|
if ( empty( $asPageSlugs ) ) { |
83
|
|
|
return; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if ( ! $this->_isInstantiatable() ) { |
87
|
|
|
return; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
// The property object needs to be done first before the parent constructor. |
91
|
|
|
$_sProprtyClassName = isset( $this->aSubClassNames[ 'oProp' ] ) |
92
|
|
|
? $this->aSubClassNames[ 'oProp' ] |
93
|
|
|
: 'AdminPageFramework_Property_' . $this->_sStructureType; |
94
|
|
|
$this->oProp = new $_sProprtyClassName( |
95
|
|
|
$this, |
96
|
|
|
get_class( $this ), |
97
|
|
|
$sCapability, |
98
|
|
|
$sTextDomain, |
99
|
|
|
$this->_sStructureType |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
// This property item must be set before the isInThePage() method is used. |
103
|
|
|
$this->oProp->aPageSlugs = is_string( $asPageSlugs ) |
104
|
|
|
? array( $asPageSlugs ) |
105
|
|
|
: $asPageSlugs; |
106
|
|
|
|
107
|
|
|
parent::__construct( |
108
|
|
|
$sMetaBoxID, |
109
|
|
|
$sTitle, |
110
|
|
|
$asPageSlugs, |
|
|
|
|
111
|
|
|
$sContext, |
112
|
|
|
$sPriority, |
113
|
|
|
$sCapability, |
114
|
|
|
$sTextDomain |
115
|
|
|
); |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.