Created
October 25, 2019 14:18
-
-
Save ChromeOrange/0853adfb17f8c0e02a58ee8eb0d5fbaf to your computer and use it in GitHub Desktop.
Add button to clear the WooCommerce logs in System Status -> Tools
This file contains 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
// Add to your custom functions | |
// Uses apply_filters( 'woocommerce_debug_tools', $tools ) | |
add_filter( 'woocommerce_debug_tools', 'woocommerce_debug_tools_remove_logs' ); | |
function woocommerce_debug_tools_remove_logs( $tools ) { | |
// Disbale Remove Logs button | |
$disable_remove_logs = apply_filters( 'woocommerce_disable_woocommerce_debug_tools_remove_logs', FALSE ); | |
if( !$disable_remove_logs ) { | |
$tools['remove_logs'] = array( | |
'name' => __( 'Remove all the logs.', 'woocommerce' ), | |
'button' => __( 'Remove logs', 'woocommerce' ), | |
'desc' => __( 'This will remove all of the log files created by WooCommerce and WooCommerce plugins.', 'woocommerce' ), | |
'callback' => 'woocommerce_debug_tools_execute_remove_logs', | |
); | |
} | |
return $tools; | |
} | |
function woocommerce_debug_tools_execute_remove_logs() { | |
$log_dir = WC_LOG_DIR; | |
foreach( scandir( $log_dir ) as $file ) { | |
$path = pathinfo( $file ); | |
// Only delete log files, don't delete the test.log file | |
if ( $path['extension'] === 'log' && $path['filename'] !== 'test' ) { | |
unlink( "{$log_dir}/{$file}" ); | |
} | |
} | |
return __( 'Log files deleted', 'woocommerce' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment