Skip to content

Commit 441cb28

Browse files
committed
Add "extra_detected_files" filter
- Add "extra_detected_files" filter that allows plugins to add additional files when the "detect" step is run.
1 parent 15ce03c commit 441cb28

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
- Add deployed_at column and an index on it.
3737
- Batch queries to the deployed_files table for better
3838
performance.
39+
- Add "extra_detected_files" filter that allows plugins to
40+
add additional files when the "detect" step is run.
3941

4042
## 9.3.2 (2025-07-29)
4143

src/URLDetector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public static function detectURLsIter(): \Iterator {
2929

3030
$iterators_to_merge = [];
3131

32+
$iterators_to_merge[] = apply_filters(
33+
Controller::getHookName( 'extra_detected_files' ),
34+
new \ArrayIterator( [] ),
35+
);
36+
3237
$iterators_to_merge[] = new \ArrayIterator(
3338
[
3439
new PathInfo( '/' ),

tests/integration/DetectTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,32 @@ public function testSitemapDoubleSlashes(): void
6666

6767
exec( 'rm -f ' . escapeshellarg( $robotstxt ) );
6868
}
69+
70+
public function testExtraDetectedFiles(): void
71+
{
72+
$plugin = <<<'PHP'
73+
<?php
74+
75+
/**
76+
* Plugin Name: Extra Detected Files Test
77+
*/
78+
79+
if ( ! defined( 'WPINC' ) ) {
80+
die;
81+
}
82+
83+
use StaticDeploy\PathInfo;
84+
85+
function extra_detected_files_filter ( $iter ) {
86+
yield from $iter;
87+
yield new PathInfo( '/extra-detected-file.html' );
88+
}
89+
add_filter( 'static_deploy_extra_detected_files', 'extra_detected_files_filter' );
90+
PHP;
91+
$this->installStringPlugin( 'extra-detected-files-test', $plugin );
92+
93+
$this->pluginCli( [ 'detect' ] );
94+
$lines = $this->pluginCli( [ 'detected-files', 'list' ] )['output'];
95+
$this->assertContains( '/extra-detected-file.html', $lines );
96+
}
6997
}

0 commit comments

Comments
 (0)