Skip to content

Instantly share code, notes, and snippets.

@patrickposner
Created September 15, 2022 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrickposner/140c4ccbb075bab391f4d8fd3fc97fa1 to your computer and use it in GitHub Desktop.
Save patrickposner/140c4ccbb075bab391f4d8fd3fc97fa1 to your computer and use it in GitHub Desktop.
Fix Freemius API with existing Basic Auth
<?php
add_filter( 'http_request_args', 'freemius_http_request_args_filter', 1, 2 );
add_filter( 'http_request_args', 'freemius_http_request_args_filter', 9999, 2 );
function freemius_http_request_args_filter( $parsed_args, $url ) {
if ( false === strpos( $url, '://api.freemius.com' ) ) {
return $parsed_args;
}
if ( empty( $parsed_args['headers'] ) ) {
return $parsed_args;
}
foreach ( $parsed_args['headers'] as $key => $value ) {
if ( 'Authorization' === $key ) {
$parsed_args['headers']['Authorization2'] = $value;
} else if ( 'Authorization2' === $key ) {
$parsed_args['headers']['Authorization'] = $value;
unset($parsed_args['headers'][$key]);
}
}
return $parsed_args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment