Skip to content

Instantly share code, notes, and snippets.

@developer-anuragsingh
Last active March 10, 2022 14:07
Show Gist options
  • Select an option

  • Save developer-anuragsingh/3672243f21b3c06b4826fc696589e4b0 to your computer and use it in GitHub Desktop.

Select an option

Save developer-anuragsingh/3672243f21b3c06b4826fc696589e4b0 to your computer and use it in GitHub Desktop.
WP - Custom functions to debug website coding errors
<?php
// get current template name (php file)
// global $template;
// echo basename($template);
add_filter('show_admin_bar', '__return_false'); // Hide admin bar from frontend
function show_file_path(){
if( isset($_REQUEST['dev']) && (1 == $_REQUEST['dev']) ):
if( isset($_REQUEST['show_file_path']) && (1 == $_REQUEST['show_file_path']) ):
$debug_backtrack = debug_backtrace();
$file_path = $debug_backtrack[0]['file'];
echo '<br />---------------------- <br />';
echo '<b>File Path -</b> ' . $file_path;
echo '<br />----------------------<br />';
endif;
endif;
}
// Function to print array value along with array holding var name
function as_debug( $arr ) {
foreach ( $GLOBALS as $var_name => $value ) {
if ( $value === $arr ) {
echo '---------------------</br>';
echo 'Var Name => <b>' . $var_name . '</b></br>';
echo '---------------------</br>';
echo '<pre>';
print_r( $arr );
echo '</pre>';
echo '---------------------</br>';
}
}
}
// Print Array Values
as_debug( $arr );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment