Automator_System_Report::get_environment_info( string[] $fields = array('environment') )


Parameters Parameters

$fields

(string[]) (Optional)

Default value: array('environment')


Top ↑

Return Return

(array)


Source Source

File: src/core/lib/utilities/class-automator-system-report.php

	public function get_environment_info( $fields = array( 'environment' ) ) {
		$enable_remote_post = $this->check_if_field_item_exists(
			'environment',
			array(
				'remote_post_successful',
				'remote_post_response',
			),
			$fields
		);

		$enable_remote_get = $this->check_if_field_item_exists(
			'environment',
			array(
				'remote_get_successful',
				'remote_get_response',
			),
			$fields
		);

		// Figure out cURL version, if installed.
		$curl_version = '';
		if ( function_exists( 'curl_version' ) ) {
			$curl_version = curl_version();
			$curl_version = $curl_version['version'] . ', ' . $curl_version['ssl_version'];
		} elseif ( extension_loaded( 'curl' ) ) {
			$curl_version = __( 'cURL installed but unable to retrieve version.', 'uncanny-automator' );
		}

		// WP memory limit.
		$wp_memory_limit = $this->automator_string_to_num( WP_MEMORY_LIMIT );
		if ( function_exists( 'memory_get_usage' ) ) {
			$wp_memory_limit = max( $wp_memory_limit, $this->automator_string_to_num( @ini_get( 'memory_limit' ) ) ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
		}

		// Test POST requests.
		$post_response_successful = null;
		$post_response_code       = null;
		if ( $enable_remote_post ) {
			$post_response_code = get_transient( 'automator_test_remote_post' );

			if ( false === $post_response_code || is_wp_error( $post_response_code ) ) {
				$response = wp_safe_remote_post(
					'https://www.automatorplugin.com/',
					array(
						'timeout'     => 10,
						'user-agent'  => 'Automator/' . AUTOMATOR_PLUGIN_VERSION,
						'httpversion' => '1.1',
						'body'        => array(
							'cmd' => '_notify-validate',
						),
					)
				);
				if ( ! is_wp_error( $response ) ) {
					$post_response_code = $response['response']['code'];
				}
				set_transient( 'automator_test_remote_post', $post_response_code, HOUR_IN_SECONDS );
			}

			$post_response_successful = ! is_wp_error( $post_response_code ) && $post_response_code >= 200 && $post_response_code < 300;
		}

		// Test GET requests.
		$get_response_successful = null;
		$get_response_code       = null;
		if ( $enable_remote_get ) {
			$get_response_code = get_transient( 'automator_test_remote_get' );

			if ( false === $get_response_code || is_wp_error( $get_response_code ) ) {
				$response = wp_safe_remote_get( 'https://www.automatorplugin.com/' );
				if ( ! is_wp_error( $response ) ) {
					$get_response_code = $response['response']['code'];
				}
				set_transient( 'automator_test_remote_get', $get_response_code, HOUR_IN_SECONDS );
			}

			$get_response_successful = ! is_wp_error( $get_response_code ) && $get_response_code >= 200 && $get_response_code < 300;
		}

		$database_version = $this->get_server_database_version();
		$environment      = array(
			'home_url'               => get_option( 'home' ),
			'site_url'               => get_option( 'siteurl' ),
			'version'                => AUTOMATOR_PLUGIN_VERSION,
			'log_directory'          => UA_DEBUG_LOGS_DIR,
			'log_directory_writable' => is_writable( dirname( UA_DEBUG_LOGS_DIR . 'test.log' ) ),
			'wp_version'             => get_bloginfo( 'version' ),
			'wp_multisite'           => is_multisite(),
			'wp_memory_limit'        => $wp_memory_limit,
			'wp_debug_mode'          => ( defined( 'WP_DEBUG' ) && WP_DEBUG ),
			'wp_cron'                => ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ),
			'language'               => get_locale(),
			'external_object_cache'  => wp_using_ext_object_cache(),
			'server_info'            => isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '',
			'php_version'            => phpversion(),
			'php_post_max_size'      => $this->automator_string_to_num( ini_get( 'post_max_size' ) ),
			'php_max_execution_time' => (int) ini_get( 'max_execution_time' ),
			'php_max_input_vars'     => (int) ini_get( 'max_input_vars' ),
			'curl_version'           => $curl_version,
			'max_upload_size'        => wp_max_upload_size(),
			'mysql_version'          => $database_version['number'],
			'mysql_version_string'   => $database_version['string'],
			'default_timezone'       => date_default_timezone_get(),
			'mbstring_enabled'       => extension_loaded( 'mbstring' ),
			'remote_post_successful' => $post_response_successful,
			'remote_post_response'   => is_wp_error( $post_response_code ) ? $post_response_code->get_error_message() : $post_response_code,
			'remote_get_successful'  => $get_response_successful,
			'remote_get_response'    => is_wp_error( $get_response_code ) ? $get_response_code->get_error_message() : $get_response_code,
		);

		// Return all environment info. Described by JSON Schema.
		return $environment;
	}