send-blogpost-notification #680

Merged
philipp merged 7 commits from send-blogpost-notification into main 2024-08-18 22:24:16 +02:00
Showing only changes of commit 6171bb0f85 - Show all commits

View File

@ -71,3 +71,40 @@ remove_action('authenticate', 'wp_authenticate_username_password', 20);
add_filter( 'authenticate', 'rot_auth', 10, 3 ); add_filter( 'authenticate', 'rot_auth', 10, 3 );
``` ```
# Wordpress notify rowt on newly published article
Add the following code to `wp-content/themes/bravada/functions.php`:
```
function send_article_url_on_publish($new_status, $old_status, $post) {
// Check if the post is transitioning to 'publish' status
if ($new_status == 'publish' && $old_status != 'publish' && $post->post_type == 'post') {
// Get the URL of the newly published article
$article_url = get_permalink($post->ID);
// URL to send the GET request to
$api_url = 'https://staging.rudernlinz.at/new-blogpost';
// Add the article URL as a query parameter
$request_url = add_query_arg(array(
'article_url' => urlencode($article_url),
'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
if (is_wp_error($response)) {
error_log('Failed to send GET request: ' . $response->get_error_message());
} else {
error_log('GET request sent successfully with article URL: ' . $article_url);
}
}
}
// Hook the function to the 'transition_post_status' action
add_action('transition_post_status', 'send_article_url_on_publish', 10, 3);
```