send-blogpost-notification #679
@ -78,6 +78,7 @@ 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') {
|
||||||
@ -85,24 +86,35 @@ function send_article_url_on_publish($new_status, $old_status, $post) {
|
|||||||
$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 GET request to
|
// URL to send the POST request to
|
||||||
$api_url = 'https://staging.rudernlinz.at/new-blogpost';
|
$api_url = 'https://app.rudernlinz.at/new-blogpost';
|
||||||
|
|
||||||
// Add the article URL as a query parameter
|
// Prepare the data for the POST request
|
||||||
$request_url = add_query_arg(array(
|
$body = array(
|
||||||
'article_url' => urlencode($article_url),
|
'article_url' => $article_url,
|
||||||
'article_title' => urlencode($article_title),
|
'article_title' => $article_title,
|
||||||
'pw' => "pw-as-specified-in-rockettoml"
|
'pw' => "pw-as-specified-in-rockettoml"
|
||||||
), $api_url);
|
);
|
||||||
|
|
||||||
// Send the GET request
|
// Prepare the arguments for wp_remote_post
|
||||||
$response = wp_remote_post($request_url);
|
$args = array(
|
||||||
|
'body' => $body,
|
||||||
|
'timeout' => '5',
|
||||||
|
'redirection' => '5',
|
||||||
|
'httpversion' => '1.0',
|
||||||
|
'blocking' => true,
|
||||||
|
'headers' => array(),
|
||||||
|
'cookies' => array()
|
||||||
|
);
|
||||||
|
|
||||||
|
// Send the POST request
|
||||||
|
$response = wp_remote_post($api_url, $args);
|
||||||
|
|
||||||
// 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