Skip to content

Instantly share code, notes, and snippets.

@nandomoreirame
Created August 19, 2019 04:35
Show Gist options
  • Save nandomoreirame/cad810d6019a01cb36e1955cbe43c5c2 to your computer and use it in GitHub Desktop.
Save nandomoreirame/cad810d6019a01cb36e1955cbe43c5c2 to your computer and use it in GitHub Desktop.
WordPress REST API theme options
<?php
add_action('rest_api_init', function () {
register_rest_route( 'wp/v2', 'options', [
'methods' => 'GET',
'callback' => 'api_theme_options'
]);
});
function api_theme_options($request) {
$options = [];
$general = get_option( 'theme_general_options' );
foreach ($general as $key => $item) {
$options[$key] = $item;
}
$response = new WP_REST_Response($options);
$response->set_status(200);
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment