Skip to content

Instantly share code, notes, and snippets.

@baorv
Created April 26, 2018 11:02
Show Gist options
  • Save baorv/97a74cf7e42184723d006c8e70a441c9 to your computer and use it in GitHub Desktop.
Save baorv/97a74cf7e42184723d006c8e70a441c9 to your computer and use it in GitHub Desktop.
Check compatible wordpress
<?php
define('WP_USE_THEMES', true);
require_once(dirname(__FILE__) . '/wp-load.php');
global $wpdb;
global $wp_version;
$requirements = [
[
'min' => '3.2',
'max' => '10',
'requirements' => [
'mysql' => '5.0.15',
'php' => '5.2.4',
'extensions' => [
[
'name' => 'mod_rewrite',
'optional' => true
],
[
'name' => 'mod_rewrite',
'optional' => false
]
]
]
],
[
'min' => '2.9',
'max' => '3.1',
'requirements' => [
'mysql' => '4.1.2',
'php' => '4.3',
'extensions' => [
[
'name' => 'mod_rewrite',
'optional' => true
]
]
]
]
];
$check_php = false;
$check_mysql = false;
$compatible_extensions = 0;
$check_extension = false;
foreach ($requirements as $requirement) {
if (version_compare($wp_version, $requirement['min'], '>=') && version_compare($wp_version, $requirement['max'], '<=')) {
$check_php = version_compare(phpversion(), $requirement['requirements']['php'], '>=');
$check_mysql = version_compare($wpdb->db_version(), $requirement['requirements']['mysql'], '>=');
$compatible_extensions = 0;
$check_extension = true;
foreach ($requirement['requirements']['extensions'] as $extension) {
if (in_array($extension['name'], apache_get_modules())) {
$compatible_extensions++;
} else {
if (!$extension['optional']) {
$check_extension = false;
}
}
}
break;
}
}
function convertBooleanToString($value)
{
return $value ? 'true' : 'false';
}
echo 'Check PHP: ' . convertBooleanToString($check_php);
echo '<br/>';
echo 'Check MYSQL: ' . convertBooleanToString($check_mysql);
echo '<br/>';
echo $compatible_extensions . ' extensions compatible';
echo '<br/>';
echo 'Check extensions: ' . convertBooleanToString($check_extension);
echo '<br/>';
echo 'Result: ' . convertBooleanToString(($check_php && $check_mysql && $check_extension));
@baorv
Copy link
Author

baorv commented Apr 26, 2018

Just copy to root directory of wordpress and go to http://domain/requirements.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment