Created
September 18, 2025 07:47
-
-
Save BhargavBhandari90/1b7d95c9d213e34929971f30518a2815 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function fp_scan_images_generator() | |
| { | |
| try { | |
| $upload_dir = wp_upload_dir(); | |
| $directory = $upload_dir['basedir']; | |
| // Recursive scan with FileSystemIterator | |
| $iterator = new RecursiveIteratorIterator( | |
| new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS) | |
| ); | |
| if (empty($iterator)) { | |
| return []; | |
| } | |
| foreach ($iterator as $file) { | |
| if ( | |
| !$file->isFile() || | |
| !in_array(strtolower($file->getExtension()), ['jpg', 'jpeg', 'png'], true) | |
| ) { | |
| continue; | |
| } | |
| yield str_replace($directory, $upload_dir['baseurl'], $file->getPathname()); | |
| } | |
| } catch (\Throwable $e) { | |
| error_log('FlyingPress: Error scaning images - ' . $e->getMessage()); | |
| } | |
| } | |
| // Batch logging | |
| function fp_batch_logging(){ | |
| $batch = []; | |
| $batch_count = 100; | |
| foreach (fp_scan_images_generator_proloy() as $url) { | |
| $batch[] = $url; | |
| if (count($batch) >= $batch_count) { | |
| error_log(print_r($batch,true)); | |
| $batch = []; | |
| } | |
| } | |
| if ($batch) { | |
| error_log(print_r($batch,true)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment