如何检查是否在wordpress中启用了XML-RPC

coo*_*ool 8 php wordpress xml-rpc

是否可以检查(通过php)在wordpress中启用XML-RPC.有点像,写一个函数会测试这个......

if(is_xmlrpc_enabled()) {
   //action
}
else {
   //another action
}
Run Code Online (Sandbox Code Playgroud)

coo*_*ool 8

对于WP版本> 3.5,默认情况下启用XML-RPC(使用'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;
}
Run Code Online (Sandbox Code Playgroud)