-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathwpengine-phpcompat.php
More file actions
197 lines (162 loc) · 4.88 KB
/
wpengine-phpcompat.php
File metadata and controls
197 lines (162 loc) · 4.88 KB
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
<?php
/**
* Plugin Name: PHP Compatibility Checker
* Plugin URI: https://wpengine.com
* Description: The WP Engine PHP Compatibility Checker can be used by any WordPress website on any web host to check PHP version compatibility.
* Version: 1.6.4
* Requires at least: 5.6
* Requires PHP: 5.6
* Author: WP Engine
* Author URI: https://wpengine.com/
* Update URI: false
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wpe-php-compat
* Domain Path: /languages
*
* @package WPEngine_PHPCompat\PHP_Compatibility_Checker
*/
namespace WPEngine_PHPCompat;
define( 'WPEPHPCOMPAT_ADMIN_PAGE_SLUG', 'wpe-php-compat' );
define( 'WPEPHPCOMPAT_CAPABILITY', 'manage_options' );
use WPEngine_PHPCompat\PHP_Compatibility_Checker;
/**
* Load plugin functionality.
*
* @since 1.0.0
*/
function wpe_phpcompat_loader() {
$register_phpcompat = new PHP_Compatibility_Checker();
$register_phpcompat->init();
// Load the text domain.
load_plugin_textdomain( 'wpe-php-compat', false, dirname( dirname( __FILE__ ) ) . '/languages' );
// Add plugin action link.
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $register_phpcompat, 'filter_plugin_links' ) );
}
/**
* Builds the class file name for the plugin
*
* @since 1.0.0
*
* @param string $class The name of the class to get.
* @return string
*/
function wpe_phpcompat_get_class_file( $class ) {
$prefix = 'WPEngine_PHPCompat\\';
$base_dir = __DIR__ . '/lib/';
$len = strlen( $prefix );
if ( 0 !== strncmp( $prefix, $class, $len ) ) {
return '';
}
$relative_class = substr( $class, $len );
$file = $base_dir . str_replace( '\\', '/', 'class-' . strtolower( str_replace( '_', '-', $relative_class ) ) ) . '.php';
$relative_class_parts = explode( '\\', $relative_class );
if ( 1 < count( $relative_class_parts ) ) {
$class_file = $relative_class_parts[0] . '/class-' . strtolower( str_replace( '_', '-', $relative_class_parts[1] ) );
$file = $base_dir . str_replace( '\\', '/', $class_file ) . '.php';
}
return $file;
}
/**
* Auto-loading functionality for the plugin features
*
* @since 1.0.0
*
* @param object $class The class to load.
*/
function wpe_phpcompat_autoloader( $class ) {
$file = wpe_phpcompat_get_class_file( $class );
if ( ! empty( $file ) && file_exists( $file ) ) {
include $file;
}
}
spl_autoload_register( __NAMESPACE__ . '\wpe_phpcompat_autoloader' );
add_action( 'plugins_loaded', __NAMESPACE__ . '\wpe_phpcompat_loader' );
/**
* Remove old options and custom post type
*
* @return void
*/
function maybe_migrate_to_wptide() {
$is_wptide = get_option( 'wpephpcompat_is_wptide', false );
if ( $is_wptide ) {
// No need to clean legacy options.
return;
}
delete_option( 'wpephpcompat.test_version' );
delete_option( 'wpephpcompat.only_active' );
delete_option( 'wpephpcompat.scan_results' );
delete_option( 'wpephpcompat.lock' );
delete_option( 'wpephpcompat.status' );
delete_option( 'wpephpcompat.numdirs' );
delete_option( 'wpephpcompat.show_notice' );
wp_clear_scheduled_hook( 'wpephpcompat_start_test_cron' );
$paged = 1;
do {
$jobs = get_posts(
array(
'posts_per_page' => 100,
'paged' => $paged,
'post_type' => 'wpephpcompat_jobs',
'fields' => 'ids',
)
);
foreach ( $jobs as $job ) {
wp_delete_post( $job );
}
$found_jobs = count( $jobs );
$paged ++;
} while ( $found_jobs );
update_option( 'wpephpcompat_is_wptide', 1 );
}
/**
* Activate plugin
*
* @return void
*/
function activate() {
maybe_migrate_to_wptide();
}
/**
* Uninstall plugin
*
* @return void
*/
function uninstall() {
maybe_migrate_to_wptide();
delete_option( 'wpephpcompat_is_wptide' );
}
/**
* Perform operations when the plugin is upgraded
*
* @param WP_Upgrader $upgrader WordPress upgrader instance.
* @param array $hook_extra Options.
* @return void
*/
function upgrade( $upgrader, $hook_extra ) {
$current_plugin_path_name = plugin_basename( __FILE__ );
if ( 'update' === $hook_extra['action'] && 'plugin' === $hook_extra['type'] ) {
foreach ( $hook_extra['plugins'] as $plugin ) {
if ( $plugin === $current_plugin_path_name ) {
maybe_migrate_to_wptide();
}
}
}
}
register_activation_hook( __FILE__, __NAMESPACE__ . '\activate' );
register_uninstall_hook( __FILE__, __NAMESPACE__ . '\uninstall' );
add_action( 'upgrader_process_complete', __NAMESPACE__ . '\upgrade', 10, 2 );
/**
* Registers the plugin updater.
*
* @return void
*/
function check_for_upgrades() {
$properties = array(
'plugin_slug' => 'php-compatibility-checker',
'plugin_basename' => plugin_basename( __FILE__ ),
);
require_once __DIR__ . '/lib/class-plugin-updater.php';
new \WPEngine_PHPCompat\PluginUpdater( $properties );
}
add_action( 'admin_init', __NAMESPACE__ . '\check_for_upgrades' );