Last active
January 10, 2024 18:30
-
-
Save ianpegg/b92324d6e1e1078bd47da0f27e300bf3 to your computer and use it in GitHub Desktop.
Provides utilities for DEV and STAGING sites.
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 | |
/** | |
* Plugin Name: EggMUP: Utilities | |
* Plugin URI: https://gist.github.com/ianpegg/b92324d6e1e1078bd47da0f27e300bf3 | |
* Description: Provides utilities for DEV and STAGING sites. | |
* Version: 1.0.0 | |
* Author: Ian Pegg | |
* Author URI: https://eggcupwebdesign.com | |
* Use this statement to include this library in other scripts | |
* <?php use EggCup\MUP\Utilities as Utilities; ?> | |
* Then call a namespaced function like so: | |
* <?php Utilities\_show($mixed); ?> | |
* php version 7.4.15 | |
* | |
* @category Must_Use_Plugin | |
* @package WordPress_Plugin | |
* @author Ian Pegg <[email protected]> | |
* @license GNU/GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt | |
* @link https://eggcupwebdesign.com | |
*/ | |
namespace EggCup\MUP\Utilities; | |
if (!defined('ABSPATH')) { | |
exit; | |
} | |
/** | |
* Custom variable dump function, automatically handles both arrays and strings | |
* | |
* @param Mixed $Mix_display Variable to be printed | |
* | |
* @return void | |
*/ | |
function _show($Mix_display) | |
{ | |
// if we're running in production mode, print nothing | |
if ('production' === wp_get_environment_type()) { | |
_log($Mix_display, '_show called in production, logging instead: '); | |
return; | |
} | |
$Str_trace = 'Debug message -- '; | |
if (is_array($Mix_display) or is_object($Mix_display)) { | |
echo $Str_trace; | |
echo '<pre>'; | |
print_r($Mix_display); | |
echo '</pre>'; | |
} else { | |
echo $Str_trace . $Mix_display; | |
} | |
} | |
/** | |
* Custom error logging function, automatically handles both arrays and strings | |
* | |
* @param Mixed $Mix_log Variable to be printed | |
* @param String $Str_trace Trace string to print before variable | |
* | |
* @return void | |
*/ | |
function _log($Mix_log, $Str_trace = 'Log message -- ') | |
{ | |
if (is_array($Mix_log) or is_object($Mix_log)) { | |
error_log(print_r($Mix_log, true)); | |
} else { | |
error_log($Str_trace . $Mix_log); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment