-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathactions.php
41 lines (37 loc) · 1.11 KB
/
actions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* Register actions which should be triggered on surtain times
*/
/**
* Register function to send webhook
*
* @return None
*/
function jamstackPreviewAndDeploymentsSendDeployWebhookRequest()
{
$url = jamstackPreviewAndDeploymentsGetWebhookUrl();
if (jamstackPreviewAndDeploymentsGetWebhookMethod() === 'POST') {
return wp_safe_remote_post($url);
}
wp_safe_remote_get($url);
}
add_action('jamstack_preview_deployments_deploy_webhook', 'jamstackPreviewAndDeploymentsSendDeployWebhookRequest');
/**
* Trigger deploy if post update
*
* @param integer $post_id post_id
*/
function jamstackPreviewAndDeploymentscheckIfAutoDeployWebsite($post_id)
{
if (get_post_status($post_id) === 'draft') {
return;
}
if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) {
return;
}
$postType = get_post_type($post_id);
if (in_array($postType, jamstackPreviewAndDeploymentsActivePostTypes())) {
do_action('jamstack_preview_deployments_deploy_webhook');
}
}
add_action('save_post', 'jamstackPreviewAndDeploymentscheckIfAutoDeployWebsite', 10, 3);