PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 12.8.3
Jetpack – WP Security, Backup, Speed, & Growth v12.8.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
jetpack / json-endpoints / jetpack / class.jetpack-json-api-core-modify-endpoint.php

class.jetpack-json-api-core-modify-endpoint.php in Jetpack – WP Security, Backup, Speed, & Growth 12.8.3, at json-endpoints/jetpack/class.jetpack-json-api-core-modify-endpoint.php

119 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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