-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
wp-last-modified-info.php
221 lines (192 loc) · 5.29 KB
/
wp-last-modified-info.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
/**
* Plugin Name: WP Last Modified Info
* Plugin URI: https://wordpress.org/plugins/wp-last-modified-info/
* Description: Ultimate Last Modified Plugin for WordPress with Gutenberg Block Integration. It is possible to use shortcodes to display last modified info anywhere on a WordPress site running 4.7 and beyond.
* Version: 1.9.1
* Author: Sayan Datta
* Author URI: https://www.sayandatta.co.in
* License: GPLv3
* Text Domain: wp-last-modified-info
* Domain Path: /languages
*
* WP Last Modified Info is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* WP Last Modified Info is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WP Last Modified Info. If not, see <http://www.gnu.org/licenses/>.
*
* @category Core
* @package WP Last Modified Info
* @author Sayan Datta <iamsayan@protonmail.com>
* @license http://www.gnu.org/licenses/ GNU General Public License
* @link https://wordpress.org/plugins/wp-last-modified-info/
*
*/
// If this file is called firectly, abort!!!
defined( 'ABSPATH' ) || exit;
/**
* WPLMI class.
*
* @class Main class of the plugin.
*/
final class WPLMI {
/**
* Plugin version.
*
* @var string
*/
public $version = '1.9.1';
/**
* Minimum version of WordPress required to run WPLMI.
*
* @var string
*/
private $wordpress_version = '4.7';
/**
* Minimum version of PHP required to run WPLMI.
*
* @var string
*/
private $php_version = '7.0';
/**
* Hold install error messages.
*
* @var bool
*/
private $messages = [];
/**
* The single instance of the class.
*
* @var WPLMI
*/
protected static $instance = null;
/**
* Retrieve main WPLMI instance.
*
* Ensure only one instance is loaded or can be loaded.
*
* @see wplmi()
* @return WPLMI
*/
public static function get() {
if ( is_null( self::$instance ) && ! ( self::$instance instanceof WPLMI ) ) {
self::$instance = new WPLMI();
self::$instance->setup();
}
return self::$instance;
}
/**
* Instantiate the plugin.
*/
private function setup() {
// Define plugin constants.
$this->define_constants();
if ( ! $this->is_requirements_meet() ) {
return;
}
// Include required files.
$this->includes();
// Instantiate services.
$this->instantiate();
// Loaded action.
do_action( 'wplmi/loaded' );
}
/**
* Check that the WordPress and PHP setup meets the plugin requirements.
*
* @return bool
*/
private function is_requirements_meet() {
// Check WordPress version.
if ( version_compare( get_bloginfo( 'version' ), $this->wordpress_version, '<' ) ) {
/* translators: WordPress Version */
$this->messages[] = sprintf( esc_html__( 'You are using the outdated WordPress, please update it to version %s or higher.', 'wp-last-modified-info' ), $this->wordpress_version );
}
// Check PHP version.
if ( version_compare( phpversion(), $this->php_version, '<' ) ) {
/* translators: PHP Version */
$this->messages[] = sprintf( esc_html__( 'WP Last Modified Info requires PHP version %s or above. Please update PHP to run this plugin.', 'wp-last-modified-info' ), $this->php_version );
}
if ( empty( $this->messages ) ) {
return true;
}
// Auto-deactivate plugin.
add_action( 'admin_init', [ $this, 'auto_deactivate' ] );
add_action( 'admin_notices', [ $this, 'activation_error' ] );
return false;
}
/**
* Auto-deactivate plugin if requirements are not met, and display a notice.
*/
public function auto_deactivate() {
deactivate_plugins( WPLMI_BASENAME );
if ( isset( $_GET['activate'] ) ) { // phpcs:ignore
unset( $_GET['activate'] ); // phpcs:ignore
}
}
/**
* Error notice on plugin activation.
*/
public function activation_error() {
?>
<div class="notice wplmi-notice notice-error">
<p>
<?= join( '<br>', $this->messages ); // phpcs:ignore ?>
</p>
</div>
<?php
}
/**
* Define the plugin constants.
*/
private function define_constants() {
define( 'WPLMI_VERSION', $this->version );
define( 'WPLMI_FILE', __FILE__ );
define( 'WPLMI_PATH', dirname( WPLMI_FILE ) . '/' );
define( 'WPLMI_URL', plugins_url( '', WPLMI_FILE ) . '/' );
define( 'WPLMI_BASENAME', plugin_basename( WPLMI_FILE ) );
}
/**
* Include the required files.
*/
private function includes() {
include __DIR__ . '/vendor/autoload.php';
}
/**
* Instantiate services.
*/
private function instantiate() {
// Activation hook.
register_activation_hook( WPLMI_FILE,
function () {
Wplmi\Base\Activate::activate();
}
);
// Deactivation hook.
register_deactivation_hook( WPLMI_FILE,
function () {
Wplmi\Base\Deactivate::deactivate();
}
);
// Init WPLMI Classes.
Wplmi\Loader::register_services();
}
}
/**
* Returns the main instance of WPLMI to prevent the need to use globals.
*
* @return WPLMI
*/
function wplmi() { // phpcs:ignore Universal.Files.SeparateFunctionsFromOO.Mixed
return WPLMI::get();
}
// Start it.
wplmi();