Documentation SearchWP

Consultez le guide d’installation, parcourez la base de connaissances, découvrez les nombreux hooks de SearchWP

searchwp\background_process\http_basic_auth_credentials

Depuis : 4.1.0

Table des matières

Enseigner les identifiants d'authentification HTTP de base de l'indexeur.

Remarque : ces identifiants sont pour l'authentification HTTP de base, pas vos identifiants de connexion WordPress.

Paramètres

Type Paramètre Défaut Depuis
Tableau $credentials
Clé Type Valeur
nom d'utilisateur Chaîne Nom d'utilisateur
mot de passe Chaîne Mot de passe
4.1.0

Exemples

Tous les hooks doivent être ajoutés à votre plugin personnalisé SearchWP Customizations Plugin.

Fournir les identifiants d'authentification HTTP de base

<?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();

Comment utiliser ce code