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

Add settings for sites behind Basic Authentication #48

Open
danielmilner opened this issue Feb 14, 2019 · 1 comment
Open

Add settings for sites behind Basic Authentication #48

danielmilner opened this issue Feb 14, 2019 · 1 comment

Comments

@danielmilner
Copy link
Member

It is fairly common for sites that are in development to be behind Basic Authentication. In these instances, WP Cron jobs and Admin Ajax requests will fail. We should add a setting to add the Basic Auth username and password to requests.

@danielmilner
Copy link
Member Author

Code samples for adding Basic Auth to both Admin Ajax and Cron requests.

Admin Ajax

add_filter( 'http_request_args', 'http_request_args_basic_auth', 10, 2 );
function http_request_args_basic_auth( $args, $url ) {
    if ( strpos( $url, admin_url( 'admin-ajax.php' ) ) === 0 ) {
        $args['headers']['Authorization'] = 'Basic ' . base64_encode( USERNAME . ':' . PASSWORD );
    }
 
    return $args;
}

Cron

add_filter( 'cron_request', 'cron_request_basic_auth' );
function cron_request_basic_auth( $cron_request ) {
    $cron_request['args']['headers']['Authorization'] = 'Basic ' . base64_encode( USERNAME . ':' . PASSWORD );
    return $cron_request;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant