diff options
| author | Max | 2018-11-05 12:47:47 +0100 |
|---|---|---|
| committer | Max | 2018-11-05 12:47:47 +0100 |
| commit | 1373956529cd4c5f7a5bdfaefad407b24c8bb828 (patch) | |
| tree | 98f6cee101b6a77a723f5796291b8128af396180 | |
| parent | 89bcafe654844367ea3a730c8c03b8e63047db06 (diff) | |
| download | fuselkoenig_de-1373956529cd4c5f7a5bdfaefad407b24c8bb828.tar.gz | |
Adds first version of an API to get the top navigation menu and the sidebar.
| -rw-r--r-- | api/api.php | 15 | ||||
| -rw-r--r-- | api/menu.php | 6 | ||||
| -rw-r--r-- | api/sidebar.php | 12 | ||||
| -rw-r--r-- | functions.php | 5 |
4 files changed, 38 insertions, 0 deletions
diff --git a/api/api.php b/api/api.php new file mode 100644 index 0000000..8332946 --- /dev/null +++ b/api/api.php @@ -0,0 +1,15 @@ +<?php + +require_once get_template_directory() . '/api/menu.php'; +require_once get_template_directory() . '/api/sidebar.php'; + +add_action( 'rest_api_init', function () { + register_rest_route( 'fuselkoenig', '/menu', array( + 'methods' => 'GET', + 'callback' => 'fk_get_menu', + ) ); + register_rest_route( 'fuselkoenig', '/sidebar', array( + 'methods' => 'GET', + 'callback' => 'fk_get_sidebar', + ) ); +} ); diff --git a/api/menu.php b/api/menu.php new file mode 100644 index 0000000..58ef116 --- /dev/null +++ b/api/menu.php @@ -0,0 +1,6 @@ +<?php + +function fk_get_menu() { + # Change 'menu' to your own navigation slug. + return wp_get_nav_menu_items('Top'); +} diff --git a/api/sidebar.php b/api/sidebar.php new file mode 100644 index 0000000..75c8b36 --- /dev/null +++ b/api/sidebar.php @@ -0,0 +1,12 @@ +<?php + +function fk_get_sidebar() { + ob_start(); + get_template_part( 'sidebar-templates/sidebar', 'right' ); + $content = ob_get_contents(); + $content = array("sidebar-right" => $content); + ob_end_clean(); + + return $content; +} + diff --git a/functions.php b/functions.php index 5e1fef8..7eebc3f 100644 --- a/functions.php +++ b/functions.php @@ -117,6 +117,8 @@ add_filter('posts_where', 'Delay_RSS_After_Publish'); /** * Deaktiviert REST-API und entfernt die Header aus dem HTML. + * + * It seems it doesn't work though. */ add_filter('rest_enabled', '_return_false'); add_filter('rest_jsonp_enabled', '_return_false'); @@ -250,3 +252,6 @@ if ( ! function_exists("get_my_clean_title")) { remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); */ + +require_once get_template_directory() . '/api/api.php'; + |
