Skip to content

Instantly share code, notes, and snippets.

@gabssnake
Last active December 17, 2015 15:19
Show Gist options
  • Save gabssnake/5630734 to your computer and use it in GitHub Desktop.
Save gabssnake/5630734 to your computer and use it in GitHub Desktop.
wordpress wp-config file bits to make life easier. not to use complete
<?php
// method A : uses uri string, like 'localhost'
// change settings if on local or remote
// lets you share the same config file in dev and prod
if (strpos($_SERVER['HTTP_HOST'], 'localhost') === false) {
// production
define('DB_NAME', 'database');
define('DB_USER', 'username');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');
define('WP_DEBUG', false);
} else {
// development
define('DB_NAME', 'database');
define('DB_USER', 'user');
define('DB_PASSWORD', 'pass');
define('DB_HOST', 'localhost');
define('WP_HOME', 'http://'.$_SERVER['HTTP_HOST'].'/blog');
define('WP_SITEURL','http://'.$_SERVER['HTTP_HOST'].'/blog');
define('WP_POST_REVISIONS', false);
define('WP_DEBUG', true);
}
// method B : uses existence of local config file
// can go at end of file to override production settings
// lets you separate dev and prod configs
if (file_exists( dirname( __FILE__ ).'/wp-config.local.php')) {
include(dirname(__FILE__).'/wp-config.local.php');
}
// site address
define('WP_HOME', 'http://'.$_SERVER['HTTP_HOST'].'/blog');
define('WP_SITEURL','http://'.$_SERVER['HTTP_HOST'].'/blog');
// memory limit
define('WP_MEMORY_LIMIT', '64M');
// revsions
define('WP_POST_REVISIONS', true); // revisions
define('AUTOSAVE_INTERVAL', 240); // in seconds
define('WP_POST_REVISIONS', 3); // limit revisions
// when to empty trash (default is 30)
define('EMPTY_TRASH_DAYS', 7); // amount of days
// disable direct file editing from wp backend
define('DISALLOW_FILE_EDIT', true);
// disable installing new themes and plugins
define('DISALLOW_FILE_MODS',true);
// FTP
define('FS_METHOD', 'ftpext');
define('FTP_USER', 'username');
define('FTP_PASS', 'password');
define('FTP_HOST', 'ftp.example.org:21');
// direct instead of FTP for plugin/theme upload
// may crash some servers. use instead of ftp credentials
define('FS_METHOD', 'direct');
// move content directories
define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content' );
define( 'WP_CONTENT_URL', 'http://example/blog/wp-content');
define( 'WP_PLUGIN_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content/plugins' );
define( 'WP_PLUGIN_URL', 'http://example/blog/wp-content/plugins');
// force ftp paths
define('FTP_BASE', '/path/to/wordpress/');
define('FTP_CONTENT_DIR', '/path/to/wordpress/wp-content/');
define('FTP_PLUGIN_DIR ', '/path/to/wordpress/wp-content/plugins/');
// errors logging
define('WP_DEBUG', true); // enables error reporting
define('WP_DEBUG_DISPLAY', false); // hides the errors
define('WP_DEBUG_LOG', true); // uses @ini_set('error_log')
@ini_set('error_log', '/home/path/domain/logs/php_error.log'); // not required, defaults to 'wp-content/error.log'
// to debug slow queries (logs function, query, and time)
// then print somewhere in the theme
// if (current_user_can('level_10')) { global $wpdb; echo "<pre>"; print_r($wpdb->queries); echo "</pre>"; }
define('SAVEQUERIES', true);
// cache
define('WP_CACHE', false); // disable the cache
define('DISABLE_CACHE', true); // disable the cache
// disable proxies or create intranets
define('WP_HTTP_BLOCK_EXTERNAL', true); // block external requests
define('WP_HTTP_BLOCK_EXTERNAL', false); // allow external requests
define('WP_ACCESSIBLE_HOSTS', 'api.wordpress.org'); // whitelist hosts
// use url to activate or deactivate debug
// like: http://www.wprecipes.com/contact?debug=debug
// BEWARE ef security my friend
if (isset($_GET['debug']) && $_GET['debug'] == 'true') { define('WP_DEBUG', true); }
// define template and style paths
define('TEMPLATEPATH', get_template_directory());
define('STYLESHEETPATH', get_stylesheet_directory());
// allow DB repair
// config at: http://site.com/wp-admin/maint/repair.php
define('WP_ALLOW_REPAIR', true);
// try to guess DB server
define('DB_HOST', $_ENV{DATABASE_SERVER});
// activate relocation
// automodifies the site url according the address used to loggin
// http://codex.wordpress.org/Changing_The_Site_URL#Relocate_method
define('RELOCATE', true);
// wp backend javascripts are concatenated by dufault
define('CONCATENATE_SCRIPTS', false);
define('SCRIPT_DEBUG', true);
// protect wp-config.php with htaccess
// # protect wpconfig.php
// <files wp-config.php>
// order allow,deny
// deny from all
// </files>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment