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