Skip to content

Commit

Permalink
Debug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Tikhomirov committed Apr 17, 2023
1 parent 5ff681a commit 48da656
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 75 deletions.
51 changes: 27 additions & 24 deletions functions/helpers.php → functions/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<script type="text/javascript" name="woo2iiko_debugger">console.log(\'wp debug\', ' . $wp_query->debug_log . '); </script>';
$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' ) ) {
Expand Down Expand Up @@ -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' );
}

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 '<script type="text/javascript" name="woo2iiko_debugger">console.log(\'wp debug\', ' . $wp_query->debug_log . '); </script>';
$wp_query->debug_showed = true;
}
}
}

51 changes: 0 additions & 51 deletions functions/debug/debug.php

This file was deleted.

0 comments on commit 48da656

Please sign in to comment.