1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Display notices in the WordPress admin. |
4
|
|
|
* |
5
|
|
|
* @since 1.3.2 |
6
|
|
|
* @version 1.5.13 |
7
|
|
|
* @author Sébastien Dumont |
8
|
|
|
* @category Admin |
9
|
|
|
* @package Auto Load Next Post/Admin/Notices |
10
|
|
|
* @license GPL-2.0+ |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
// Exit if accessed directly. |
14
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
15
|
|
|
exit; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
if ( ! class_exists( 'Auto_Load_Next_Post_Admin_Notices' ) ) { |
19
|
|
|
|
20
|
|
|
class Auto_Load_Next_Post_Admin_Notices { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Activation date. |
24
|
|
|
* |
25
|
|
|
* @access public |
26
|
|
|
* @static |
27
|
|
|
* @since 1.4.10 |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
public static $install_date; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Constructor |
34
|
|
|
* |
35
|
|
|
* @access public |
36
|
|
|
* @since 1.3.2 |
37
|
|
|
* @version 1.5.11 |
38
|
|
|
*/ |
39
|
|
|
public function __construct() { |
40
|
|
|
self::$install_date = get_site_option( 'auto_load_next_post_install_date', time() ); |
41
|
|
|
|
42
|
|
|
// Check WordPress enviroment. |
43
|
|
|
add_action( 'admin_init', array( $this, 'check_wp' ), 12 ); |
44
|
|
|
|
45
|
|
|
// Don't bug the user if they don't want to see any notices. |
46
|
|
|
add_action( 'admin_init', array( $this, 'dont_bug_me' ), 15 ); |
47
|
|
|
|
48
|
|
|
// Display other admin notices when required. All are dismissable. |
49
|
|
|
add_action( 'admin_print_styles', array( $this, 'add_notices' ), 0 ); |
50
|
|
|
} // END __construct() |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Checks that the WordPress version meets the plugin requirement. |
54
|
|
|
* |
55
|
|
|
* @access public |
56
|
|
|
* @since 1.0.0 |
57
|
|
|
* @version 1.5.11 |
58
|
|
|
* @global string $wp_version |
59
|
|
|
* @return bool |
60
|
|
|
*/ |
61
|
|
|
public function check_wp() { |
62
|
|
|
global $wp_version; |
63
|
|
|
|
64
|
|
|
// If the current user can not install plugins then return nothing! |
65
|
|
|
if ( ! current_user_can( 'install_plugins' ) ) { |
66
|
|
|
return false; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if ( ! version_compare( $wp_version, AUTO_LOAD_NEXT_POST_WP_VERSION_REQUIRE, '>=' ) ) { |
70
|
|
|
add_action( 'admin_notices', array( $this, 'requirement_wp_notice' ) ); |
71
|
|
|
return false; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return true; |
75
|
|
|
} // END check_wp() |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Don't bug the user if they don't want to see any notices. |
79
|
|
|
* |
80
|
|
|
* @access public |
81
|
|
|
* @since 1.5.0 |
82
|
|
|
* @global $current_user |
83
|
|
|
*/ |
84
|
|
|
public function dont_bug_me() { |
85
|
|
|
global $current_user; |
86
|
|
|
|
87
|
|
|
$user_hidden_notice = false; |
88
|
|
|
|
89
|
|
|
// If the user is allowed to install plugins and requested to hide the review notice then hide it for that user. |
90
|
|
View Code Duplication |
if ( ! empty( $_GET['hide_auto_load_next_post_review_notice'] ) && current_user_can( 'install_plugins' ) ) { |
91
|
|
|
add_user_meta( $current_user->ID, 'auto_load_next_post_hide_review_notice', '1', true ); |
92
|
|
|
$user_hidden_notice = true; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
// If the user is allowed to install plugins and requested to hide the welcome notice then hide it for that user. |
96
|
|
View Code Duplication |
if ( ! empty( $_GET['hide_auto_load_next_post_welcome_notice'] ) && current_user_can( 'install_plugins' ) ) { |
97
|
|
|
add_user_meta( $current_user->ID, 'auto_load_next_post_hide_welcome_notice', '1', true ); |
98
|
|
|
$user_hidden_notice = true; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
if ( ! empty( $_GET['hide_auto_load_next_post_beta_notice'] ) && current_user_can( 'install_plugins' ) ) { |
102
|
|
|
set_transient( 'alnp_beta_notice_hidden', 'hidden', WEEK_IN_SECONDS ); |
103
|
|
|
$user_hidden_notice = true; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
if ( $user_hidden_notice ) { |
107
|
|
|
// Redirect to the plugins page. |
108
|
|
|
wp_safe_redirect( admin_url( 'plugins.php' ) ); |
109
|
|
|
exit; |
110
|
|
|
} |
111
|
|
|
} // END dont_bug_me() |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Checks if the theme supports the plugin and display the plugin review |
115
|
|
|
* notice after 7 days or more from the time the plugin was installed. |
116
|
|
|
* |
117
|
|
|
* @access public |
118
|
|
|
* @since 1.3.2 |
119
|
|
|
* @version 1.5.13 |
120
|
|
|
* @global $current_user |
121
|
|
|
* @return void|bool |
122
|
|
|
*/ |
123
|
|
|
public function add_notices() { |
124
|
|
|
global $current_user; |
125
|
|
|
|
126
|
|
|
// If the current user can not install plugins then return nothing! |
127
|
|
|
if ( ! current_user_can( 'install_plugins' ) ) { |
128
|
|
|
return false; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$screen = get_current_screen(); |
132
|
|
|
$screen_id = $screen ? $screen->id : ''; |
133
|
|
|
|
134
|
|
|
// Notices should only show on the main dashboard and on the plugins screen. |
135
|
|
|
if ( ! in_array( $screen_id, alnp_get_admin_screens() ) ) { |
136
|
|
|
return false; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
// Is admin welcome notice hidden? |
140
|
|
|
$hide_welcome_notice = get_user_meta( $current_user->ID, 'auto_load_next_post_hide_welcome_notice', true ); |
141
|
|
|
|
142
|
|
|
// Check if we need to display the welcome notice. |
143
|
|
View Code Duplication |
if ( empty( $hide_welcome_notice ) ) { |
144
|
|
|
// If the user has just installed the plugin for the first time then welcome the user. |
145
|
|
|
if ( ( intval( time() - self::$install_date ) / WEEK_IN_SECONDS ) % 52 <= 2 ) { |
146
|
|
|
add_action( 'admin_notices', array( $this, 'welcome_notice' ) ); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
// Is admin review notice hidden? |
151
|
|
|
$hide_review_notice = get_user_meta( $current_user->ID, 'auto_load_next_post_hide_review_notice', true ); |
152
|
|
|
|
153
|
|
|
// Check if we need to display the review plugin notice. |
154
|
|
View Code Duplication |
if ( empty( $hide_review_notice ) ) { |
155
|
|
|
// If it has been a week or more since activating the plugin then display the review notice. |
156
|
|
|
if ( ( intval( time() - self::$install_date ) ) > WEEK_IN_SECONDS ) { |
157
|
|
|
add_action( 'admin_notices', array( $this, 'plugin_review_notice' ) ); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
// Is this version of Auto Load Next Post a beta release? |
162
|
|
|
if ( is_alnp_beta() && empty( get_transient( 'alnp_beta_notice_hidden' ) ) ) { |
163
|
|
|
add_action( 'admin_notices', array( $this, 'beta_notice' ) ); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
$template = get_option( 'template' ); |
167
|
|
|
|
168
|
|
|
// Checks if the theme supports Auto Load Next Post and not provided via a plugin. |
169
|
|
|
if ( is_alnp_supported() ) { |
170
|
|
|
$plugin_supported = alnp_get_theme_support( 'plugin_support' ); |
171
|
|
|
|
172
|
|
|
// Return if theme is supported via plugin. |
173
|
|
|
if ( ! empty( $plugin_supported ) && $plugin_supported == 'yes' ) { |
174
|
|
|
update_option( 'auto_load_next_post_theme_supported', $template ); |
175
|
|
|
return false; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
// If supported theme does not match active theme then show notice. |
179
|
|
|
if ( get_option( 'auto_load_next_post_theme_supported' ) !== $template ) { |
180
|
|
|
add_action( 'admin_notices', array( $this, 'theme_ready_notice' ) ); |
181
|
|
|
update_option( 'auto_load_next_post_theme_supported', $template ); |
182
|
|
|
} |
183
|
|
|
} else { |
184
|
|
|
// If theme not supported then delete option. |
185
|
|
|
delete_option( 'auto_load_next_post_theme_supported' ); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
// Upgrade warning notice that will disappear once the new release is installed. |
189
|
|
|
$upgrade_version = '1.6.0'; |
190
|
|
|
|
191
|
|
|
if ( version_compare( AUTO_LOAD_NEXT_POST_VERSION, $upgrade_version, '<' ) ) { |
192
|
|
|
add_action( 'admin_notices', array( $this, 'upgrade_warning' ) ); |
193
|
|
|
} |
194
|
|
|
} // END add_notices() |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Shows an upgrade warning notice if the installed version is less |
198
|
|
|
* than the new release coming soon. |
199
|
|
|
* |
200
|
|
|
* @access public |
201
|
|
|
* @since 1.4.13 |
202
|
|
|
* @version 1.5.13 |
203
|
|
|
*/ |
204
|
|
|
public function upgrade_warning() { |
205
|
|
|
include_once( dirname( __FILE__ ) . '/views/html-notice-upgrade-warning.php' ); |
206
|
|
|
} // END upgrade_warning() |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Show the WordPress requirement notice. |
210
|
|
|
* |
211
|
|
|
* @access public |
212
|
|
|
* @since 1.4.3 |
213
|
|
|
*/ |
214
|
|
|
public function requirement_wp_notice() { |
215
|
|
|
include( dirname( __FILE__ ) . '/views/html-notice-requirement-wp.php' ); |
216
|
|
|
} // END requirement_wp_notice() |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Show the theme ready notice. |
220
|
|
|
* |
221
|
|
|
* @access public |
222
|
|
|
* @since 1.5.0 |
223
|
|
|
*/ |
224
|
|
|
public function theme_ready_notice() { |
225
|
|
|
include( dirname( __FILE__ ) . '/views/html-notice-theme-ready.php' ); |
226
|
|
|
} // END theme_ready_notice() |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Show the welcome notice. |
230
|
|
|
* |
231
|
|
|
* @access public |
232
|
|
|
* @since 1.5.0 |
233
|
|
|
*/ |
234
|
|
|
public function welcome_notice() { |
235
|
|
|
include( dirname( __FILE__ ) . '/views/html-notice-welcome.php' ); |
236
|
|
|
} // END welcome_notice() |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Show the beta notice. |
240
|
|
|
* |
241
|
|
|
* @access public |
242
|
|
|
* @since 1.5.0 |
243
|
|
|
*/ |
244
|
|
|
public function beta_notice() { |
245
|
|
|
include( dirname( __FILE__ ) . '/views/html-notice-trying-beta.php' ); |
246
|
|
|
} // END beta_notice() |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Show the plugin review notice. |
250
|
|
|
* |
251
|
|
|
* @access public |
252
|
|
|
* @since 1.4.4 |
253
|
|
|
* @version 1.4.10 |
254
|
|
|
*/ |
255
|
|
|
public function plugin_review_notice() { |
256
|
|
|
$install_date = self::$install_date; |
257
|
|
|
|
258
|
|
|
include( dirname( __FILE__ ) . '/views/html-notice-please-review.php' ); |
259
|
|
|
} // END plugin_review_notice() |
260
|
|
|
|
261
|
|
|
} // END class. |
262
|
|
|
|
263
|
|
|
} // END if class exists. |
264
|
|
|
|
265
|
|
|
return new Auto_Load_Next_Post_Admin_Notices(); |
266
|
|
|
|