-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.php
54 lines (47 loc) · 1.27 KB
/
util.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Conifer utility functions
*
* @copyright 2018 SiteCrafting, Inc.
* @author Coby Tamayo <ctamayo@sitecrafting.com>
*/
/**
* Log stuff to wp-content/debug.log, with a prefix so you can pipe
* to a grep to filter out irrelevant log entries.
* Assumes you have WP debugging configured like so in wp-config.php:
* define('WP_DEBUG', true);
* define('WP_DEBUG_DISPLAY', false);
* define('WP_DEBUG_LOG', true);
* @param mixed $message the message or other value to log. If not a string, gets var_export'ed
* @package Conifer
*/
function debug($message) {
if(!is_string($message)) {
$message = var_export($message,true);
}
// break up message by line and prefix each one
error_log( implode("\n", array_map(function($line) {
return "debug $line";
}, explode("\n", $message))));
}
/**
* Variadic (sprintf() style) version of debug(). Calls sprintf() internally.
* @package Conifer
*/
function sdebug() {
// TODO use the PHP 7 spread operator! :D
debug(call_user_func_array('sprintf', func_get_args()));
}
/**
* Die on $message
* @package Conifer
*/
function debug_die($message, $pre = true) {
if (!is_string($message)) {
$message = var_export($message, true);
}
if ($pre) {
echo '<pre>';
}
die($message);
}