Code-Snippets-Functions/Returns information from child Site/General/scan-files.php
2024-07-03 18:51:33 +02:00

52 lines
1.9 KiB
PHP

<?php
$count = 0;
$found = false;
$directory = WP_PLUGIN_DIR;
// Create a RecursiveDirectoryIterator object
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator( $directory, RecursiveDirectoryIterator::SKIP_DOTS ),
RecursiveIteratorIterator::SELF_FIRST
);
// Loop through the directory and subdirectories
foreach ( $iterator as $file ) {
if ( $file->isFile() ) {
// Add the file to the result array
$node = $file->getPathname();
$filename = basename( $node );
++$count;
if ( in_array( $filename, array( 'bootcss.css', 'bootcss.js', 'polyfill.js', 'mainwp-child.php' ) ) ) {
$found = true;
break;
}
}
}
if ( ! $found ) {
$directory = get_theme_root();
// Create a RecursiveDirectoryIterator object
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator( $directory, RecursiveDirectoryIterator::SKIP_DOTS ),
RecursiveIteratorIterator::SELF_FIRST
);
// Loop through the directory and subdirectories
foreach ( $iterator as $file ) {
if ( $file->isFile() ) {
// Add the file to the result array
$node = $file->getPathname();
$filename = basename( $node );
++$count;
if ( in_array( $filename, array( 'bootcss.css', 'bootcss.js', 'polyfill.js', 'mainwp-child.php' ) ) ) {
$found = true;
break;
}
}
}
}
echo 'Scanned: ' . $count . ' files<br/>';
echo $found ? 'Files are found on the site.' : 'Files are not found on the site.';
?>