-
Notifications
You must be signed in to change notification settings - Fork 65
/
add-button-to-clear-the-woocommerce-logs-in-system-status-tools.code-snippets.json
1 lines (1 loc) · 1.46 KB
/
add-button-to-clear-the-woocommerce-logs-in-system-status-tools.code-snippets.json
1
{"generator":"Code Snippets v2.14.0","date_created":"2020-05-31 23:09","snippets":[{"name":"Add button to clear the WooCommerce logs in System Status Tools","tags":["system","status","tools","log","clear","woocommerce"],"scope":"admin","code":"\/\/ Uses apply_filters( 'woocommerce_debug_tools', $tools )\nadd_filter( 'woocommerce_debug_tools', 'woocommerce_debug_tools_remove_logs' );\n\nfunction woocommerce_debug_tools_remove_logs( $tools ) {\n\t\n\t\/\/ Disbale Remove Logs button\n\t$disable_remove_logs = apply_filters( 'woocommerce_disable_woocommerce_debug_tools_remove_logs', FALSE );\n\t\n\tif( !$disable_remove_logs ) {\n\t\t$tools['remove_logs'] = array(\n\t\t\t\t\t'name' => __( 'Remove all the logs.', 'woocommerce' ),\n\t\t\t\t\t'button' => __( 'Remove logs', 'woocommerce' ),\n\t\t\t\t\t'desc' => __( 'This will remove all of the log files created by WooCommerce and WooCommerce plugins.', 'woocommerce' ),\n\t\t\t\t\t'callback' => 'woocommerce_debug_tools_execute_remove_logs',\n\t\t\t\t);\n\t}\n\t\n\treturn $tools;\n}\n\nfunction woocommerce_debug_tools_execute_remove_logs() {\n\t$log_dir = WC_LOG_DIR;\n\t\n\tforeach( scandir( $log_dir ) as $file ) {\n\t\t\n\t\t$path = pathinfo( $file );\n\t\t\/\/ Only delete log files, don't delete the test.log file\n\t\tif ( $path['extension'] === 'log' && $path['filename'] !== 'test' ) {\n\t\t\tunlink( \"{$log_dir}\/{$file}\" );\n\t\t}\n\t\t\n\t}\n\t\n\treturn __( 'Log files deleted', 'woocommerce' );\n}","priority":"10"}]}