| 1 |
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 |
|
| 3 |
/** |
| 4 |
* Core modify endpoint class. |
| 5 |
* |
| 6 |
* POST /sites/%s/core |
| 7 |
* POST /sites/%s/core/update |
| 8 |
*/ |
| 9 |
class Jetpack_JSON_API_Core_Modify_Endpoint extends Jetpack_JSON_API_Core_Endpoint { |
| 10 |
|
| 11 |
/** |
| 12 |
* Needed capabilities. |
| 13 |
* |
| 14 |
* @var string |
| 15 |
*/ |
| 16 |
protected $needed_capabilities = 'update_core'; |
| 17 |
|
| 18 |
/** |
| 19 |
* Action. |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
protected $action = 'default_action'; |
| 24 |
|
| 25 |
/** |
| 26 |
* New version. |
| 27 |
* |
| 28 |
* @var string |
| 29 |
*/ |
| 30 |
protected $new_version; |
| 31 |
|
| 32 |
/** |
| 33 |
* An array of log strings. |
| 34 |
* |
| 35 |
* @var array |
| 36 |
*/ |
| 37 |
protected $log; |
| 38 |
|
| 39 |
/** |
| 40 |
* The default action. |
| 41 |
* |
| 42 |
* @return bool |
| 43 |
*/ |
| 44 |
public function default_action() { |
| 45 |
$args = $this->input(); |
| 46 |
|
| 47 |
if ( isset( $args['autoupdate'] ) && is_bool( $args['autoupdate'] ) ) { |
| 48 |
Jetpack_Options::update_option( 'autoupdate_core', $args['autoupdate'] ); |
| 49 |
} |
| 50 |
|
| 51 |
return true; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Update the version. |
| 56 |
* |
| 57 |
* @return string|false|WP_Error New WordPress version on success, false or WP_Error on failure. |
| 58 |
*/ |
| 59 |
protected function update() { |
| 60 |
$args = $this->input(); |
| 61 |
$version = isset( $args['version'] ) ? $args['version'] : false; |
| 62 |
$locale = isset( $args['locale'] ) ? $args['locale'] : get_locale(); |
| 63 |
|
| 64 |
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 65 |
|
| 66 |
delete_site_transient( 'update_core' ); |
| 67 |
wp_version_check( array(), true ); |
| 68 |
|
| 69 |
if ( $version ) { |
| 70 |
$update = find_core_update( $version, $locale ); |
| 71 |
} else { |
| 72 |
$update = $this->find_latest_update_offer(); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Pre-upgrade action |
| 77 |
* |
| 78 |
* @since 3.9.3 |
| 79 |
* |
| 80 |
* @param object|array $update as returned by find_core_update() or find_core_auto_update() |
| 81 |
*/ |
| 82 |
do_action( 'jetpack_pre_core_upgrade', $update ); |
| 83 |
|
| 84 |
$skin = new Automatic_Upgrader_Skin(); |
| 85 |
$upgrader = new Core_Upgrader( $skin ); |
| 86 |
|
| 87 |
$this->new_version = $upgrader->upgrade( $update ); |
| 88 |
|
| 89 |
$this->log = $upgrader->skin->get_upgrade_messages(); |
| 90 |
|
| 91 |
if ( is_wp_error( $this->new_version ) ) { |
| 92 |
return $this->new_version; |
| 93 |
} |
| 94 |
|
| 95 |
return $this->new_version; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Select the latest update. |
| 100 |
* Remove filters to bypass automattic updates. |
| 101 |
* |
| 102 |
* @return object|false The core update offering on success, false on failure. |
| 103 |
*/ |
| 104 |
protected function find_latest_update_offer() { |
| 105 |
// Select the latest update. |
| 106 |
// Remove filters to bypass automattic updates. |
| 107 |
add_filter( 'request_filesystem_credentials', '__return_true' ); |
| 108 |
add_filter( 'automatic_updates_is_vcs_checkout', '__return_false' ); |
| 109 |
add_filter( 'allow_major_auto_core_updates', '__return_true' ); |
| 110 |
add_filter( 'send_core_update_notification_email', '__return_false' ); |
| 111 |
$update = find_core_auto_update(); |
| 112 |
remove_filter( 'request_filesystem_credentials', '__return_true' ); |
| 113 |
remove_filter( 'automatic_updates_is_vcs_checkout', '__return_false' ); |
| 114 |
remove_filter( 'allow_major_auto_core_updates', '__return_true' ); |
| 115 |
remove_filter( 'send_core_update_notification_email', '__return_false' ); |
| 116 |
return $update; |
| 117 |
} |
| 118 |
} |
| 119 |
|