Skip to content

Instantly share code, notes, and snippets.

@alpha1
Created November 30, 2022 03:20
Show Gist options
  • Save alpha1/7e697003624791de077db88df43c10fa to your computer and use it in GitHub Desktop.
Save alpha1/7e697003624791de077db88df43c10fa to your computer and use it in GitHub Desktop.
Append Site Options to WP JSON API Index
<?php
//https://developer.wordpress.org/reference/hooks/rest_index/
add_filter( 'rest_index', 'append_site_public_settings_to_rest_api_index', 10, 2 );
function append_site_public_settings_to_rest_api_index( $response, $request ){
$options_to_include = array(
'date_format',
'time_format',
'gmt_offset',
'blog_public',
'tag_base',
'wp_page_for_privacy_policy',
'posts_per_page',
'permalink_structure',
'template',
'stylesheet'
);
$options = wp_load_alloptions();;
$fields_to_add = array_intersect_key( $options, array_flip( $options_to_include ) );
$response->data = array_merge( $response->data, $fields_to_add );
return $response;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment