| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: PHP Compatibility Checker |
| 4 |
* Plugin URI: https://wpengine.com |
| 5 |
* Description: The WP Engine PHP Compatibility Checker can be used by any WordPress website on any web host to check PHP version compatibility. |
| 6 |
* Version: 1.6.3 |
| 7 |
* Requires at least: 5.6 |
| 8 |
* Requires PHP: 5.6 |
| 9 |
* Author: WP Engine |
| 10 |
* Author URI: https://wpengine.com/ |
| 11 |
* License: GPLv2 or later |
| 12 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 13 |
* Text Domain: wpe-php-compat |
| 14 |
* Domain Path: /languages |
| 15 |
* |
| 16 |
* @package WPEngine_PHPCompat\PHP_Compatibility_Checker |
| 17 |
*/ |
| 18 |
|
| 19 |
namespace WPEngine_PHPCompat; |
| 20 |
|
| 21 |
define( 'WPEPHPCOMPAT_ADMIN_PAGE_SLUG', 'wpe-php-compat' ); |
| 22 |
define( 'WPEPHPCOMPAT_CAPABILITY', 'manage_options' ); |
| 23 |
|
| 24 |
use WPEngine_PHPCompat\PHP_Compatibility_Checker; |
| 25 |
|
| 26 |
/** |
| 27 |
* Load plugin functionality. |
| 28 |
* |
| 29 |
* @since 1.0.0 |
| 30 |
*/ |
| 31 |
function wpe_phpcompat_loader() { |
| 32 |
$register_phpcompat = new PHP_Compatibility_Checker(); |
| 33 |
$register_phpcompat->init(); |
| 34 |
|
| 35 |
// Load the text domain. |
| 36 |
load_plugin_textdomain( 'wpe-php-compat', false, dirname( dirname( __FILE__ ) ) . '/languages' ); |
| 37 |
|
| 38 |
// Add plugin action link. |
| 39 |
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $register_phpcompat, 'filter_plugin_links' ) ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Builds the class file name for the plugin |
| 44 |
* |
| 45 |
* @since 1.0.0 |
| 46 |
* |
| 47 |
* @param string $class The name of the class to get. |
| 48 |
* @return string |
| 49 |
*/ |
| 50 |
function wpe_phpcompat_get_class_file( $class ) { |
| 51 |
|
| 52 |
$prefix = 'WPEngine_PHPCompat\\'; |
| 53 |
$base_dir = __DIR__ . '/lib/'; |
| 54 |
|
| 55 |
$len = strlen( $prefix ); |
| 56 |
|
| 57 |
if ( 0 !== strncmp( $prefix, $class, $len ) ) { |
| 58 |
return ''; |
| 59 |
} |
| 60 |
|
| 61 |
$relative_class = substr( $class, $len ); |
| 62 |
$file = $base_dir . str_replace( '\\', '/', 'class-' . strtolower( str_replace( '_', '-', $relative_class ) ) ) . '.php'; |
| 63 |
|
| 64 |
$relative_class_parts = explode( '\\', $relative_class ); |
| 65 |
|
| 66 |
if ( 1 < count( $relative_class_parts ) ) { |
| 67 |
$class_file = $relative_class_parts[0] . '/class-' . strtolower( str_replace( '_', '-', $relative_class_parts[1] ) ); |
| 68 |
$file = $base_dir . str_replace( '\\', '/', $class_file ) . '.php'; |
| 69 |
} |
| 70 |
|
| 71 |
return $file; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Auto-loading functionality for the plugin features |
| 76 |
* |
| 77 |
* @since 1.0.0 |
| 78 |
* |
| 79 |
* @param object $class The class to load. |
| 80 |
*/ |
| 81 |
function wpe_phpcompat_autoloader( $class ) { |
| 82 |
|
| 83 |
$file = wpe_phpcompat_get_class_file( $class ); |
| 84 |
|
| 85 |
if ( ! empty( $file ) && file_exists( $file ) ) { |
| 86 |
include $file; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
spl_autoload_register( __NAMESPACE__ . '\wpe_phpcompat_autoloader' ); |
| 91 |
|
| 92 |
add_action( 'plugins_loaded', __NAMESPACE__ . '\wpe_phpcompat_loader' ); |
| 93 |
|
| 94 |
/** |
| 95 |
* Remove old options and custom post type |
| 96 |
* |
| 97 |
* @return void |
| 98 |
*/ |
| 99 |
function maybe_migrate_to_wptide() { |
| 100 |
$is_wptide = get_option( 'wpephpcompat_is_wptide', false ); |
| 101 |
|
| 102 |
if ( $is_wptide ) { |
| 103 |
// No need to clean legacy options. |
| 104 |
return; |
| 105 |
} |
| 106 |
|
| 107 |
delete_option( 'wpephpcompat.test_version' ); |
| 108 |
delete_option( 'wpephpcompat.only_active' ); |
| 109 |
delete_option( 'wpephpcompat.scan_results' ); |
| 110 |
delete_option( 'wpephpcompat.lock' ); |
| 111 |
delete_option( 'wpephpcompat.status' ); |
| 112 |
delete_option( 'wpephpcompat.numdirs' ); |
| 113 |
delete_option( 'wpephpcompat.show_notice' ); |
| 114 |
|
| 115 |
wp_clear_scheduled_hook( 'wpephpcompat_start_test_cron' ); |
| 116 |
|
| 117 |
$paged = 1; |
| 118 |
|
| 119 |
do { |
| 120 |
$jobs = get_posts( |
| 121 |
array( |
| 122 |
'posts_per_page' => 100, |
| 123 |
'paged' => $paged, |
| 124 |
'post_type' => 'wpephpcompat_jobs', |
| 125 |
'fields' => 'ids', |
| 126 |
) |
| 127 |
); |
| 128 |
|
| 129 |
foreach ( $jobs as $job ) { |
| 130 |
wp_delete_post( $job ); |
| 131 |
} |
| 132 |
|
| 133 |
$found_jobs = count( $jobs ); |
| 134 |
$paged ++; |
| 135 |
} while ( $found_jobs ); |
| 136 |
|
| 137 |
update_option( 'wpephpcompat_is_wptide', 1 ); |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Activate plugin |
| 142 |
* |
| 143 |
* @return void |
| 144 |
*/ |
| 145 |
function activate() { |
| 146 |
maybe_migrate_to_wptide(); |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* Uninstall plugin |
| 151 |
* |
| 152 |
* @return void |
| 153 |
*/ |
| 154 |
function uninstall() { |
| 155 |
maybe_migrate_to_wptide(); |
| 156 |
delete_option( 'wpephpcompat_is_wptide' ); |
| 157 |
} |
| 158 |
|
| 159 |
/** |
| 160 |
* Perform operations when the plugin is upgraded |
| 161 |
* |
| 162 |
* @param WP_Upgrader $upgrader WordPress upgrader instance. |
| 163 |
* @param array $hook_extra Options. |
| 164 |
* @return void |
| 165 |
*/ |
| 166 |
function upgrade( $upgrader, $hook_extra ) { |
| 167 |
$current_plugin_path_name = plugin_basename( __FILE__ ); |
| 168 |
|
| 169 |
if ( 'update' === $hook_extra['action'] && 'plugin' === $hook_extra['type'] ) { |
| 170 |
foreach ( $hook_extra['plugins'] as $plugin ) { |
| 171 |
if ( $plugin === $current_plugin_path_name ) { |
| 172 |
maybe_migrate_to_wptide(); |
| 173 |
} |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
register_activation_hook( __FILE__, __NAMESPACE__ . '\activate' ); |
| 179 |
register_uninstall_hook( __FILE__, __NAMESPACE__ . '\uninstall' ); |
| 180 |
add_action( 'upgrader_process_complete', __NAMESPACE__ . '\upgrade', 10, 2 ); |
| 181 |
|