1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Display notices in the WordPress admin. |
4
|
|
|
* |
5
|
|
|
* @since 1.3.2 |
6
|
|
|
* @version 1.4.10 |
7
|
|
|
* @author Sébastien Dumont |
8
|
|
|
* @category Admin |
9
|
|
|
* @package Auto Load Next Post |
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.4.10 |
38
|
|
|
*/ |
39
|
|
|
public function __construct() { |
40
|
|
|
self::$install_date = get_site_option( 'auto_load_next_post_install_date', time() ); |
41
|
|
|
|
42
|
|
|
add_action( 'admin_init', array( $this, 'check_wp' ), 12 ); |
43
|
|
|
add_action( 'admin_init', array( $this, 'dont_bug_me' ), 15 ); |
44
|
|
|
|
45
|
|
|
add_action( 'admin_notices', array( $this, 'add_notices' ), 0 ); |
46
|
|
|
} // END __construct() |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Checks that the WordPress version meets the plugin requirement. |
50
|
|
|
* |
51
|
|
|
* @access public |
52
|
|
|
* @since 1.0.0 |
53
|
|
|
* @global string $wp_version |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
|
|
public function check_wp() { |
57
|
|
|
global $wp_version; |
58
|
|
|
|
59
|
|
|
if ( ! version_compare( $wp_version, AUTO_LOAD_NEXT_POST_WP_VERSION_REQUIRE, '>=' ) ) { |
60
|
|
|
add_action( 'admin_notices', array( $this, 'requirement_wp_notice' ) ); |
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return true; |
65
|
|
|
} // END check_wp() |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Dont bug the user if they do not want any notices. |
69
|
|
|
* |
70
|
|
|
* @access public |
71
|
|
|
* @since 1.4.10 |
72
|
|
|
* @global $current_user |
73
|
|
|
*/ |
74
|
|
|
public function dont_bug_me() { |
75
|
|
|
global $current_user; |
76
|
|
|
|
77
|
|
|
// If the user is allowed to install plugins and requested to hide the notice then hide it for that user. |
78
|
|
|
if ( ! empty( $_GET['hide_auto_load_next_post_review_notice'] ) && current_user_can( 'install_plugins' ) ) { |
79
|
|
|
add_user_meta( $current_user->ID, 'auto_load_next_post_hide_review_notice', '1', true ); |
80
|
|
|
// Redirect to the plugins page. |
81
|
|
|
wp_safe_redirect( admin_url( 'plugins.php' ) ); exit; |
82
|
|
|
} |
83
|
|
|
} // END dont_bug_me() |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Checks if the theme supports the plugin and display the plugin review |
87
|
|
|
* notice after 7 days or more from the time the plugin was installed. |
88
|
|
|
* |
89
|
|
|
* @access public |
90
|
|
|
* @since 1.3.2 |
91
|
|
|
* @version 1.4.10 |
92
|
|
|
* @global $current_user |
93
|
|
|
*/ |
94
|
|
|
public function add_notices() { |
95
|
|
|
global $current_user; |
96
|
|
|
|
97
|
|
|
$template = get_option('template'); |
98
|
|
|
|
99
|
|
|
if ( ! supports_alnp() ) { |
100
|
|
|
// If user hides theme support notice then set active theme. |
101
|
|
|
if ( ! empty( $_GET['hide_auto_load_next_post_theme_support_check'] ) ) { |
102
|
|
|
update_option( 'auto_load_next_post_theme_support_check', $template ); |
103
|
|
|
return; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
if ( get_option( 'auto_load_next_post_theme_support_check' ) !== $template ) { |
107
|
|
|
add_action( 'admin_notices', array( $this, 'theme_check_notice' ) ); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
// Is admin notice hidden? |
112
|
|
|
$hide_notice = get_user_meta( $current_user->ID, 'auto_load_next_post_hide_review_notice', true ); |
113
|
|
|
|
114
|
|
|
// Check if we need to display the review plugin notice. |
115
|
|
|
if ( current_user_can( 'install_plugins' ) && empty( $hide_notice ) ) { |
116
|
|
|
// If it has been a week or more since activating the plugin then display the review notice. |
117
|
|
|
if ( ( time() - self::$install_date ) > WEEK_IN_SECONDS ) { |
118
|
|
|
add_action( 'admin_notices', array( $this, 'plugin_review_notice' ) ); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
} // END add_notices() |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Show the WordPress requirement notice. |
125
|
|
|
* |
126
|
|
|
* @access public |
127
|
|
|
* @since 1.4.3 |
128
|
|
|
*/ |
129
|
|
|
public function requirement_wp_notice() { |
130
|
|
|
include( dirname( __FILE__ ) . '/views/html-notice-requirement-wp.php' ); |
131
|
|
|
} // END requirement_wp_notice() |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Show the theme check notice. |
135
|
|
|
* |
136
|
|
|
* @access public |
137
|
|
|
* @since 1.3.2 |
138
|
|
|
*/ |
139
|
|
|
public function theme_check_notice() { |
140
|
|
|
include( dirname( __FILE__ ) . '/views/html-notice-theme-support.php' ); |
141
|
|
|
} // END theme_check_notice() |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Show the plugin review notice. |
145
|
|
|
* |
146
|
|
|
* @access public |
147
|
|
|
* @since 1.4.4 |
148
|
|
|
* @version 1.4.10 |
149
|
|
|
*/ |
150
|
|
|
public function plugin_review_notice() { |
151
|
|
|
$install_date = self::$install_date; |
152
|
|
|
|
153
|
|
|
include( dirname( __FILE__ ) . '/views/html-notice-please-review.php' ); |
154
|
|
|
} // END plugin_review_notice() |
155
|
|
|
|
156
|
|
|
} // END class. |
157
|
|
|
|
158
|
|
|
} // END if class exists. |
159
|
|
|
|
160
|
|
|
return new Auto_Load_Next_Post_Admin_Notices(); |
161
|
|
|
|