|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* One of the abstract class of the plugin admin page class. |
|
4
|
|
|
* |
|
5
|
|
|
* @package Admin Page Framework Loader |
|
6
|
|
|
* @copyright Copyright (c) 2014, Michael Uno |
|
7
|
|
|
* @author Michael Uno |
|
8
|
|
|
* @authorurl http://michaeluno.jp |
|
9
|
|
|
* @since 3.5.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
class AdminPageFrameworkLoader_AdminPage extends AdminPageFramework { |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* User constructor. |
|
16
|
|
|
* |
|
17
|
|
|
* @since 3.5.0 |
|
18
|
|
|
*/ |
|
19
|
1 |
|
public function start() { |
|
20
|
|
|
|
|
21
|
1 |
|
if ( ! $this->oProp->bIsAdmin ) { |
|
22
|
1 |
|
return; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
// Allows the user to switch the menu visibility. |
|
26
|
|
|
if ( isset( $_GET['enable_apfl_admin_pages'] ) ) { |
|
27
|
|
|
|
|
28
|
|
|
// Update the options and reload the page |
|
29
|
|
|
$_oOption = AdminPageFrameworkLoader_Option::getInstance( AdminPageFrameworkLoader_Registry::$aOptionKeys[ 'main' ] ); |
|
30
|
|
|
$_oOption->update( 'enable_admin_pages', ( boolean ) $_GET[ 'enable_apfl_admin_pages' ] ); |
|
31
|
|
|
|
|
32
|
|
|
$this->oUtil->goToLocalURL( |
|
33
|
|
|
remove_query_arg( 'enable_apfl_admin_pages' ), |
|
34
|
|
|
array( 'AdminPageFrameworkLoader_Utility', 'replyToShowRedirectError' ) |
|
35
|
|
|
); |
|
36
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
// Enable / disable the demo pages |
|
40
|
|
|
if ( isset( $_GET[ 'enable_apfl_demo_pages' ] ) ) { |
|
41
|
|
|
|
|
42
|
|
|
// Update the options and reload the page |
|
43
|
|
|
$_oOption = AdminPageFrameworkLoader_Option::getInstance( AdminPageFrameworkLoader_Registry::$aOptionKeys[ 'main' ] ); |
|
44
|
|
|
$_oOption->update( 'enable_demo', ( boolean ) $_GET[ 'enable_apfl_demo_pages' ] ); |
|
45
|
|
|
|
|
46
|
|
|
if ( $_GET[ 'enable_apfl_demo_pages' ] ) { |
|
47
|
|
|
$this->setSettingNotice( |
|
48
|
|
|
__( 'Enabled demo!', 'admin-page-framework-loader' ), |
|
49
|
|
|
'updated' |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$this->oUtil->goToLocalURL( |
|
54
|
|
|
remove_query_arg( 'enable_apfl_demo_pages' ), |
|
55
|
|
|
array( 'AdminPageFrameworkLoader_Utility', 'replyToShowRedirectError' ) |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Sets up admin pages. |
|
64
|
|
|
* |
|
65
|
|
|
* @since 3.5.0 |
|
66
|
|
|
*/ |
|
67
|
|
|
public function setUp() { |
|
68
|
|
|
|
|
69
|
|
|
$_aOptions = $this->oProp->aOptions; |
|
70
|
|
|
$_bAdminPageEnabled = ! is_array( $_aOptions ) // for the first time of loading, the option is not set and it is not an array. |
|
71
|
|
|
|| ( isset( $_aOptions['enable_admin_pages'] ) && $_aOptions['enable_admin_pages'] ); |
|
72
|
|
|
|
|
73
|
|
|
// Set up pages |
|
74
|
|
|
if ( $_bAdminPageEnabled ) { |
|
75
|
|
|
|
|
76
|
|
|
$this->setRootMenuPage( |
|
77
|
|
|
AdminPageFrameworkLoader_Registry::SHORTNAME, // menu slug |
|
78
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/image/wp-logo_16x16.png', // menu icon |
|
79
|
|
|
4 // menu position |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
// Add pages |
|
83
|
|
|
new AdminPageFrameworkLoader_AdminPage_Tool( |
|
84
|
|
|
$this, |
|
85
|
|
|
array( |
|
86
|
|
|
'page_slug' => AdminPageFrameworkLoader_Registry::$aAdminPages[ 'tool' ], |
|
87
|
|
|
'title' => __( 'Tools', 'admin-page-framework-loader' ), |
|
88
|
|
|
'style' => array( |
|
89
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/css/code.css', |
|
90
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/css/admin.css' |
|
91
|
|
|
), |
|
92
|
|
|
) |
|
93
|
|
|
); |
|
94
|
|
|
new AdminPageFrameworkLoader_AdminPage_Addon( |
|
95
|
|
|
$this, |
|
96
|
|
|
array( |
|
97
|
|
|
'page_slug' => AdminPageFrameworkLoader_Registry::$aAdminPages[ 'addon' ], // page slug |
|
98
|
|
|
'title' => __( 'Add Ons', 'admin-page-framework-loader' ), |
|
99
|
|
|
'style' => array( |
|
100
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/css/code.css', |
|
101
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/css/admin.css' |
|
102
|
|
|
), |
|
103
|
|
|
) |
|
104
|
|
|
); |
|
105
|
|
|
new AdminPageFrameworkLoader_AdminPage_Help( |
|
106
|
|
|
$this, |
|
107
|
|
|
array( |
|
108
|
|
|
'page_slug' => AdminPageFrameworkLoader_Registry::$aAdminPages[ 'help' ], |
|
109
|
|
|
'title' => __( 'Help', 'admin-page-framework-loader' ), |
|
110
|
|
|
'order' => 1000, // to be the last menu item |
|
111
|
|
|
'style' => array( |
|
112
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/css/code.css', |
|
113
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/css/admin.css' |
|
114
|
|
|
), |
|
115
|
|
|
) |
|
116
|
|
|
); |
|
117
|
|
|
|
|
118
|
|
|
add_action( 'load_' . $this->oProp->sClassName, array( $this, 'replyToDoPageSettings' ) ); |
|
119
|
|
|
|
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$this->_addActionLinks( $_bAdminPageEnabled, $_aOptions ); |
|
123
|
|
|
|
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Does page settings. |
|
128
|
|
|
*/ |
|
129
|
|
|
private function _addActionLinks( $_bAdminPageEnabled, $_aOptions ) { |
|
130
|
|
|
|
|
131
|
|
|
if ( 'plugins.php' !== $this->oProp->sPageNow ) { |
|
132
|
|
|
return; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
// Action Links |
|
136
|
|
|
|
|
137
|
|
|
$this->setPluginSettingsLinkLabel( '' ); |
|
138
|
|
|
$this->addLinkToPluginTitle( |
|
139
|
|
|
$this->_getAdminURLTools( $_bAdminPageEnabled ), |
|
140
|
|
|
$this->_getAdminPageSwitchLink( $_bAdminPageEnabled ), |
|
141
|
|
|
$this->_getDemoSwitcherLink( $_bAdminPageEnabled, $_aOptions ) |
|
142
|
|
|
); |
|
143
|
|
|
$this->addLinkToPluginDescription( |
|
144
|
|
|
"<a href='https://wordpress.org/support/plugin/admin-page-framework' target='_blank'>" |
|
145
|
|
|
. __( 'Support', 'admin-page-framework-loader' ) |
|
146
|
|
|
. "</a>" |
|
147
|
|
|
); |
|
148
|
|
|
|
|
149
|
|
|
} |
|
150
|
|
|
/** |
|
151
|
|
|
* Returns the Tools admin page link. |
|
152
|
|
|
* @return string |
|
153
|
|
|
*/ |
|
154
|
|
|
private function _getAdminURLTools( $_bAdminPageEnabled ) { |
|
155
|
|
|
if ( ! $_bAdminPageEnabled ) { |
|
156
|
|
|
return; |
|
157
|
|
|
} |
|
158
|
|
|
$_sLink = esc_url( |
|
159
|
|
|
add_query_arg( |
|
160
|
|
|
array( |
|
161
|
|
|
'page' => AdminPageFrameworkLoader_Registry::$aAdminPages['tool'], |
|
162
|
|
|
), |
|
163
|
|
|
admin_url( 'admin.php' ) |
|
164
|
|
|
) |
|
165
|
|
|
); |
|
166
|
|
|
return "<a href='{$_sLink}'>" . __( 'Tools', 'admin-page-framework-loader' ) . "</a>"; |
|
167
|
|
|
} |
|
168
|
|
|
/** |
|
169
|
|
|
* Returns the Enable /Disable Admin Pages link. |
|
170
|
|
|
*/ |
|
171
|
|
|
private function _getAdminPageSwitchLink( $bEnabled ) { |
|
172
|
|
|
$_sLink = esc_url( |
|
173
|
|
|
add_query_arg( |
|
174
|
|
|
array( |
|
175
|
|
|
'enable_apfl_admin_pages' => $bEnabled ? 0 : 1, |
|
176
|
|
|
) |
|
177
|
|
|
) |
|
178
|
|
|
); |
|
179
|
|
|
return $bEnabled |
|
180
|
|
|
? "<a href='{$_sLink}'>" . __( 'Disable Admin Pages', 'admin-page-framework-loader' ) . "</a>" |
|
181
|
|
|
: "<a href='{$_sLink}'>" . __( 'Enable Admin Pages', 'admin-page-framework-loader' ) . "</a>"; |
|
182
|
|
|
} |
|
183
|
|
|
/** |
|
184
|
|
|
* Returns the switch link of the demo pages. |
|
185
|
|
|
*/ |
|
186
|
|
|
private function _getDemoSwitcherLink( $_bAdminPageEnabled, $mOptions=array() ) { |
|
187
|
|
|
|
|
188
|
|
|
if ( ! $_bAdminPageEnabled ) { |
|
189
|
|
|
return ''; |
|
190
|
|
|
} |
|
191
|
|
|
$_bEnabled = isset( $mOptions['enable_demo'] ) && $mOptions['enable_demo']; |
|
192
|
|
|
$_sLink = esc_url( |
|
193
|
|
|
add_query_arg( |
|
194
|
|
|
array( |
|
195
|
|
|
'enable_apfl_demo_pages' => $_bEnabled ? 0 : 1, |
|
196
|
|
|
) |
|
197
|
|
|
) |
|
198
|
|
|
); |
|
199
|
|
|
return $_bEnabled |
|
200
|
|
|
? "<a href='{$_sLink}'>" . __( 'Disable Demo', 'admin-page-framework-loader' ) . "</a>" |
|
201
|
|
|
: "<a href='{$_sLink}'><strong id='activate-demo-action-link' style='font-size: 1em;'>" . __( 'Enable Demo', 'admin-page-framework-loader' ) . "</strong></a>"; |
|
202
|
|
|
|
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @return void |
|
207
|
|
|
* @callback action load_{class name} |
|
208
|
|
|
*/ |
|
209
|
|
|
public function replyToDoPageSettings( /* $oFactory */ ) { |
|
210
|
|
|
|
|
211
|
|
|
$this->setPageHeadingTabsVisibility( false ); // disables the page heading tabs by passing false. |
|
212
|
|
|
$this->setInPageTabTag( 'h2' ); // sets the tag used for in-page tabs |
|
213
|
|
|
$this->setPageTitleVisibility( false ); // disable the page title of a specific page. |
|
214
|
|
|
|
|
215
|
|
|
// Page meta boxes |
|
216
|
|
|
new AdminPageFrameworkLoader_AdminPageMetaBox_Notification( |
|
217
|
|
|
null, // meta box id - passing null will make it auto generate |
|
218
|
|
|
__( 'Notification', 'admin-page-framework-loader' ), // title |
|
219
|
|
|
array( // page slugs |
|
220
|
|
|
AdminPageFrameworkLoader_Registry::$aAdminPages[ 'tool' ], |
|
221
|
|
|
AdminPageFrameworkLoader_Registry::$aAdminPages[ 'addon' ], |
|
222
|
|
|
AdminPageFrameworkLoader_Registry::$aAdminPages[ 'help' ], |
|
223
|
|
|
), |
|
224
|
|
|
'side', // context |
|
225
|
|
|
'default' // priority |
|
226
|
|
|
); |
|
227
|
|
|
|
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
} |
|
231
|
|
|
|