Skip to content

Commit 250555f

Browse files
committed
Add getHookName for generating hook names
1 parent e45d7ec commit 250555f

18 files changed

Lines changed: 174 additions & 74 deletions

src/CLI.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,17 @@ public function deploy(
509509
WP_CLI::line( 'No deployment add-ons are enabled, skipping deployment.' );
510510
} else {
511511
WsLog::l( 'Starting deployment' );
512-
do_action( 'wp2static_deploy', ProcessedSite::getPath(), $deployer );
512+
do_action(
513+
Controller::getHookName( 'deploy' ),
514+
ProcessedSite::getPath(),
515+
$deployer
516+
);
513517
}
514518
WsLog::l( 'Starting post-deployment actions' );
515-
do_action( 'wp2static_post_deploy_trigger', $deployer );
519+
do_action(
520+
Controller::getHookName( 'post_deploy_trigger' ),
521+
$deployer
522+
);
516523
}
517524

518525
/*

src/Controller.php

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ public static function ensureIndex( string $table_name, string $index_name,
172172
}
173173
}
174174

175+
public static function getHookName(string $hook_slug) : string {
176+
return 'wp2static_' . $hook_slug;
177+
}
178+
175179
public static function getTableName(string $table_slug) : string {
176180
global $wpdb;
177181

@@ -284,7 +288,9 @@ public function deleteDeployCache() : void {
284288
public static function wp2staticUISaveOptions() : void {
285289
CoreOptions::savePosted( 'core' );
286290

287-
do_action( 'wp2static_addon_ui_save_options' );
291+
do_action(
292+
Controller::getHookName( 'addon_ui_save_options' )
293+
);
288294

289295
check_admin_referer( 'wp2static-ui-options' );
290296

@@ -437,7 +443,9 @@ public static function wp2staticStaticSiteShow() : void {
437443
public static function wp2staticUISaveJobOptions() : void {
438444
CoreOptions::savePosted( 'jobs' );
439445

440-
do_action( 'wp2static_addon_ui_save_job_options' );
446+
do_action(
447+
Controller::getHookName( 'addon_ui_save_job_options' )
448+
);
441449

442450
check_admin_referer( 'wp2static-ui-job-options' );
443451

@@ -461,7 +469,9 @@ public static function wp2staticTrashedPostHandler() : void {
461469
public static function wp2staticUISaveAdvancedOptions() : void {
462470
CoreOptions::savePosted( 'advanced' );
463471

464-
do_action( 'wp2static_addon_ui_save_advanced_options' );
472+
do_action(
473+
Controller::getHookName( 'addon_ui_save_advanced_options' )
474+
);
465475

466476
check_admin_referer( 'wp2static-ui-advanced-options' );
467477

@@ -620,13 +630,16 @@ public static function wp2staticProcessQueue() : void {
620630
} else {
621631
WsLog::l( 'Starting deployment' );
622632
do_action(
623-
'wp2static_deploy',
633+
Controller::getHookName( 'deploy' ),
624634
ProcessedSite::getPath(),
625635
$deployer
626636
);
627637
}
628638
WsLog::l( 'Starting post-deployment actions' );
629-
do_action( 'wp2static_post_deploy_trigger', $deployer );
639+
do_action(
640+
Controller::getHookName( 'post_deploy_trigger' ),
641+
$deployer
642+
);
630643

631644
break;
632645
case 'direct_deploy':
@@ -675,8 +688,8 @@ public static function wp2staticProcessQueue() : void {
675688
* Make a non-blocking POST request to run wp2staticProcessQueue.
676689
*/
677690
public static function wp2staticProcessQueueAdminPost() : void {
678-
$url = admin_url( 'admin-post.php' ) . '?action=wp2static_process_queue';
679-
$nonce = wp_create_nonce( 'wp2static_process_queue' );
691+
$url = admin_url( 'admin-post.php' ) . '?action=' . self::getHookName( 'process_queue' );
692+
$nonce = wp_create_nonce( self::getHookName( 'process_queue' ) );
680693
$result = wp_remote_post(
681694
$url,
682695
[
@@ -719,13 +732,16 @@ public static function wp2staticHeadless() : void {
719732
} else {
720733
WsLog::l( 'Starting deployment' );
721734
do_action(
722-
'wp2static_deploy',
735+
Controller::getHookName( 'deploy' ),
723736
ProcessedSite::getPath(),
724737
$deployer
725738
);
726739
}
727740
WsLog::l( 'Starting post-deployment actions' );
728-
do_action( 'wp2static_post_deploy_trigger', $deployer );
741+
do_action(
742+
Controller::getHookName( 'post_deploy_trigger' ),
743+
$deployer
744+
);
729745
}
730746

731747
public static function invalidateSingleURLCache(
@@ -795,9 +811,18 @@ public static function webhookDeployNotification() : void {
795811
'method' => CoreOptions::getValue( 'completionWebhookMethod' ),
796812
'timeout' => 30,
797813
'user-agent' =>
798-
apply_filters( 'wp2static_deploy_webhook_user_agent', 'WP2Static.com' ),
799-
'body' => apply_filters( 'wp2static_deploy_webhook_body', $body ),
800-
'headers' => apply_filters( 'wp2static_deploy_webhook_headers', [] ),
814+
apply_filters(
815+
Controller::getHookName( 'deploy_webhook_user_agent' ),
816+
'WP2Static.com'
817+
),
818+
'body' => apply_filters(
819+
Controller::getHookName( 'deploy_webhook_body' ),
820+
$body
821+
),
822+
'headers' => apply_filters(
823+
Controller::getHookName( 'deploy_webhook_headers' ),
824+
[]
825+
),
801826
]
802827
);
803828

@@ -807,7 +832,7 @@ public static function webhookDeployNotification() : void {
807832
}
808833

809834
public static function wp2staticRun() : void {
810-
check_ajax_referer( 'wp2static-run-page', 'security' );
835+
check_ajax_referer( Controller::getHookName( 'run_page' ), 'security' );
811836

812837
WsLog::l( 'Running full workflow from UI' );
813838

@@ -820,7 +845,7 @@ public static function wp2staticCrawl() : void {
820845
$crawlers = Addons::getType( 'crawl' );
821846
$crawler_slug = empty( $crawlers ) ? 'wp2static' : $crawlers[0]->slug;
822847
do_action(
823-
'wp2static_crawl',
848+
Controller::getHookName( 'crawl' ),
824849
$crawler_slug
825850
);
826851
WsLog::l( 'Crawling completed' );
@@ -830,7 +855,7 @@ public static function wp2staticCrawl() : void {
830855
* Give logs to UI
831856
*/
832857
public static function wp2staticPollLog() : void {
833-
check_ajax_referer( 'wp2static-run-page', 'security' );
858+
check_ajax_referer( Controller::getHookName( 'run_page' ), 'security' );
834859

835860
$logs = WsLog::poll();
836861

src/Crawler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function __construct() {
5454
$this->site_path = rtrim( SiteInfo::getURL( 'site' ), '/' );
5555

5656
$port_override = apply_filters(
57-
'wp2static_curl_port',
57+
Controller::getHookName( 'curl_port' ),
5858
null
5959
);
6060

src/DetectSitemapsURLs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static function detect( string $wp_site_url, bool $log = false ) : \Itera
4646
$site_path = rtrim( SiteInfo::getURL( 'site' ), '/' );
4747

4848
$port_override = apply_filters(
49-
'wp2static_curl_port',
49+
Controller::getHookName( 'curl_port' ),
5050
null
5151
);
5252

@@ -69,7 +69,7 @@ public static function detect( string $wp_site_url, bool $log = false ) : \Itera
6969
'timeout' => 600,
7070
'headers' => [
7171
'User-Agent' => apply_filters(
72-
'wp2static_curl_user_agent',
72+
Controller::getHookName( 'curl_user_agent' ),
7373
'WP2Static.com',
7474
),
7575
],

src/DirectDeployer.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ public function __construct() {
2222
return;
2323
}
2424

25-
$deployer_class = apply_filters( 'wp2static_deployer_class', '', $deployer );
25+
$deployer_class = apply_filters(
26+
Controller::getHookName( 'deployer_class' ),
27+
'',
28+
$deployer
29+
);
2630

2731
if ( empty( $deployer_class ) ) {
2832
WsLog::l( 'No deployer class found, skipping direct deployment.' );
@@ -66,7 +70,10 @@ public function deployComplete() : void {
6670
$this->processor->complete();
6771

6872
WsLog::l( 'Starting post-direct deployment actions' );
69-
do_action( 'wp2static_post_direct_deploy_trigger', $this );
73+
do_action(
74+
Controller::getHookName( 'post_direct_deploy_trigger' ),
75+
$this
76+
);
7077
}
7178

7279
public function deployPaths( \Iterator $paths, bool $remove_404s = true ) : void {

src/FileFiltering.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct() {
2323

2424
$filenames_to_ignore =
2525
apply_filters(
26-
'wp2static_filenames_to_ignore',
26+
Controller::getHookName( 'filenames_to_ignore' ),
2727
$filenames_to_ignore
2828
);
2929

@@ -37,7 +37,7 @@ public function __construct() {
3737

3838
$file_extensions_to_ignore =
3939
apply_filters(
40-
'wp2static_file_extensions_to_ignore',
40+
Controller::getHookName( 'file_extensions_to_ignore' ),
4141
$file_extensions_to_ignore
4242
);
4343

src/FileProcessor.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,40 @@ public function __construct() {
2525
*/
2626
public function processFile( string $filename ) : void {
2727
if ( $filename === ProcessedSite::getPath() . '/robots.txt' ) {
28-
do_action( 'wp2static_process_robots_txt', $filename );
28+
do_action(
29+
Controller::getHookName( 'process_robots_txt' ),
30+
$filename
31+
);
2932
return;
3033
}
3134
switch ( pathinfo( $filename, PATHINFO_EXTENSION ) ) {
3235
case 'html':
33-
do_action( 'wp2static_process_html', $filename );
34-
do_action( 'wp2static_process_html_complete', $filename );
36+
do_action(
37+
Controller::getHookName( 'process_html' ),
38+
$filename
39+
);
40+
do_action(
41+
Controller::getHookName( 'process_html_complete' ),
42+
$filename
43+
);
3544
break;
3645
case 'css':
37-
do_action( 'wp2static_process_css', $filename );
46+
do_action(
47+
Controller::getHookName( 'process_css' ),
48+
$filename
49+
);
3850
break;
3951
case 'js':
40-
do_action( 'wp2static_process_js', $filename );
52+
do_action(
53+
Controller::getHookName( 'process_js' ),
54+
$filename
55+
);
4156
break;
4257
case 'xml':
43-
do_action( 'wp2static_process_xml', $filename );
58+
do_action(
59+
Controller::getHookName( 'process_xml' ),
60+
$filename
61+
);
4462
break;
4563
}
4664
}

src/PostProcessor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ public function processStaticSite(
7676

7777
$this->complete();
7878

79-
do_action( 'wp2static_post_process_complete', ProcessedSite::getPath() );
79+
do_action(
80+
Controller::getHookName( 'post_process_complete' ),
81+
ProcessedSite::getPath()
82+
);
8083
}
8184

8285
public function processIter(

src/ProcessedSite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ProcessedSite {
1515

1616
public static function getPath() : string {
1717
return apply_filters(
18-
'wp2static_processed_site_path',
18+
Controller::getHookName( 'processed_site_path' ),
1919
SiteInfo::getPath( 'uploads' ) . 'wp2static-processed-site'
2020
);
2121
}

src/SimpleRewriter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ class SimpleRewriter {
3232

3333
public function __construct() {
3434
$this->destination_url = apply_filters(
35-
'wp2static_set_destination_url',
35+
Controller::getHookName( 'set_destination_url' ),
3636
CoreOptions::getValue( 'deploymentURL' )
3737
);
3838
$this->hosts_to_rewrite = CoreOptions::getLineDelimitedBlobValue( 'hostsToRewrite' );
3939
$this->site_url = apply_filters(
40-
'wp2static_set_wordpress_site_url',
40+
Controller::getHookName( 'set_wordpress_site_url' ),
4141
untrailingslashit( SiteInfo::getUrl( 'site' ) )
4242
);
4343
$this->skip_url_rewrite = (int) CoreOptions::getValue( 'skipURLRewrite' ) === 1 ? true : false;

0 commit comments

Comments
 (0)