Make WordPress Core


Ignore:
Timestamp:
04/12/2019 07:23:13 PM (7 years ago)
Author:
azaozz
Message:

Site health: Load the "Info" tab immediately and notify the user while gathering site data. Changes the Info tab to work similarly to the Status tab: it does separate request to fetch the directories sizes and doesn't "block" the loading of the page.

Props xkon, afercia, Clorith, azaozz.
See #46707.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r45034 r45176  
    49594959        wp_send_json_success();
    49604960}
     4961
     4962/**
     4963 * Ajax handler for site health check to get directories and database sizes.
     4964 *
     4965 * @since 5.2.0
     4966 */
     4967function wp_ajax_health_check_get_sizes() {
     4968        check_ajax_referer( 'health-check-site-status-result' );
     4969
     4970        if ( ! current_user_can( 'install_plugins' ) ) {
     4971                wp_send_json_error();
     4972        }
     4973
     4974        if ( ! class_exists( 'WP_Debug_Data' ) ) {
     4975                require_once( ABSPATH . 'wp-admin/includes/class-wp-debug-data.php' );
     4976        }
     4977
     4978        $sizes_data = WP_Debug_Data::get_sizes();
     4979        $all_sizes  = array();
     4980
     4981        foreach ( $sizes_data as $name => $value ) {
     4982                $name = sanitize_text_field( $name );
     4983                $data = array();
     4984
     4985                if ( isset( $value['size'] ) ) {
     4986                        if ( is_string( $value['size'] ) ) {
     4987                                $data['size'] = sanitize_text_field( $value['size'] );
     4988                        } else {
     4989                                $data['size'] = (int) $value['size'];
     4990                        }
     4991                }
     4992
     4993                if ( isset( $value['debug'] ) ) {
     4994                        if ( is_string( $value['debug'] ) ) {
     4995                                $data['debug'] = sanitize_text_field( $value['debug'] );
     4996                        } else {
     4997                                $data['debug'] = (int) $value['debug'];
     4998                        }
     4999                }
     5000
     5001                $all_sizes[ $name ] = $data;
     5002        }
     5003
     5004        if ( isset( $all_sizes['total_size']['debug'] ) && 'not available' === $all_sizes['total_size']['debug'] ) {
     5005                wp_send_json_error( $all_sizes );
     5006        }
     5007
     5008        wp_send_json_success( $all_sizes );
     5009}
Note: See TracChangeset for help on using the changeset viewer.