Completed
Branch dev (58959f)
by
unknown
02:02
created

Auto_Load_Next_Post_Admin_Notices::add_notices()   D

Complexity

Conditions 9
Paths 19

Size

Total Lines 40
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 2 Features 1
Metric Value
cc 9
eloc 17
c 7
b 2
f 1
nc 19
nop 0
dl 0
loc 40
rs 4.909
1
<?php
2
/**
3
 * Display notices in the WordPress admin.
4
 *
5
 * @since    1.3.2
6
 * @author   Sébastien Dumont
7
 * @category Admin
8
 * @package  Auto Load Next Post
9
 * @license  GPL-2.0+
10
 */
11
12
if ( ! defined('ABSPATH')) {
13
	exit;
14
}
15
// Exit if accessed directly
16
17
if ( ! class_exists('Auto_Load_Next_Post_Admin_Notices')) {
18
19
/**
20
 * Class - Auto_Load_Next_Post_Admin_Notices
21
 *
22
 * @since 1.3.2
23
 */
24
class Auto_Load_Next_Post_Admin_Notices {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
25
26
	/**
27
	 * Constructor
28
	 *
29
	 * @since  1.3.2
30
	 * @access public
31
	 */
32
	public function __construct() {
33
		add_action('admin_init', array($this, 'check_wp'));
34
		add_action('admin_init', array($this, 'add_notices'));
35
	} // END __construct()
36
37
	/**
38
	 * Checks if the theme supports the plugin.
39
	 * If not, then a notice is displayed explaining what to do next.
40
	 *
41
	 * @since  1.3.2
42
	 * @access public
43
	 * @global $current_user
44
	 */
45
	public function add_notices() {
46
		global $current_user;
47
48
		$template = get_option('template');
49
50
		if ( ! supports_alnp()) {
51
52
			if ( ! empty($_GET['hide_auto_load_next_post_theme_support_check'])) {
53
				update_option('auto_load_next_post_theme_support_check', $template);
54
				return;
55
			}
56
57
			if (get_option('auto_load_next_post_theme_support_check') !== $template) {
58
				add_action('admin_notices', array($this, 'theme_check_notice'));
59
			}
60
61
		}
62
63
		if ( ! empty($_GET['hide_auto_load_next_post_review_notice']) && current_user_can('install_plugins')) {
64
			// Add user meta
65
			add_user_meta($current_user->ID, 'auto_load_next_post_hide_review_notice', '1', true);
66
		}
67
68
		// Is admin notice hidden?
69
		$hide_notice = get_user_meta($current_user->ID, 'auto_load_next_post_hide_review_notice', true);
70
71
		// Check if we need to display the review plugin notice
72
		if (current_user_can('install_plugins') && empty($hide_notice)) {
73
			// Get installation date
74
			$datetime_install = self::get_install_date();
75
			$datetime_past    = new DateTime('-14 days');
76
77
			if ($datetime_past >= $datetime_install) {
78
				// 14 or more days ago, show admin notice
79
				add_action('admin_notices', array($this, 'plugin_review_notice'));
80
			}
81
		}
82
83
84
	} // END add_notices()
85
86
	/**
87
	 * Checks that the WordPress version meets the plugin requirement.
88
	 *
89
	 * @since  1.0.0
90
	 * @access public
91
	 * @global string $wp_version
92
	 * @return bool
93
	 */
94
	public function check_wp() {
95
		global $wp_version;
96
97
		if ( ! version_compare($wp_version, AUTO_LOAD_NEXT_POST_WP_VERSION_REQUIRE, '>=')) {
98
			add_action('admin_notices', array($this, 'requirement_wp_notice'));
99
			return false;
100
		}
101
102
		return true;
103
	} // END check_requirements()
104
105
	/**
106
	 * Get the install data
107
	 *
108
	 * @since  1.4.4
109
	 * @access private
110
	 * @return DateTime
111
	 */
112
	private function get_install_date() {
113
		$date_string = get_site_option('auto_load_next_post_install_date', '');
114
		if (empty($date_string)) {
115
			// There is no install date, plugin was installed before version 1.2.0. Add it now.
116
			$date_string = Auto_Load_Next_Post_Install::insert_install_date();
117
		}
118
119
		return new DateTime($date_string);
120
	}
121
122
	/**
123
	 * Show the WordPress requirement notice.
124
	 *
125
	 * @since  1.4.3
126
	 * @access public
127
	 */
128
	public function requirement_wp_notice() {
129
		include('views/html-notice-requirement-wp.php');
130
	} // END requirement_wp_notice()
131
132
	/**
133
	 * Show the theme check notice.
134
	 *
135
	 * @since  1.3.2
136
	 * @access public
137
	 */
138
	public function theme_check_notice() {
139
		include('views/html-notice-theme-support.php');
140
	} // END theme_check_notice()
141
142
	/**
143
	 * Show the plugin review notice.
144
	 *
145
	 * @since  1.4.4
146
	 * @access public
147
	 */
148
	public function plugin_review_notice() {
149
		include('views/html-notice-please-review.php');
150
	} // END plugin_review_notice()
151
152
} // END Auto_Load_Next_Post_Admin_Notices class.
153
154
} // END if class exists.
155
156
return new Auto_Load_Next_Post_Admin_Notices();
157