class-jetpack-json-api-attachment-ownership-trait.php
2 months ago
class-jetpack-json-api-delete-backup-helper-script-endpoint.php
7 months ago
class-jetpack-json-api-install-backup-helper-script-endpoint.php
7 months ago
class-jetpack-json-api-modules-list-v1-2-endpoint.php
7 months ago
class.jetpack-json-api-check-capabilities-endpoint.php
7 months ago
class.jetpack-json-api-core-endpoint.php
7 months ago
class.jetpack-json-api-core-modify-endpoint.php
1 month ago
class.jetpack-json-api-cron-endpoint.php
7 months ago
class.jetpack-json-api-endpoint.php
1 month ago
class.jetpack-json-api-get-comment-backup-endpoint.php
7 months ago
class.jetpack-json-api-get-database-object-backup-endpoint.php
7 months ago
class.jetpack-json-api-get-option-backup-endpoint.php
7 months ago
class.jetpack-json-api-get-post-backup-endpoint.php
7 months ago
class.jetpack-json-api-get-term-backup-endpoint.php
7 months ago
class.jetpack-json-api-get-user-backup-endpoint.php
7 months ago
class.jetpack-json-api-jps-woocommerce-connect-endpoint.php
7 months ago
class.jetpack-json-api-log-endpoint.php
7 months ago
class.jetpack-json-api-maybe-auto-update-endpoint.php
7 months ago
class.jetpack-json-api-modules-endpoint.php
7 months ago
class.jetpack-json-api-modules-get-endpoint.php
7 months ago
class.jetpack-json-api-modules-list-endpoint.php
7 months ago
class.jetpack-json-api-modules-modify-endpoint.php
7 months ago
class.jetpack-json-api-plugins-delete-endpoint.php
7 months ago
class.jetpack-json-api-plugins-endpoint.php
1 month ago
class.jetpack-json-api-plugins-get-endpoint.php
7 months ago
class.jetpack-json-api-plugins-install-endpoint.php
7 months ago
class.jetpack-json-api-plugins-list-endpoint.php
3 weeks ago
class.jetpack-json-api-plugins-modify-endpoint.php
7 months ago
class.jetpack-json-api-plugins-modify-v1-2-endpoint.php
7 months ago
class.jetpack-json-api-plugins-new-endpoint.php
7 months ago
class.jetpack-json-api-plugins-replace-endpoint.php
2 months ago
class.jetpack-json-api-sync-endpoint.php
1 month ago
class.jetpack-json-api-themes-active-endpoint.php
7 months ago
class.jetpack-json-api-themes-delete-endpoint.php
7 months ago
class.jetpack-json-api-themes-endpoint.php
1 month ago
class.jetpack-json-api-themes-get-endpoint.php
7 months ago
class.jetpack-json-api-themes-install-endpoint.php
7 months ago
class.jetpack-json-api-themes-list-endpoint.php
7 months ago
class.jetpack-json-api-themes-modify-endpoint.php
7 months ago
class.jetpack-json-api-themes-new-endpoint.php
7 months ago
class.jetpack-json-api-themes-replace-endpoint.php
2 months ago
class.jetpack-json-api-translations-endpoint.php
7 months ago
class.jetpack-json-api-translations-modify-endpoint.php
7 months ago
class.jetpack-json-api-updates-status-endpoint.php
1 month ago
class.jetpack-json-api-user-connect-endpoint.php
7 months ago
class.jetpack-json-api-user-create-endpoint.php
1 month ago
class.wpcom-json-api-get-option-endpoint.php
1 month ago
class.wpcom-json-api-update-option-endpoint.php
7 months ago
json-api-jetpack-endpoints.php
2 months ago
class.jetpack-json-api-core-modify-endpoint.php
125 lines
| 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 = $args['version'] ?? false; |
| 68 | $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 | } |
| 125 |