WP-Mix

A fresh mix of code snippets and tutorials

Get WP, PHP, and SQL Info

Here are some sweet code snippets for getting various types of server information. Includes more functions for getting and/or checking various types of WordPress, PHP, and SQL data. Strictly plug-&-play for quick reference and copy/paste usage.

WordPress: Check the database table prefix:

// check table prefix
function shapeSpace_check_wp_prefix() {
	
    if ($GLOBALS['table_prefix'] === 'wp_') {
        echo 'fail';
    } else {
        echo 'pass';
    }
    
}

WordPress: Check the wp-config.php file:

// check wp-config.php
function shapeSpace_check_wp_config($path) {
	
	if (!is_writable($path)) {
		return 'pass';
	}
	
	if (!function_exists('file') || !function_exists('file_get_contents') || !function_exists('file_put_contents')) {
		return 'pass';
	} else {
		return 'fail';
	}
	
}

PHP: Check XML support

// check php xml support
function shapeSpace_check_php_xml() {
	
	if (is_callable('xml_parser_create')) {
		return 'pass';
	} else {
		return 'fail';
	}

}

PHP: Check IPTC support

// check php iptc support
function shapeSpace_check_php_iptc() {
	
	if (is_callable('iptcparse')) {
		return 'pass';
	} else {
		return 'fail';
	}
	
}

PHP: Check EXIF support

// check php exif support
function shapeSpace_check_php_exif() {
	
	if (is_callable('exif_read_data')) {
		// substr(phpversion('exif'), 0, 4)
		return 'pass';
	} else {
		return 'fail';
	}
	
}

SQL: Get SQL version

// get sql version
function shapeSpace_get_sql_version() {
	
	global $wpdb;
	
	return $wpdb->get_var('SELECT VERSION() AS version');
	
}

SQL: Get SQL info

// get sql info
function shapeSpace_get_sql_info() {
	
	global $wpdb;
	
	$sqlvar = $wpdb->get_results("SHOW VARIABLES LIKE 'sql_mode'");
	
	$sqlmode = 'n/a';
	
	if (is_array($sqlvar)) {
		$sqlmode = $sqlvar[0]->Value;
	}
	
	return $sqlmode;
	
}

Related

Learn more

Digging Into WordPressWordPress Themes In DepthWizard’s SQL Recipes for WordPress