-
-
Save chuckreynolds/1821789bd625854b2397 to your computer and use it in GitHub Desktop.
my list of debugging functions to keep in an MU file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Norcross Debug Functions | |
Plugin URI: https://gist.github.com/norcross/7864205/ | |
Description: A set of functions I use on all sites while building | |
Author: Andrew Norcross | |
Version: 0.0.1 | |
Requires at least: 3.0 | |
Author URI: http://andrewnorcross.com | |
*/ | |
function rkv_bypass_auto_update_email( $send, $type, $core_update, $result ) { | |
// check our type and bail if successful | |
if ( ! empty( $type ) && $type == 'success' ) { | |
return false; | |
} | |
// return the send function | |
return true; | |
} | |
add_filter( 'auto_core_update_send_email', 'rkv_bypass_auto_update_email', 10, 4 ); | |
/** | |
* display array results in a readable fashion | |
* | |
* @param [type] $s [description] | |
* @param boolean $die [description] | |
* @param boolean $return [description] | |
* @return [type] [description] | |
*/ | |
function preprint( $s, $die = false, $return = false ) { | |
// set an empty | |
$code = ''; | |
// some CSS to make it a bit more readable | |
$style = 'background-color: #fff; white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: break-word;'; | |
// the code itself | |
$code .= '<pre style="' . $style . '">'; | |
$code .= print_r( $s, 1 ); | |
$code .= '</pre>'; | |
// return if requested | |
if ( $return ) { | |
return $code; | |
} | |
// print if requested ( the default ) | |
if ( ! $return ) { | |
print $code; | |
} | |
// die if you want to die | |
if ( $die ) { | |
die(); | |
} | |
} | |
/* | |
* | |
* Debugging Convenience function | |
* | |
* Shows all the "filters" currently attached to a hook | |
* | |
* ex. | |
* print_filters_for('the_content'); | |
* | |
*/ | |
function print_filters_for( $hook = '' ) { | |
global $wp_filter; | |
if( empty( $hook ) || !isset( $wp_filter[$hook] ) ) | |
return; | |
print '<pre>'; | |
print_r( $wp_filter[$hook] ); | |
print '</pre>'; | |
} | |
/** | |
* [fullquery description] | |
* @return [type] [description] | |
*/ | |
function fullquery() { | |
global $wp_query; | |
preprint( $wp_query, true ); | |
} | |
/** | |
* Suppress errors generated by specified WordPress plugins. | |
* | |
* Include in the auto_prepend_file php.ini directive to ignore globally. Update | |
* the directory separator as required. | |
* | |
* @see http://plugins.trac.wordpress.org/browser/ostrichcize/tags/0.1/ostrichcize.php#L146 | |
* | |
* @param string $errno The error number. | |
* @param string $errstr The error message. | |
* @param string $errfile Path to the file that caused the error. | |
* @param int $errline Line number of the error. | |
* @return bool True to success error reporting; false to use default error handler. | |
*/ | |
function blazersix_wpdev_error_handler( $errno, $errstr, $errfile, $errline ) { | |
$paths = array( | |
'plugins\\wordpress-importer\\' | |
); | |
foreach ( $paths as $path ) { | |
if ( false !== strpos( $errstr, $path ) ) { | |
return true; | |
} | |
if ( false !== strpos( $errfile, $path ) ) { | |
return true; | |
} | |
} | |
// The path was not found, so report the error. | |
return false; | |
} | |
set_error_handler( 'blazersix_wpdev_error_handler' ); | |
/* | |
* | |
* parse a JSON item | |
* | |
* json_parse($variable); | |
* | |
*/ | |
function json_parse($text){ | |
$parsedText = str_replace('\n', '', $text); | |
return str_replace('\t', '', $parsedText); | |
} | |
/** | |
* set up some quick links for the admin bar | |
* | |
* @param WP_Admin_Bar $wp_admin_bar [description] | |
* @return [type] [description] | |
*/ | |
function rkv_admin_bar_static( WP_Admin_Bar $wp_admin_bar ) { | |
// bail if current user doesnt have cap | |
if ( ! current_user_can( 'manage_options' ) ) { | |
return; | |
} | |
// remove customizer | |
$wp_admin_bar->remove_node( 'customize' ); | |
// add a parent item | |
$wp_admin_bar->add_node( | |
array( | |
'id' => 'rkv-dev-links', | |
'title' => 'RKV Dev Links', | |
) | |
); | |
// add GitHub issues | |
$wp_admin_bar->add_node( | |
array( | |
'id' => 'github-issues', | |
'title' => 'GitHub Issues', | |
'href' => 'https://github.com/project-name/issues', | |
'position' => 0, | |
'parent' => 'rkv-dev-links', | |
'meta' => array( | |
'title' => 'GitHub Issues', | |
'target' => '_blank' | |
) | |
) | |
); | |
// add CMB2 wiki | |
$wp_admin_bar->add_node( | |
array( | |
'id' => 'cmb2-wiki-site', | |
'title' => 'CMB2 Wiki', | |
'href' => 'https://github.com/WebDevStudios/CMB2/wiki/', | |
'parent' => 'rkv-dev-links', | |
'position' => 0, | |
'meta' => array( | |
'title' => 'CMB2 Wiki', | |
'target' => '_blank' | |
) | |
) | |
); | |
// add live staging site | |
$wp_admin_bar->add_node( | |
array( | |
'id' => 'staging-site', | |
'title' => 'Staging Site', | |
'href' => 'http://devsite-url.com/', | |
'parent' => 'rkv-dev-links', | |
'position' => 0, | |
'meta' => array( | |
'title' => 'Staging Site', | |
'target' => '_blank' | |
) | |
) | |
); | |
} | |
add_action( 'admin_bar_menu', 'rkv_admin_bar_static', 9999 ); | |
/** | |
* [rkv_auto_login description] | |
* @return [type] [description] | |
*/ | |
function rkv_auto_login() { | |
// bail on ajax | |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { | |
return; | |
} | |
// allow for test log out | |
if ( isset( $_GET['testlogout'] ) ) { | |
// handle the logout | |
wp_logout(); | |
// clear the auth cookies | |
wp_clear_auth_cookie(); | |
// and return | |
return; | |
} | |
// bail if the user is logged in | |
if ( is_user_logged_in() ) { | |
return; | |
} | |
// get the user | |
$user = get_userdata( 1 ); // 1 being the ID that I want | |
// bail if I don't have userdata | |
if ( empty( $user ) || ! is_object( $user ) ) { | |
return; | |
} | |
// set the current user | |
wp_set_current_user( $user->ID, $user->user_login ); | |
// set the auth cookie | |
wp_set_auth_cookie( $user->ID ); | |
// now actually log in | |
do_action( 'wp_login', $user->user_login ); | |
} | |
add_action( 'init', 'rkv_auto_login' ); | |
add_action( 'admin_init', 'rkv_auto_login' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment