| 1 |
<?php |
| 2 |
|
| 3 |
class MMB_WP extends MMB_Core |
| 4 |
{ |
| 5 |
function __construct() |
| 6 |
{ |
| 7 |
parent::__construct(); |
| 8 |
} |
| 9 |
|
| 10 |
/************************************************************* |
| 11 |
* FACADE functions |
| 12 |
* (functions to be called after a remote XMLRPC from Master) |
| 13 |
**************************************************************/ |
| 14 |
function check_version() |
| 15 |
{ |
| 16 |
require_once(ABSPATH . 'wp-includes/version.php'); |
| 17 |
require_once(ABSPATH . '/wp-admin/includes/update.php'); |
| 18 |
|
| 19 |
$updates = get_core_updates(); |
| 20 |
$update = $updates[0]; |
| 21 |
global $wp_version; |
| 22 |
|
| 23 |
if (!isset($update->response) || 'latest' == $update->response) { |
| 24 |
return array( |
| 25 |
'current_version' => $wp_version, |
| 26 |
'latest_version' => false |
| 27 |
); |
| 28 |
} else { |
| 29 |
return array( |
| 30 |
'current_version' => $wp_version, |
| 31 |
'latest_version' => $update |
| 32 |
); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Upgrades WordPress locally |
| 38 |
* |
| 39 |
*/ |
| 40 |
function upgrade($params){ |
| 41 |
|
| 42 |
ob_start(); |
| 43 |
require_once(ABSPATH . 'wp-admin/includes/file.php'); |
| 44 |
require_once(ABSPATH . 'wp-admin/includes/misc.php'); |
| 45 |
require_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'); |
| 46 |
|
| 47 |
WP_Filesystem(); |
| 48 |
global $wp_version, $wp_filesystem; |
| 49 |
$upgrader = new WP_Upgrader(); |
| 50 |
$updates = $this->mmb_get_transient('update_core'); |
| 51 |
$current = $updates->updates[0]; |
| 52 |
|
| 53 |
|
| 54 |
// Is an update available? |
| 55 |
if ( !isset( $current->response ) || $current->response == 'latest' ) |
| 56 |
return array('upgraded' => ' has latest '.$wp_version.' WordPress version.'); |
| 57 |
|
| 58 |
$res = $upgrader->fs_connect( array(ABSPATH, WP_CONTENT_DIR) ); |
| 59 |
if ( is_wp_error($res) ) |
| 60 |
return array('error' => $this->mmb_get_error($res)); |
| 61 |
|
| 62 |
$wp_dir = trailingslashit($wp_filesystem->abspath()); |
| 63 |
|
| 64 |
$download = $upgrader->download_package( $current->package ); |
| 65 |
if ( is_wp_error($download) ) |
| 66 |
return array('error' => $this->mmb_get_error($download)); |
| 67 |
|
| 68 |
$working_dir = $upgrader->unpack_package( $download ); |
| 69 |
if ( is_wp_error($working_dir) ) |
| 70 |
return array('error' => $this->mmb_get_error($working_dir)); |
| 71 |
|
| 72 |
if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) { |
| 73 |
$wp_filesystem->delete($working_dir, true); |
| 74 |
return array('error' => 'Unable to move update files.'); |
| 75 |
} |
| 76 |
|
| 77 |
$wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE); |
| 78 |
|
| 79 |
require(ABSPATH . 'wp-admin/includes/update-core.php'); |
| 80 |
ob_end_clean(); |
| 81 |
|
| 82 |
$update_core = update_core($working_dir, $wp_dir); |
| 83 |
|
| 84 |
if(is_wp_error($update_core)) |
| 85 |
return array('error' => $this->mmb_get_error($update_core)); |
| 86 |
|
| 87 |
$this->mmb_delete_transient('update_core'); |
| 88 |
return array('upgraded' => ' upgraded sucessfully.'); |
| 89 |
} |
| 90 |
|
| 91 |
} |