send-blogpost-notification #679
@ -78,31 +78,43 @@ add_filter( 'authenticate', 'rot_auth', 10, 3 );
|
|||||||
Add the following code to `wp-content/themes/bravada/functions.php`:
|
Add the following code to `wp-content/themes/bravada/functions.php`:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
function send_article_url_on_publish($new_status, $old_status, $post) {
|
function send_article_url_on_publish($new_status, $old_status, $post) {
|
||||||
// Check if the post is transitioning to 'publish' status
|
// Check if the post is transitioning to 'publish' status
|
||||||
if ($new_status == 'publish' && $old_status != 'publish' && $post->post_type == 'post') {
|
if ($new_status == 'publish' && $old_status != 'publish' && $post->post_type == 'post') {
|
||||||
// Get the URL of the newly published article
|
// Get the URL of the newly published article
|
||||||
$article_url = get_permalink($post->ID);
|
$article_url = get_permalink($post->ID);
|
||||||
$article_title = get_the_title($post->ID);
|
$article_title = get_the_title($post->ID);
|
||||||
|
|
||||||
|
// URL to send the POST request to
|
||||||
|
$api_url = 'https://app.rudernlinz.at/new-blogpost';
|
||||||
|
|
||||||
|
// Prepare the data for the POST request
|
||||||
|
$body = array(
|
||||||
|
'article_url' => $article_url,
|
||||||
|
'article_title' => $article_title,
|
||||||
|
'pw' => "pw-as-specified-in-rockettoml"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Prepare the arguments for wp_remote_post
|
||||||
|
$args = array(
|
||||||
|
'body' => $body,
|
||||||
|
'timeout' => '5',
|
||||||
|
'redirection' => '5',
|
||||||
|
'httpversion' => '1.0',
|
||||||
|
'blocking' => true,
|
||||||
|
'headers' => array(),
|
||||||
|
'cookies' => array()
|
||||||
|
);
|
||||||
|
|
||||||
// URL to send the GET request to
|
// Send the POST request
|
||||||
$api_url = 'https://staging.rudernlinz.at/new-blogpost';
|
$response = wp_remote_post($api_url, $args);
|
||||||
|
|
||||||
// Add the article URL as a query parameter
|
|
||||||
$request_url = add_query_arg(array(
|
|
||||||
'article_url' => urlencode($article_url),
|
|
||||||
'article_title' => urlencode($article_title),
|
|
||||||
'pw' => "pw-as-specified-in-rockettoml"
|
|
||||||
), $api_url);
|
|
||||||
|
|
||||||
// Send the GET request
|
|
||||||
$response = wp_remote_post($request_url);
|
|
||||||
|
|
||||||
// Optional: Check if the request was successful
|
// Optional: Check if the request was successful
|
||||||
if (is_wp_error($response)) {
|
if (is_wp_error($response)) {
|
||||||
error_log('Failed to send GET request: ' . $response->get_error_message());
|
error_log('Failed to send POST request: ' . $response->get_error_message());
|
||||||
} else {
|
} else {
|
||||||
error_log('GET request sent successfully with article URL: ' . $article_url);
|
error_log('POST request sent successfully with article URL: ' . $article_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user