WP_Site_Health::get_test_file_uploads() WordPress Method
The WP_Site_Health::get_test_file_uploads() function is used to test if the WordPress installation can upload files. This is important for WordPress installations that need to be able to upload files, for example when installing plugins or themes.
WP_Site_Health::get_test_file_uploads() #
Test if ‘file_uploads’ directive in PHP.ini is turned off.
Return
(array) The test results.
Source
File: wp-admin/includes/class-wp-site-health.php
public function get_test_file_uploads() { $result = array( 'label' => __( 'Files can be uploaded' ), 'status' => 'good', 'badge' => array( 'label' => __( 'Performance' ), 'color' => 'blue', ), 'description' => sprintf( '<p>%s</p>', sprintf( /* translators: 1: file_uploads, 2: php.ini */ __( 'The %1$s directive in %2$s determines if uploading files is allowed on your site.' ), '<code>file_uploads</code>', '<code>php.ini</code>' ) ), 'actions' => '', 'test' => 'file_uploads', ); if ( ! function_exists( 'ini_get' ) ) { $result['status'] = 'critical'; $result['description'] .= sprintf( /* translators: %s: ini_get() */ __( 'The %s function has been disabled, some media settings are unavailable because of this.' ), '<code>ini_get()</code>' ); return $result; } if ( empty( ini_get( 'file_uploads' ) ) ) { $result['status'] = 'critical'; $result['description'] .= sprintf( '<p>%s</p>', sprintf( /* translators: 1: file_uploads, 2: 0 */ __( '%1$s is set to %2$s. You won\'t be able to upload files on your site.' ), '<code>file_uploads</code>', '<code>0</code>' ) ); return $result; } $post_max_size = ini_get( 'post_max_size' ); $upload_max_filesize = ini_get( 'upload_max_filesize' ); if ( wp_convert_hr_to_bytes( $post_max_size ) < wp_convert_hr_to_bytes( $upload_max_filesize ) ) { $result['label'] = sprintf( /* translators: 1: post_max_size, 2: upload_max_filesize */ __( 'The "%1$s" value is smaller than "%2$s"' ), 'post_max_size', 'upload_max_filesize' ); $result['status'] = 'recommended'; if ( 0 === wp_convert_hr_to_bytes( $post_max_size ) ) { $result['description'] = sprintf( '<p>%s</p>', sprintf( /* translators: 1: post_max_size, 2: upload_max_filesize */ __( 'The setting for %1$s is currently configured as 0, this could cause some problems when trying to upload files through plugin or theme features that rely on various upload methods. It is recommended to configure this setting to a fixed value, ideally matching the value of %2$s, as some upload methods read the value 0 as either unlimited, or disabled.' ), '<code>post_max_size</code>', '<code>upload_max_filesize</code>' ) ); } else { $result['description'] = sprintf( '<p>%s</p>', sprintf( /* translators: 1: post_max_size, 2: upload_max_filesize */ __( 'The setting for %1$s is smaller than %2$s, this could cause some problems when trying to upload files.' ), '<code>post_max_size</code>', '<code>upload_max_filesize</code>' ) ); } return $result; } return $result; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.5.0 | Introduced. |