Last active
March 10, 2022 14:07
-
-
Save developer-anuragsingh/3672243f21b3c06b4826fc696589e4b0 to your computer and use it in GitHub Desktop.
WP - Custom functions to debug website coding errors
This file contains hidden or 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 | |
| // 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