WC_Admin_Notices::is_uploads_directory_protected()
Check if uploads directory is protected.
Метод класса: WC_Admin_Notices{}
Хуков нет.
Возвращает
true|false
.
Использование
$result = WC_Admin_Notices::is_uploads_directory_protected();
Список изменений
С версии 4.2.0 | Введена. |
Код WC_Admin_Notices::is_uploads_directory_protected() WC Admin Notices::is uploads directory protected WC 9.4.2
protected static function is_uploads_directory_protected() { $cache_key = '_woocommerce_upload_directory_status'; $status = get_transient( $cache_key ); // Check for cache. if ( false !== $status ) { return 'protected' === $status; } // Get only data from the uploads directory. $uploads = wp_get_upload_dir(); // Check for the "uploads/woocommerce_uploads" directory. $response = wp_safe_remote_get( esc_url_raw( $uploads['baseurl'] . '/woocommerce_uploads/' ), array( 'redirection' => 0, ) ); $response_code = intval( wp_remote_retrieve_response_code( $response ) ); $response_content = wp_remote_retrieve_body( $response ); // Check if returns 200 with empty content in case can open an index.html file, // and check for non-200 codes in case the directory is protected. $is_protected = ( 200 === $response_code && empty( $response_content ) ) || ( 200 !== $response_code ); set_transient( $cache_key, $is_protected ? 'protected' : 'unprotected', 1 * DAY_IN_SECONDS ); return $is_protected; }