Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save wp-seopress/bcaa0f07c3038ab8f8f2fc0e8ffa9632 to your computer and use it in GitHub Desktop.

Select an option

Save wp-seopress/bcaa0f07c3038ab8f8f2fc0e8ffa9632 to your computer and use it in GitHub Desktop.
Filter the arguments sent to AI provider to generate social metadata
<?php
add_filter( 'seopress_ai_openai_social_request_args', 'sp_ai_openai_social_request_args' );
function sp_ai_openai_social_request_args( $args ) {
// Example: increase the timeout if your answers are long.
$args['timeout'] = 45;
// Example: adding/overriding a custom header.
if ( ! isset( $args['headers'] ) || ! is_array( $args['headers'] ) ) {
$args['headers'] = [];
}
$args['headers']['X-My-Project'] = 'my-seopress-ai-integration';
// Example: force the language in the JSON body, if necessary.
if ( isset( $args['body'] ) && is_string( $args['body'] ) ) {
$body = json_decode( $args['body'], true );
if ( json_last_error() === JSON_ERROR_NONE && is_array( $body ) ) {
$body['user_locale'] = get_locale(); // e.g. "fr_FR"
$args['body'] = wp_json_encode( $body );
}
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment