Ise the following InfiniteWP code snippets to list and delete files from the WP root folder. For example for:
- The readme*.html file that is added with every WordPress update
- The error_log file that is written by the Hoasted servers
Code snippets can be added to InfiniteWP under Tools » Code Snippets. Select the website(s), then select or create the code snippet and run the code.
Display files
This code snippet displays a list of readme*.html files. Change the file name for other files.
$wordpressRoot = ABSPATH; // WordPress root directory
$files = glob($wordpressRoot . 'readme*.html');
foreach ($files as $file) {
if (is_file($file)) {
echo "Readme File: $file\n";
}
}Code language: PHP (php)
Delete files
This code snippet deletes readme*.html files. Change the file name for other files.
$wordpressRoot = ABSPATH; // WordPress root directory
$files = glob($wordpressRoot . 'readme*.html');
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
echo "Deleted: $file\n";
}
}Code language: PHP (php)