Skip to content

Commit

Permalink
Merge pull request #353 from s3rgiosan/feature/expose-response-headers
Browse files Browse the repository at this point in the history
Expose last X headers for extensability
  • Loading branch information
iamdharmesh authored Dec 16, 2024
2 parents b56a9d5 + 10d440e commit 9c98b46
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions includes/class-publish-tweet.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,19 @@ 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 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 );
do_action( 'autoshare_for_twitter_after_status_update', $response, $update_data, $post, $account_id, $last_headers );

return $response;
}
Expand Down
9 changes: 9 additions & 0 deletions includes/class-twitter-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 9c98b46

Please sign in to comment.