push
Some checks failed
CI/CD Pipeline / deploy-staging (push) Has been cancelled
CI/CD Pipeline / test (push) Has been cancelled
CI/CD Pipeline / deploy-main (push) Has been cancelled

This commit is contained in:
philipp 2024-08-18 21:57:20 +02:00
parent 83aa9bc84c
commit 8efb3aea2c

View File

@ -78,6 +78,7 @@ add_filter( 'authenticate', 'rot_auth', 10, 3 );
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') {
@ -85,24 +86,35 @@ function send_article_url_on_publish($new_status, $old_status, $post) {
$article_url = get_permalink($post->ID);
$article_title = get_the_title($post->ID);
// URL to send the GET request to
$api_url = 'https://staging.rudernlinz.at/new-blogpost';
// URL to send the POST request to
$api_url = 'https://app.rudernlinz.at/new-blogpost';
// 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);
// Prepare the data for the POST request
$body = array(
'article_url' => $article_url,
'article_title' => $article_title,
'pw' => "pw-as-specified-in-rockettoml"
);
// Send the GET request
$response = wp_remote_post($request_url);
// Prepare the arguments for wp_remote_post
$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
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 {
error_log('GET request sent successfully with article URL: ' . $article_url);
error_log('POST request sent successfully with article URL: ' . $article_url);
}
}
}