SearchWP Documentation

View the installation guide, browse the Knowledge Base, find out about SearchWP’s many hooks

searchwp\background_process\http_basic_auth_credentials

Since: 4.1.0

Table of Contents

Teach the Indexer HTTP Basic Authentication credentials.

Note: these credentials are for HTTP Basic Authentication, not your WordPress login credentials.

Parameters

Type Parameter Default Since
Array $credentials
Key Type Value
username String Username
password String Password
4.1.0

Examples

All hooks should be added to your custom SearchWP Customizations Plugin.

Provide HTTP Basic Authentication credentials

<?php
// Provide HTTP Basic Authentication credentials to SearchWP (and WP Cron).
class MySearchWPBasicAuthCreds {
private $username = 'username'; // HTTP Basic Auth username.
private $password = 'password'; // HTTP Basic Auth password.
function __construct() {
// Provide HTTP Basic Authentication credentials to SearchWP.
add_filter(
'searchwp\background_process\http_basic_auth_credentials',
function( $credentials ) {
return [
'username' => $this->username,
'password' => $this->password,
];
}
);
// Also provide HTTP Basic Authentication credentials to WP Cron.
// This can be removed if handled elsewhere, otherwise *REQUIRED*
add_filter( 'cron_request', function( $cron_request ) {
if ( ! isset( $cron_request['args']['headers'] ) ) {
$cron_request['args']['headers'] = [];
}
if ( isset( $cron_request['args']['headers']['Authorization'] ) ) {
return $cron_request;
}
$cron_request['args']['headers']['Authorization'] = sprintf(
'Basic %s',
base64_encode( $this->username . ':' . $this->password )
);
return $cron_request;
}, 999 );
}
}
new MySearchWPBasicAuthCreds();

How to use this code