-
-
Save mindmergedesign/0a7373058598763f99a9fe999d69112f to your computer and use it in GitHub Desktop.
WordPress Netlify Build Hook
This file contains 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 | |
// Netlify Webhook Build Function | |
// -- this function will trigger a rebuild on post update | |
// -- add your api key or url below | |
add_action( 'save_post', 'netlify_rebuild'); | |
function netlify_rebuild( $post_id ) { | |
if ( wp_is_post_revision( $post_id ) ) { | |
return; | |
} | |
if ( get_post_status( $post_id ) == 'publish' ) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, 'https://api.netlify.com/build_hooks/YOUR-API-KEY'); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, "{}"); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
$headers = array(); | |
$headers[] = 'Content-Type: application/x-www-form-urlencoded'; | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
$result = curl_exec($ch); | |
if (curl_errno($ch)) { | |
echo 'Error:' . curl_error($ch); | |
} | |
curl_close ($ch); | |
} else { | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment