From 504ceede9839acc647c38a3eaa2b83d4994ead72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Santos?= Date: Mon, 16 Dec 2024 01:06:18 +0000 Subject: [PATCH 1/2] Expose last X headers for extensability --- includes/class-publish-tweet.php | 8 ++++++-- includes/class-twitter-api.php | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/includes/class-publish-tweet.php b/includes/class-publish-tweet.php index a8858497..9cbbe242 100644 --- a/includes/class-publish-tweet.php +++ b/includes/class-publish-tweet.php @@ -87,14 +87,18 @@ public function status_update( $body, $post, $account_id = null ) { // Send tweet to Twitter. $response = $this->twitter_api->tweet( $update_data ); + // Get the last headers from the Twitter API. + $last_headers = $this->twitter_api->get_last_headers(); + /** * Fires after the request to the Twitter endpoint had been made. * * @param array|object The response from the Twitter endpoint. * @param array Data to send to the Twitter endpoint. - * @param \WP_Post The post associated with the tweet. + * @param \WP_Post The post associated with the tweet. + * @param array The headers from the last request. */ - do_action( 'autoshare_for_twitter_after_status_update', $response, $update_data, $post ); + do_action( 'autoshare_for_twitter_after_status_update', $response, $update_data, $post, $last_headers ); return $response; } diff --git a/includes/class-twitter-api.php b/includes/class-twitter-api.php index 807811eb..047d4367 100644 --- a/includes/class-twitter-api.php +++ b/includes/class-twitter-api.php @@ -240,4 +240,13 @@ public function disconnect_account() { return false; } } + + /** + * Get the HTTP headers from the most recent request. + * + * @return array + */ + public function get_last_headers() { + return $this->client->getLastXHeaders(); + } } From 3c400b83c785d081def7567f5b59495e9800b80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Santos?= Date: Mon, 16 Dec 2024 01:27:02 +0000 Subject: [PATCH 2/2] Add the account ID --- includes/class-publish-tweet.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/class-publish-tweet.php b/includes/class-publish-tweet.php index 9cbbe242..1427ec0f 100644 --- a/includes/class-publish-tweet.php +++ b/includes/class-publish-tweet.php @@ -96,9 +96,10 @@ public function status_update( $body, $post, $account_id = null ) { * @param array|object The response from the Twitter endpoint. * @param array Data to send to the Twitter endpoint. * @param \WP_Post The post associated with the tweet. + * @param int|null The Twitter account ID. * @param array The headers from the last request. */ - do_action( 'autoshare_for_twitter_after_status_update', $response, $update_data, $post, $last_headers ); + do_action( 'autoshare_for_twitter_after_status_update', $response, $update_data, $post, $account_id, $last_headers ); return $response; }