wp_check_php_mysql_versions

函式
wp_check_php_mysql_versions ( No parameters )

wp_check_php_mysql_versions: 這是一個檢查當前版本的PHP和MySQL是否與WordPress相容的函式。它可以用來確保WordPress網站執行在與WordPress相容的PHP和MySQL版本上。

檢查所需的PHP版本,以及MySQL擴充套件或資料庫落入。

如果不符合要求,則拒絕。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_check_php_mysql_versions() {
global $required_php_version, $wp_version;
$php_version = PHP_VERSION;
if ( version_compare( $required_php_version, $php_version, '>' ) ) {
$protocol = wp_get_server_protocol();
header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
header( 'Content-Type: text/html; charset=utf-8' );
printf( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.', $php_version, $wp_version, $required_php_version );
exit( 1 );
}
if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' )
// This runs before default constants are defined, so we can't assume WP_CONTENT_DIR is set yet.
&& ( defined( 'WP_CONTENT_DIR' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' )
|| ! file_exists( ABSPATH . 'wp-content/db.php' ) )
) {
require_once ABSPATH . WPINC . '/functions.php';
wp_load_translations_early();
$args = array(
'exit' => false,
'code' => 'mysql_not_found',
);
wp_die(
__( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ),
__( 'Requirements Not Met' ),
$args
);
exit( 1 );
}
}
function wp_check_php_mysql_versions() { global $required_php_version, $wp_version; $php_version = PHP_VERSION; if ( version_compare( $required_php_version, $php_version, '>' ) ) { $protocol = wp_get_server_protocol(); header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 ); header( 'Content-Type: text/html; charset=utf-8' ); printf( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.', $php_version, $wp_version, $required_php_version ); exit( 1 ); } if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) // This runs before default constants are defined, so we can't assume WP_CONTENT_DIR is set yet. && ( defined( 'WP_CONTENT_DIR' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) || ! file_exists( ABSPATH . 'wp-content/db.php' ) ) ) { require_once ABSPATH . WPINC . '/functions.php'; wp_load_translations_early(); $args = array( 'exit' => false, 'code' => 'mysql_not_found', ); wp_die( __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ), __( 'Requirements Not Met' ), $args ); exit( 1 ); } }
function wp_check_php_mysql_versions() {
	global $required_php_version, $wp_version;
	$php_version = PHP_VERSION;

	if ( version_compare( $required_php_version, $php_version, '>' ) ) {
		$protocol = wp_get_server_protocol();
		header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 );
		header( 'Content-Type: text/html; charset=utf-8' );
		printf( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.', $php_version, $wp_version, $required_php_version );
		exit( 1 );
	}

	if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' )
		// This runs before default constants are defined, so we can't assume WP_CONTENT_DIR is set yet.
		&& ( defined( 'WP_CONTENT_DIR' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' )
			|| ! file_exists( ABSPATH . 'wp-content/db.php' ) )
	) {
		require_once ABSPATH . WPINC . '/functions.php';
		wp_load_translations_early();
		$args = array(
			'exit' => false,
			'code' => 'mysql_not_found',
		);
		wp_die(
			__( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ),
			__( 'Requirements Not Met' ),
			$args
		);
		exit( 1 );
	}
}

常見問題

FAQs
檢視更多 >