コード例 #1
0
/**
 * Load the JSON API
 */
function rest_oauth1_loaded()
{
    if (empty($GLOBALS['wp']->query_vars['rest_oauth1'])) {
        return;
    }
    $authenticator = new WP_REST_OAuth1();
    $response = $authenticator->dispatch($GLOBALS['wp']->query_vars['rest_oauth1']);
    if (is_wp_error($response)) {
        $error_data = $response->get_error_data();
        if (is_array($error_data) && isset($error_data['status'])) {
            $status = $error_data['status'];
        } else {
            $status = 500;
        }
        status_header($status);
        echo $response->get_error_message();
        die;
    }
    header('Content-Type: application/x-www-form-urlencoded; charset=utf-8');
    $response = http_build_query($response, '', '&');
    echo $response;
    // Finish off our request
    die;
}