|
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
|
|
|
/** |
|
13
|
|
|
* Constructs the Welcome admin page |
|
14
|
|
|
* |
|
15
|
|
|
* @filter apply admin_page_framework_loader_filter_admin_welcome_redirect_url Applies to the redirecting welcome url. Use this filter to disable the redirection upon plugin installation. |
|
16
|
|
|
* |
|
17
|
|
|
* @since 3.5.0 |
|
18
|
|
|
*/ |
|
19
|
|
|
class AdminPageFrameworkLoader_AdminPageWelcome extends AdminPageFramework { |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* User constructor. |
|
23
|
|
|
* |
|
24
|
|
|
* @since 3.5.0 |
|
25
|
|
|
*/ |
|
26
|
|
|
public function start() { |
|
27
|
|
|
|
|
28
|
|
|
if ( ! is_admin() ) { |
|
29
|
|
|
return; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
add_action( 'admin_menu', array( $this, '_replyToHandleRedirects' ) ); |
|
33
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
/** |
|
36
|
|
|
* Handles page redirects. |
|
37
|
|
|
* |
|
38
|
|
|
* This is called to prevent the plugin from performing the redirect when the plugin is not activated or intervene the activation process. |
|
39
|
|
|
* If this is called in the start() method above, it will redirect the user to the page during the activation process |
|
40
|
|
|
* and the user gets a page that is not created because the plugin is not activated. |
|
41
|
|
|
* |
|
42
|
|
|
* @callback action admin_menu |
|
43
|
|
|
* @since 3.5.0 |
|
44
|
|
|
* @sicne 3.5.3 Change the hook from `admin_init` as the resetting option results in an error 'You do not have permission to access this page.' |
|
45
|
|
|
*/ |
|
46
|
|
|
public function _replyToHandleRedirects() { |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
// When newly installed, the 'welcomed' value is not set. |
|
49
|
|
|
$_oOption = AdminPageFrameworkLoader_Option::getInstance(); |
|
50
|
|
|
if ( ! $_oOption->get( 'welcomed' ) ) { |
|
51
|
|
|
$this->_setInitialOptions( $_oOption, AdminPageFrameworkLoader_Registry::VERSION ); |
|
52
|
|
|
$this->_gotToWelcomePage(); // will exit |
|
53
|
|
|
} |
|
54
|
|
|
if ( $_oOption->hasUpgraded() ) { |
|
55
|
|
|
$this->_setInitialOptions( $_oOption, $_oOption->get( 'version_saved' ) ); |
|
56
|
|
|
$this->_gotToWelcomePage(); // will exit |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
/** |
|
61
|
|
|
* |
|
62
|
|
|
* @return void |
|
63
|
|
|
*/ |
|
64
|
|
|
private function _setInitialOptions( $oOption, $sVersionUpgradedFrom ) { |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
$oOption->set( 'welcomed', true ); |
|
67
|
|
|
$oOption->set( 'version_upgraded_from', $sVersionUpgradedFrom ); |
|
68
|
|
|
$oOption->set( 'version_saved', AdminPageFrameworkLoader_Registry::VERSION ); |
|
69
|
|
|
$oOption->save(); |
|
70
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
private function _gotToWelcomePage() { |
|
|
|
|
|
|
74
|
|
|
$_sWelcomePageURL = apply_filters( |
|
75
|
|
|
AdminPageFrameworkLoader_Registry::HOOK_SLUG . '_filter_admin_welcome_redirect_url', |
|
76
|
|
|
add_query_arg( |
|
77
|
|
|
array( 'page' => AdminPageFrameworkLoader_Registry::$aAdminPages['about'] ), |
|
78
|
|
|
admin_url( 'index.php' ) // Dashboard |
|
79
|
|
|
) |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
$this->oUtil->goToLocalURL( $_sWelcomePageURL ); |
|
83
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Sets up admin pages. |
|
88
|
|
|
* |
|
89
|
|
|
* @since 3.5.0 |
|
90
|
|
|
*/ |
|
91
|
|
|
public function setUp() { |
|
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
$this->sPageSlug = AdminPageFrameworkLoader_Registry::$aAdminPages['about']; |
|
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
// Root page |
|
96
|
|
|
$this->setRootMenuPage( |
|
97
|
|
|
'Dashboard' // menu slug |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
// Sub-pages |
|
101
|
|
|
$this->addSubMenuItems( |
|
102
|
|
|
array( |
|
103
|
|
|
'title' => AdminPageFrameworkLoader_Registry::SHORTNAME, |
|
104
|
|
|
'page_slug' => AdminPageFrameworkLoader_Registry::$aAdminPages[ 'about' ], // page slug |
|
105
|
|
|
'show_in_menu' => false, |
|
106
|
|
|
'style' => array( |
|
107
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/css/about.css', |
|
108
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/css/column.css', |
|
109
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/javascript/flip/jquery.m.flip.css', |
|
110
|
|
|
version_compare( $GLOBALS['wp_version'], '3.8', '<' ) |
|
111
|
|
|
? ".about-wrap .introduction h2 { |
|
112
|
|
|
padding: 1em; |
|
113
|
|
|
}" |
|
114
|
|
|
: "", |
|
115
|
|
|
), |
|
116
|
|
|
'script' => array( |
|
117
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/javascript/flip/jquery.m.flip.js', |
|
118
|
|
|
"jQuery( document ).ready( function() { |
|
119
|
|
|
jQuery( '.apf-badge-image' ).mflip(); |
|
120
|
|
|
} );", |
|
121
|
|
|
), |
|
122
|
|
|
) |
|
123
|
|
|
); |
|
124
|
|
|
|
|
125
|
|
|
// Page Settings |
|
126
|
|
|
$this->setPageHeadingTabsVisibility( false ); // disables the page heading tabs by passing false. |
|
127
|
|
|
$this->setInPageTabTag( 'h2' ); // sets the tag used for in-page tabs |
|
128
|
|
|
$this->setPageTitleVisibility( false ); // disable the page title of a specific page. |
|
129
|
|
|
$this->setPluginSettingsLinkLabel( '' ); // pass an empty string to disable it. |
|
130
|
|
|
|
|
131
|
|
|
// Hook |
|
132
|
|
|
add_action( "load_" . AdminPageFrameworkLoader_Registry::$aAdminPages['about'], array( $this, 'replyToLoadPage' ) ); |
|
133
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Triggered when the page loads. |
|
138
|
|
|
* |
|
139
|
|
|
* Adds tabs. |
|
140
|
|
|
*/ |
|
141
|
|
|
public function replyToLoadPage( $oFactory ) { |
|
142
|
|
|
|
|
143
|
|
|
$_sPageSlug = AdminPageFrameworkLoader_Registry::$aAdminPages['about']; |
|
144
|
|
|
new AdminPageFrameworkLoader_AdminPageWelcome_Welcome( |
|
145
|
|
|
$this, // factory object |
|
146
|
|
|
$_sPageSlug, // page slug |
|
147
|
|
|
array( |
|
148
|
|
|
'tab_slug' => 'welcome', |
|
149
|
|
|
// 'title' => __( "What's New", 'admin-page-framework-loader' ), // ' |
|
|
|
|
|
|
150
|
|
|
'style' => array( |
|
151
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/css/admin.css', |
|
152
|
|
|
AdminPageFrameworkLoader_Registry::$sDirPath . '/asset/css/code.css', |
|
153
|
|
|
' .main-image, .main-image img { text-align: center; max-width: 90%; margin-left: auto; margin-right: auto; } ', |
|
154
|
|
|
), |
|
155
|
|
|
) |
|
156
|
|
|
); |
|
157
|
|
|
|
|
158
|
|
|
$this->_setPreferences( $oFactory ); |
|
159
|
|
|
|
|
160
|
|
|
} |
|
161
|
|
|
/** |
|
162
|
|
|
* Gets triggered when the page loads. |
|
163
|
|
|
*/ |
|
164
|
|
|
private function _setPreferences( $oFactory ) { |
|
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
$this->oProp->sWrapperClassAttribute = "wrap about-wrap"; |
|
167
|
|
|
|
|
168
|
|
|
$oFactory->setInPageTabsVisibility( false ); |
|
169
|
|
|
|
|
170
|
|
|
add_filter( "content_top_{$this->sPageSlug}", array( $this, 'replyToFilterContentTop' ) ); |
|
171
|
|
|
|
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Filters the top part of the page content. |
|
177
|
|
|
* |
|
178
|
|
|
* @remark A callback of the "content_top_{page slug}" filter hook. |
|
179
|
|
|
*/ |
|
180
|
|
|
public function replyToFilterContentTop( $sContent ) { |
|
181
|
|
|
|
|
182
|
|
|
$_sVersion = '- ' . AdminPageFrameworkLoader_Registry::VERSION; |
|
183
|
|
|
$_sPluginName = AdminPageFrameworkLoader_Registry::SHORTNAME . ' ' . $_sVersion; |
|
184
|
|
|
|
|
185
|
|
|
$_sBadgeURL = esc_url( AdminPageFrameworkLoader_Registry::getPluginURL( 'asset/image/icon-128x128.png' ) ); |
|
186
|
|
|
|
|
187
|
|
|
$_aOutput = array(); |
|
188
|
|
|
$_aOutput[] = "<h1>" |
|
189
|
|
|
. sprintf( __( 'Welcome to %1$s', 'admin-page-framework-loader' ), $_sPluginName ) |
|
190
|
|
|
. "</h1>"; |
|
191
|
|
|
$_aOutput[] = "<div class='about-text'>" |
|
192
|
|
|
. sprintf( __( 'Thank you for updating to the latest version! %1$s is ready to make your plugin or theme development faster, more organized and better!', 'admin-page-framework-loader' ), $_sPluginName ) |
|
193
|
|
|
. "</div>"; |
|
194
|
|
|
$_aOutput[] = '' |
|
195
|
|
|
. "<div class='apf-badge'>" |
|
196
|
|
|
. "<div class='apf-badge-image m-flip'>" |
|
197
|
|
|
. "<img src='{$_sBadgeURL}' />" |
|
198
|
|
|
. "</div>" |
|
199
|
|
|
. "<span class='label'>" . sprintf( __( 'Version %1$s', 'admin-page-framework-loader' ), $_sVersion ) . "</span>" |
|
200
|
|
|
. "</div>"; |
|
201
|
|
|
|
|
202
|
|
|
return implode( PHP_EOL, $_aOutput ) |
|
203
|
|
|
. $sContent; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
} |
|
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.