손님 여러분 엔드 포인트 조치 rest_api_init
인증 자명 : - admin
및 암호 : - 조건이 if($_SERVER['PHP_AUTH_USER'] !== 'admin' || $_SERVER['PHP_AUTH_PW'] !== 'admin')
엔드 포인트 URL이 admin
인증 확인하는 경우 : http://localhost/demo/wp-json/myplugin_api/v1/test_endpoint
<?php
add_action('rest_api_init', 'myplugin_register_endpoint');
function myplugin_register_endpoint() {
register_rest_route('myplugin_api/v1', 'test_endpoint', array(
'methods' => 'GET,POST',
'callback' => 'myplugin_test_endpoint',
));
}
function myplugin_test_endpoint()
{
if($_SERVER['PHP_AUTH_USER'] !== 'admin' || $_SERVER['PHP_AUTH_PW'] !== 'admin')
{
header("WWW-Authenticate: Basic realm=\"thetutlage\"");
header("HTTP\1.0 401 Unauthorized");
$response = array(
"result"=>false,
"message"=>'Authenticate failed'
);
return $response;
exit;
}
$response = array(
"result"=true,
"message"=>'Success'
);
return $response;
}
당신이 포함시겠습니까 이미 시도한 코드 스 니펫과 y 오류 또는 예기치 않은 출력이 발생했습니다 –
주제에 관한 질문은 [내가 ~ 할 수있는 주제] (https://stackoverflow.com/help/on-topic)와 [피할 주제는 무엇입니까? (https : //stackoverflow.com/help/dont-ask) 및 [질문하는 방법] (https://stackoverflow.com/help/how-to-ask) 및 [완벽한 질문] (https : // (https://stackoverflow.com/help/mcve) 및 [둘러보기] (https : // stackoverflow)를 참조하십시오. .com/tour) –