Removing the debug.log file via code snippets extension

Hi,
I am using the Security Ninja plugin for security checks and here it is recommended to remove the debug.log file. Is there a way to do this eg. via the Code snippets extension? Or is there another recommended way to do this automatically or semiautomatically? Just an easy way without the need to access the File Manager.

Best,
Chrilles

1 Like

I think this should be possible with some code using this function:

For the path you can use the ABSPATH constant to get the main folder of the site or WP_CONTENT_DIR to get the path to the wp-content folder. Append the debug.log filename and you’re almost there.

I haven’t tested this yet (so use at your own risk), but it would be a snippet as simple as this:

wp_delete_file(WP_CONTENT_DIR . '/debug.log');

As code snippets type you would use “Return info from Child Sites”, so it would be executed once.

1 Like

Thanks a lot Jos.
I will try it out soon.

Best,
Chrilles

2 Likes

I always use this in my default .htaccess

block debug log reads

RewriteEngine On
RewriteRule ^debug.log - [L]

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.