Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose last X headers for extensability #353

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading