Automattic\WooCommerce\Internal\Admin
SiteHealth::get_uploads_directory_browsing_status
Check whether the WooCommerce uploads directory lists its files when requested from the web.
Method of the class: SiteHealth{}
No Hooks.
Returns
string. 'protected', 'unprotected', or 'unverified'.
Usage
// private - for code of main (parent) class only $result = $this->get_uploads_directory_browsing_status(): string;
SiteHealth::get_uploads_directory_browsing_status() SiteHealth::get uploads directory browsing status code WC 11.3.0
private function get_uploads_directory_browsing_status(): string {
$uploads = wp_get_upload_dir();
$response = wp_safe_remote_get(
esc_url_raw( $uploads['baseurl'] . '/woocommerce_uploads/' ),
array(
'redirection' => 0,
)
);
if ( is_wp_error( $response ) ) {
return 'unverified';
}
$response_code = intval( wp_remote_retrieve_response_code( $response ) );
if ( 0 === $response_code ) {
return 'unverified';
}
return ( 200 !== $response_code || empty( wp_remote_retrieve_body( $response ) ) ) ? 'protected' : 'unprotected';
}