Skip to content

Instantly share code, notes, and snippets.

@zaus zaus/debug-me.php
Last active Feb 12, 2016

Embed
What would you like to do?
Simple WP debug helper "plugin"

USAGE

in your wp-config.php file rather than the usual

define('WP_DEBUG', true);

replace with

require_once('wp-content/plugins/debug-me/debug.inc.php');

or wherever it's supposed to be located. Then you can test code using the _log function.

Activate the plugin only to test the logging function above, otherwise it can remain disabled.

<?php
/*
Plugin Name: Dev Debug Me
Plugin URI: https://codex.wordpress.org/Debugging_in_WordPress
Description: Just some developer includes for debugging. Not actually a plugin; activate to test log writing.
Author: zaus
Version: 0.1
Author URI: https://gist.github.com/zaus/35c1deb8ead5baa6fc40
*/
_log('dev-debug-me', 'opened', array('foo', 'bar'));
/*
== USAGE ==
in your wp-config.php file
rather than the usual
define('WP_DEBUG', true);
replace with
require_once('wp-content/plugins/debug-me/debug.inc.php');
or wherever it's supposed to be located.
Activate the plugin only to test the logging function above, otherwise it can remain disabled.
*/
<?php
// regular WP setup
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
// toggle via url param, why not...
define('WP_DEBUG_DISPLAY', isset($_GET['display-debug-log']));
if( !function_exists('_log') ) :
function _log($args) {
$args = func_get_args();
$msg = '';
foreach($args as $arg) {
$msg = $msg . print_r($arg, true) . "\n";
}
// will write to debug.log file, etc
// tack on some padding so trace shows up more nicely
trigger_error('@@ USER-LOG @@' . "\n" . $msg . "\t\t");
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.