Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukecav/f4b37bb9dac1c9d5f7ae099aa599b557 to your computer and use it in GitHub Desktop.
Save lukecav/f4b37bb9dac1c9d5f7ae099aa599b557 to your computer and use it in GitHub Desktop.
Add button to clear the WooCommerce logs in System Status Tools
// 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