Created
August 19, 2019 04:35
-
-
Save nandomoreirame/cad810d6019a01cb36e1955cbe43c5c2 to your computer and use it in GitHub Desktop.
WordPress REST API theme options
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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