diff --git a/functions/helpers.php b/functions/debug.php similarity index 73% rename from functions/helpers.php rename to functions/debug.php index f12085d..4aeb3bc 100644 --- a/functions/helpers.php +++ b/functions/debug.php @@ -3,31 +3,16 @@ * Debug helpers. Unused in actions */ -if ( ! function_exists( 'console_log' ) ) { - function console_log($data){ - global $wp_query, $current_user; - $wp_query->debug_log = _log($data); - $wp_query->debug_showed = false; - if (isset($current_user) && $current_user instanceof WP_User && $current_user->has_cap('manage_options')) { - add_action('admin_head', 'show_in_console'); - add_action('admin_footer', 'show_in_console', 99); - add_action('wp_head', 'show_in_console', 99); - add_action('wp_footer', 'show_in_console'); - } - } -} -function show_in_console(){ - global $wp_query; - if(!$wp_query->debug_showed) { - echo ''; - $wp_query->debug_showed = true; +if(!function_exists('change_log_file_location')): + add_action('mu_plugin_loaded', 'change_log_file_location'); + function change_log_file_location(){ + ini_set( 'error_log', WP_CONTENT_DIR . '/hidden-debug.log' ); } -} +endif; /** * Simple debug trace to wp-content/debug.log - * * @usage _log( $var ); */ if ( ! function_exists( '_log' ) ) { @@ -56,7 +41,25 @@ function _log( $log ) { } } -add_action('mu_plugin_loaded', 'change_log_file_location'); -function change_log_file_location(){ - ini_set( 'error_log', WP_CONTENT_DIR . '/hidden-debug.log' ); -} \ No newline at end of file + +if ( ! function_exists( 'console_log' ) ) { + function console_log($data){ + global $wp_query, $current_user; + $wp_query->debug_log = _log($data); + $wp_query->debug_showed = false; + if (isset($current_user) && $current_user instanceof WP_User && $current_user->has_cap('manage_options')) { + add_action('admin_head', 'show_in_console'); + add_action('admin_footer', 'show_in_console', 99); + add_action('wp_head', 'show_in_console', 99); + add_action('wp_footer', 'show_in_console'); + } + } + function show_in_console(){ + global $wp_query; + if(!$wp_query->debug_showed) { + echo ''; + $wp_query->debug_showed = true; + } + } +} + diff --git a/functions/debug/debug.php b/functions/debug/debug.php deleted file mode 100644 index 354e4cb..0000000 --- a/functions/debug/debug.php +++ /dev/null @@ -1,51 +0,0 @@ -debug_data = $data; - - switch ($mode){ - case 'console': - add_action('wp_head', 'console'); - add_action('admin_head', 'console'); - break; - case 'log': - error_log(print_r($wp_query->debug_data, true)); - break; - default: - global $wp_query; - echo '
';
-			print_r($data ?? $wp_query->debug_data);
-			echo '
'; - break; - } -} -endif; - -if(!function_exists('console_log')): -function console_log($data = null){ - debug($data, 'log'); - console($data); -} -endif; - -if(!function_exists('console')): -function console($data = null){ - global $wp_query; - - $json_data = addcslashes(json_encode($data ?? $wp_query->debug_data ?? '', JSON_FORCE_OBJECT),'\'\\'); - ?> - -