-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
84 lines (77 loc) · 2.23 KB
/
functions.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* Logs a message to a specified directory.
*
* @param mixed $message The message to be logged.
* @param bool $trace Whether to log the backtrace.
* @param string $dir The directory where the log file will be written.
*
* @return void
* @throws \Exception
*/
function write_log( $message, bool $trace = false, string $dir = WP_CONTENT_DIR ) {
DevKabir\WPDebugger\Plugin::get_instance()->log( $message, $trace, $dir );
}
/**
* Debug from called spot.
*
* @return void
* @throws Exception
*/
function init_debugger() {
DevKabir\WPDebugger\Plugin::get_instance()->throw_exception();
}
/**
* Outputs a formatted dump of a variable for debugging purposes.
*
* @param mixed $variable The variable to dump.
* @return void
*/
function dump( $variable ) {
$compiled_data = DevKabir\WPDebugger\Template::compile( array( '{{content}}' => var_export( $variable, true ) ), DevKabir\WPDebugger\Template::get_part( 'dump' ) );
echo DevKabir\WPDebugger\Template::compile( array( '{{content}}' => $compiled_data ), DevKabir\WPDebugger\Template::get_layout() );
}
/**
* Dump a variable and stop execution.
*
* @param mixed $data The variable to dump.
*
* @return void
*/
function dd( $data ) {
dump( $data );
die;
}
/**
* Renders a checkbox field in the WordPress settings page.
*
* @param array $args { .
* @var string $id The ID of the option to be saved in the database.
* @var string $label The label for the checkbox.
*
* @see add_settings_field()
* }
*
* @return void
*/
function render_settings_fields( $args ) {
$option = get_option( $args['id'] );
echo '<input type="checkbox" id="' . $args['id'] . '" name="' . $args['id'] . '" value="1"' . checked( 1, $option, false ) . ' />';
echo '<label for="' . $args['id'] . '"> ' . $args['label'] . '</label>';
}
/**
* Retrieves the value of the `show_debugbar` option from the database.
*
* @return bool Whether the debug bar should be shown.
*/
function show_debugbar() {
return (bool) get_option( 'show_debugbar', false );
}
/**
* Retrieves the value of the `enable_debugger` option from the database.
*
* @return bool Whether the debugger should be enabled.
*/
function enable_debugger() {
return (bool) get_option( 'enable_debugger', false );
}