SearchWP Documentation

Visualizza la guida all'installazione, sfoglia la Knowledge Base, scopri i numerosi hook di SearchWP

searchwp\indexer\http_basic_auth_credentials

Da: 4.0.0

Questo hook è deprecato
Si prega di utilizzare searchwp\background_process\http_basic_auth_credentials invece.

Insegna le credenziali HTTP Basic Authentication all'Indicizzatore.

Nota: queste credenziali sono per l'autenticazione HTTP Basic, non per le credenziali di accesso a WordPress.

Parametri

Tipo Parametro Predefinito Da
Array $credentials
Chiave Tipo Valore
nome utente Stringa Nome utente
password Stringa Password
4.0.0

Esempi

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

Fornisci le credenziali HTTP Basic Authentication

<?php
// @deprecated
// @see https://searchwp.com/documentation/hooks/searchwp-background_process-http_basic_auth_credentials/
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\indexer\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 )
);
}, 999 );
}
}
new MySearchWPBasicAuthCreds();

Come usare questo codice