Created
September 15, 2022 09:28
-
-
Save patrickposner/140c4ccbb075bab391f4d8fd3fc97fa1 to your computer and use it in GitHub Desktop.
Fix Freemius API with existing Basic Auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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