class-acf-ajax-check-screen.php
1 year ago
class-acf-ajax-local-json-diff.php
1 year ago
class-acf-ajax-query-users.php
1 year ago
class-acf-ajax-query.php
1 year ago
class-acf-ajax-upgrade.php
1 year ago
class-acf-ajax-user-setting.php
1 year ago
class-acf-ajax.php
1 year ago
index.php
1 year ago
class-acf-ajax-upgrade.php
57 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; // Exit if accessed directly |
| 5 | } |
| 6 | |
| 7 | if ( ! class_exists( 'ACF_Ajax_Upgrade' ) ) : |
| 8 | |
| 9 | class ACF_Ajax_Upgrade extends ACF_Ajax { |
| 10 | |
| 11 | /** @var string The AJAX action name */ |
| 12 | var $action = 'acf/ajax/upgrade'; |
| 13 | |
| 14 | /** |
| 15 | * Returns the response data to sent back. |
| 16 | * |
| 17 | * @since 5.7.2 |
| 18 | * |
| 19 | * @param array $request The request args. |
| 20 | * @return boolean|WP_Error True if successful, or WP_Error on failure. |
| 21 | */ |
| 22 | public function get_response( $request ) { |
| 23 | if ( ! current_user_can( acf_get_setting( 'capability' ) ) ) { |
| 24 | return new WP_Error( 'upgrade_error', __( 'Sorry, you do not have permission to do that.', 'acf' ) ); |
| 25 | } |
| 26 | |
| 27 | // Switch blog. |
| 28 | if ( isset( $request['blog_id'] ) ) { |
| 29 | switch_to_blog( $request['blog_id'] ); |
| 30 | } |
| 31 | |
| 32 | // Bail early if no upgrade avaiable. |
| 33 | if ( ! acf_has_upgrade() ) { |
| 34 | return new WP_Error( 'upgrade_error', __( 'No updates available.', 'acf' ) ); |
| 35 | } |
| 36 | |
| 37 | // Listen for output. |
| 38 | ob_start(); |
| 39 | |
| 40 | // Run upgrades. |
| 41 | acf_upgrade_all(); |
| 42 | |
| 43 | // Store output. |
| 44 | $error = ob_get_clean(); |
| 45 | |
| 46 | // Return error or success. |
| 47 | if ( $error ) { |
| 48 | return new WP_Error( 'upgrade_error', $error ); |
| 49 | } |
| 50 | |
| 51 | return true; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | acf_new_instance( 'ACF_Ajax_Upgrade' ); |
| 56 | endif; // class_exists check |
| 57 |