wp/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php
changeset 21 48c4eec2b7e6
parent 18 be944660c56a
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    41 
    41 
    42 	/**
    42 	/**
    43 	 * Registers API routes.
    43 	 * Registers API routes.
    44 	 *
    44 	 *
    45 	 * @since 5.6.0
    45 	 * @since 5.6.0
       
    46 	 * @since 6.1.0 Adds page-cache async test.
    46 	 *
    47 	 *
    47 	 * @see register_rest_route()
    48 	 * @see register_rest_route()
    48 	 */
    49 	 */
    49 	public function register_routes() {
    50 	public function register_routes() {
    50 		register_rest_route(
    51 		register_rest_route(
   149 				'directory-sizes'
   150 				'directory-sizes'
   150 			),
   151 			),
   151 			array(
   152 			array(
   152 				'methods'             => 'GET',
   153 				'methods'             => 'GET',
   153 				'callback'            => array( $this, 'get_directory_sizes' ),
   154 				'callback'            => array( $this, 'get_directory_sizes' ),
   154 				'permission_callback' => function() {
   155 				'permission_callback' => function () {
   155 					return $this->validate_request_permission( 'debug_enabled' ) && ! is_multisite();
   156 					return $this->validate_request_permission( 'directory_sizes' ) && ! is_multisite();
   156 				},
   157 				},
       
   158 			)
       
   159 		);
       
   160 
       
   161 		register_rest_route(
       
   162 			$this->namespace,
       
   163 			sprintf(
       
   164 				'/%s/%s',
       
   165 				$this->rest_base,
       
   166 				'page-cache'
       
   167 			),
       
   168 			array(
       
   169 				array(
       
   170 					'methods'             => 'GET',
       
   171 					'callback'            => array( $this, 'test_page_cache' ),
       
   172 					'permission_callback' => function () {
       
   173 						return $this->validate_request_permission( 'page_cache' );
       
   174 					},
       
   175 				),
   157 			)
   176 			)
   158 		);
   177 		);
   159 	}
   178 	}
   160 
   179 
   161 	/**
   180 	/**
   241 		$this->load_admin_textdomain();
   260 		$this->load_admin_textdomain();
   242 		return $this->site_health->get_test_authorization_header();
   261 		return $this->site_health->get_test_authorization_header();
   243 	}
   262 	}
   244 
   263 
   245 	/**
   264 	/**
       
   265 	 * Checks that full page cache is active.
       
   266 	 *
       
   267 	 * @since 6.1.0
       
   268 	 *
       
   269 	 * @return array The test result.
       
   270 	 */
       
   271 	public function test_page_cache() {
       
   272 		$this->load_admin_textdomain();
       
   273 		return $this->site_health->get_test_page_cache();
       
   274 	}
       
   275 
       
   276 	/**
   246 	 * Gets the current directory sizes for this install.
   277 	 * Gets the current directory sizes for this install.
   247 	 *
   278 	 *
   248 	 * @since 5.6.0
   279 	 * @since 5.6.0
   249 	 *
   280 	 *
   250 	 * @return array|WP_Error
   281 	 * @return array|WP_Error
   303 	 */
   334 	 */
   304 	protected function load_admin_textdomain() {
   335 	protected function load_admin_textdomain() {
   305 		// Accounts for inner REST API requests in the admin.
   336 		// Accounts for inner REST API requests in the admin.
   306 		if ( ! is_admin() ) {
   337 		if ( ! is_admin() ) {
   307 			$locale = determine_locale();
   338 			$locale = determine_locale();
   308 			load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" );
   339 			load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo", $locale );
   309 		}
   340 		}
   310 	}
   341 	}
   311 
   342 
   312 	/**
   343 	/**
   313 	 * Gets the schema for each site health test.
   344 	 * Gets the schema for each site health test.