WP_Site_Health::get_test_file_uploads

Advertisement

Summery Summery

Test if ‘file_uploads’ directive in PHP.ini is turned off.

Syntax Syntax

WP_Site_Health::get_test_file_uploads()

Return Return

(array) The test results.

Source 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';
			$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;
	}

Advertisement

Changelog Changelog

Changelog
Version Description
5.5.0 Introduced.

Advertisement

Leave a Reply