Last active
April 28, 2021 13:14
-
-
Save AashikP/408583ddd7ad504b613915104507738d to your computer and use it in GitHub Desktop.
var_dump as dashboard notice.
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 | |
/** | |
* Function to var_dump contents as WordPress Dashboard notification. | |
* | |
* Instructions: | |
* Optional argument $file can be supplied as __FILE__ $line supplied as __LINE__ if you also want to | |
* print out the file and line number (for whatever reason) where this function is called. | |
* | |
* @param variable $dump_this Will dump the variable as an admin notice. | |
* @param string $file Original file link. | |
* @param string $line number where the functino is executed. | |
*/ | |
function dd( $dump_this, $file = 'NA', $line = 'NA' ) { | |
add_action( | |
'admin_notices', | |
function () use ( $dump_this, $file, $line ) { | |
echo '<div class="notice is-dismissible">'; | |
if ( 'NA' !== $file ) { | |
echo '<span style="color:#be5046;font-weight:600">' . esc_html( $file ) . '</span>'; | |
} | |
if ( 'NA' !== $line ) { | |
echo '<span style="color:#98c379;font-weight:600"> : ' . esc_html( $line ) . '</span>'; | |
} | |
var_dump( $dump_this ); // phpcs:ignore | |
echo '</div>'; | |
return; | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment