diff --git a/notes.md b/wordpress-notes.md similarity index 62% rename from notes.md rename to wordpress-notes.md index 74ce2fe..8170489 100644 --- a/notes.md +++ b/wordpress-notes.md @@ -71,3 +71,40 @@ remove_action('authenticate', 'wp_authenticate_username_password', 20); 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); +```