Skip to content

Instantly share code, notes, and snippets.

@patrickposner
Created April 17, 2023 13:00
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/ebafa8d8012ac792ecc844abcd965973 to your computer and use it in GitHub Desktop.
Save patrickposner/ebafa8d8012ac792ecc844abcd965973 to your computer and use it in GitHub Desktop.
Freemius Basic Auth License Activation
<?php
/* FREEMIUS API BASIC AUTH WORKAROUND */
add_filter( 'http_request_args', 'my_http_request_args_filter', 1, 2 );
add_filter( 'http_request_args', 'my_http_request_args_filter', 9999, 2 );
function my_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