반응형
WordPress에서 XML-RPC가 활성화되었는지 확인하는 방법
(php를 통해) WordPress에서 XML-RPC가 활성화 되어 있는지 확인할 수 있습니까?예를 들어, 이것을 테스트하는 함수를 작성하는 것입니다.
if(is_xmlrpc_enabled()) {
//action
}
else {
//another action
}
XML-RPC는 WP 버전이 3.5보다 크면 디폴트로 이니블로 되어 있습니다('xmlrpc_enabled' 후크를 사용하면 디세이블이 됩니다). 오래된 버전의 경우 데이터베이스(옵션테이블)에는 활성화 여부를 나타내는 필드가 있습니다.(이 옵션은 wp > 3.5의 경우 삭제됩니다).
function is_xmlrpc_enabled() {
$returnBool = false;
$enabled = get_option('enable_xmlrpc'); //for ver<3.5
if($enabled) {
$returnBool = true;
}
else {
global $wp_version;
if (version_compare($wp_version, '3.5', '>=')) {
$returnBool = true; //its on by default for versions above 3.5
}
else {
$returnBool = false;
}
}
return $returnBool;
}
WordPress의 XML-RPC 서버에는 다음 두 가지 테스트 방법이 있습니다.
demo.sayHello – Returns a standard “Hello!” message.
demo.addTwoNumbers – Accepts an array containing two numbers and returns the sum.
function sayHello()
{
$params = array();
return $this->send_request('demo.sayHello',$params);
}
$objXMLRPClientWordPress = new XMLRPClientWordPress("http://localhost/wordpress31/xmlrpc.php" , "username" , "passowrd");
function send_request($requestname, $params)
{
$request = xmlrpc_encode_request($requestname, $params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $this->XMLRPCURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$results = curl_exec($ch);
curl_close($ch);
return $results;
}
동일한 결과를 얻을 경우 WordPress XML-RPC 서버로 요청을 올바르게 전송하고 요청을 제대로 수신할 수 있습니다.
언급URL : https://stackoverflow.com/questions/15501321/how-to-check-is-xml-rpc-enabled-in-wordpress
반응형
'sourcecode' 카테고리의 다른 글
각진 상태JS 진짜 MVC? (0) | 2023.02.27 |
---|---|
Oracle SQL: 다른 테이블의 데이터로 테이블 업데이트 (0) | 2023.02.27 |
사용자 정보를 CSV로 내보내기 - 추가 컬럼 (0) | 2023.02.27 |
NodeJS에서 JSON이 비어 있는지 확인하려면 어떻게 해야 합니까? (0) | 2023.02.27 |
jQuery 내의 WordPress 템플릿 디렉토리에 대한 경로? (0) | 2023.02.27 |