Created
November 30, 2022 03:20
-
-
Save alpha1/7e697003624791de077db88df43c10fa to your computer and use it in GitHub Desktop.
Append Site Options to WP JSON API Index
This file contains 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 | |
//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