Skip to content

Commit

Permalink
update webhooks #234
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisherold committed Sep 27, 2022
1 parent b4ca258 commit fdab771
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions wordpress/wp-content/themes/headless/setup/helpers/webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,20 @@
add_action('acf/save_post', 'purge_options', 10, 2);
add_action('wp_update_nav_menu', 'purge_menu', 10, 2);

// Loop through post types and add actions
foreach ( $headless_webhooks_post_types as $post_type ) {
add_action('publish_' . $post_type, 'purge_post', 10, 2);
}
$statuses_to_skip = array('auto-draft', 'inherit');

add_action('transition_post_status', function ($new_status, $old_status, $post) use ($statuses_to_skip, $headless_webhooks_post_types) {
if ($new_status != $old_status && !in_array($new_status, $statuses_to_skip) && in_array($post->post_type, $headless_webhooks_post_types)) {
purge_post($post->ID);
}
}, 10, 3);

add_action('pre_post_update', function ($post_id, $data) {
$cur_post = get_post($post_id);
if ($cur_post->post_password != $data['post_password']) {
purge_post($post_id);
}
}, 10, 2);
}

// check if redirection is enabled
Expand Down

0 comments on commit fdab771

Please sign in to comment.