{"id":88155,"date":"2018-07-04T08:37:06","date_gmt":"2018-07-04T08:37:06","guid":{"rendered":"https:\/\/wordpress.org\/plugins\/wp-rest-menu\/"},"modified":"2022-02-17T20:43:38","modified_gmt":"2022-02-17T20:43:38","slug":"wp-rest-menu","status":"publish","type":"plugin","link":"https:\/\/sr.wordpress.org\/plugins\/wp-rest-menu\/","author":7669888,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"1.0.4","stable_tag":"1.0.4","tested":"5.9.13","requires":"5.0","requires_php":"5.6","requires_plugins":"","header_name":"WP REST Menu","header_author":"Kostas Charalampidis <skapator@gmail.com>","header_description":"Adds menu endpoints to WP REST API, filters json fields optionaly and provides an additional nested parent-child endpoint.","assets_banners_color":"b467dd","last_updated":"2022-02-17 20:43:38","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"https:\/noveldigital.pro","header_author_uri":"https:\/\/noveldigital.pro","rating":5,"author_block_rating":0,"active_installs":100,"downloads":8445,"num_ratings":4,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","faq"],"tags":{"1.0":{"tag":"1.0","author":"skapator","date":"2019-03-09 19:43:49"},"1.0.1":{"tag":"1.0.1","author":"skapator","date":"2019-03-09 19:43:49"},"1.0.2":{"tag":"1.0.2","author":"skapator","date":"2020-04-08 20:04:38"},"1.0.3":{"tag":"1.0.3","author":"skapator","date":"2022-02-17 20:41:38"},"1.0.4":{"tag":"1.0.4","author":"skapator","date":"2022-02-17 20:43:38"}},"upgrade_notice":[],"ratings":{"1":0,"2":0,"3":0,"4":0,"5":"3"},"assets_icons":{"icon-128x128.png":{"filename":"icon-128x128.png","revision":2678036,"resolution":"128x128","location":"assets","locale":""}},"assets_banners":{"banner-772x250.png":{"filename":"banner-772x250.png","revision":2678035,"resolution":"772x250","location":"assets","locale":""}},"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.0","1.0.1","1.0.2","1.0.3","1.0.4"],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[1556,158814,2301,158815],"plugin_category":[],"plugin_contributors":[83278],"plugin_business_model":[],"class_list":["post-88155","plugin","type-plugin","status-publish","hentry","plugin_tags-api","plugin_tags-v2","plugin_tags-wp-rest-api","plugin_tags-wp-rest-menus","plugin_contributors-skapator","plugin_committers-skapator"],"banners":{"banner":"https:\/\/ps.w.org\/wp-rest-menu\/assets\/banner-772x250.png?rev=2678035","banner_2x":false,"banner_rtl":false,"banner_2x_rtl":false},"icons":{"svg":false,"icon":"https:\/\/ps.w.org\/wp-rest-menu\/assets\/icon-128x128.png?rev=2678036","icon_2x":false,"generated":false},"screenshots":[],"raw_content":"<!--section=description-->\n<p>This plugin adds new endpoints for WordPress registered menus.\nUsefull when building SPAs with Vuejs, React or any front-end framework.\nWorks with Advacned Custom Fields, WPML, Polylang<\/p>\n\n<p>The new endpoints available:<\/p>\n\n<p><strong>Get all menus<\/strong><\/p>\n\n<pre><code>GET \/menus\/v1\/menus\n\n\/\/ Response sample\n{  \n    term_id: 2,\n    name: \"Main Menu\",\n    slug: \"main-menu\",\n    term_group: 0,\n    term_taxonomy_id: 2,\n    taxonomy: \"nav_menu\",\n    description: \"\",\n    parent: 0,\n    count: 8,\n    filter: \"raw\"\n},\n...\n<\/code><\/pre>\n\n<p><strong>Get a menus items by id (term_id)<\/strong><\/p>\n\n<pre><code>GET \/menus\/v1\/menus\/&lt;id&gt;\n\n\/\/ Response sample\n{  \n    ID: 5,\n    post_author: \"1\",\n    post_date: \"2018-07-03 06:42:18\",\n    post_date_gmt: \"2018-07-03 06:42:18\",\n    filter: \"raw\",\n    db_id:5,\n    menu_item_parent: \"0\",\n    object_id: \"5\",\n    object: \"custom\",\n    type: \"custom\",\n    type_label: \"Custom Link\",\n    title: \"Home\",\n    url: \"https:\\\/\\\/wp-rest-menu.local\\\/\",\n    target: \"\",\n    attr_title: \"\",\n    description: \"\",\n    classes: [  \n     \"\"\n    ],\n    xfn: \"\",\n    meta: null\n},\n...\n<\/code><\/pre>\n\n<p><strong>Get all menu locations<\/strong>\nAll menu locations assigned  in \/wp-admin\/nav-menus.php?action=locations<\/p>\n\n<pre><code>GET \/menus\/v1\/menus\/locations is deprecated and will be removed in newer versions use:\nGET \/menus\/v1\/locations\n\n\/\/ Response example\n{  \n    slug: \"top\",\n    description: \"Top Menu\"\n},\n{  \n    slug: \"social\",\n    description: \"Social Links Menu\"\n}\n...\n<\/code><\/pre>\n\n<p><strong>Get all menu location items<\/strong>\nAll menu locations assigned in \/wp-admin\/nav-menus.php?action=locations<\/p>\n\n<pre><code>GET \/menus\/v1\/menus\/locations\/&lt;slug&gt; is deprecated and will be removed in newer versions use:\nGET \/menus\/v1\/locations\/&lt;slug&gt;\n\n\/\/ Response samexampleple\n{  \n    ID: 5,\n    post_author: \"1\",\n    post_date: \"2018-07-03 06:42:18\",\n    post_date_gmt: \"2018-07-03 06:42:18\",\n    filter: \"raw\",\n    db_id:5,\n    menu_item_parent: \"0\",\n    object_id: \"5\",\n    object: \"custom\",\n    type: \"custom\",\n    type_label: \"Custom Link\",\n    title: \"Home\",\n    url: \"https:\\\/\\\/wp-rest-menu.local\\\/\",\n    target: \"\",\n    attr_title: \"\",\n    description: \"\",\n    classes: [  \n     \"\"\n    ],\n    xfn: \"\",\n    meta: null\n},\n...\n<\/code><\/pre>\n\n<p>There are two filters availiable:<\/p>\n\n<p><strong>Fields Filter<\/strong><\/p>\n\n<pre><code>\/\/ it will return only the fields specified\nGET \/menus\/v1\/menus\/&lt;id&gt;\/?fields=ID,title,meta\n\n\/\/ Response sample\n\/\/ Response sample\n{  \n    ID: 5,\n    title: \"Home\",\n    meta: null\n},\n...\n<\/code><\/pre>\n\n<p><strong>Nested Items Filter<\/strong><\/p>\n\n<pre><code>\/\/ it will return menu items parents and nested children in a 'children' field\n\/\/ Currently only one level deep is supported\nGET \/menus\/v1\/menus\/&lt;id&gt;\/?nested=1\n\n\/\/ Response sample\n{  \n  ID: 1716,\n  menu_item_parent: \"0\",\n  object_id: \"174\",\n  object: \"page\",\n  title: \"Level 1\",\n  meta: {  \n     vue_component: \"LevelComponent\",\n     menu-item-field-01: \"Field 1 value\",\n     menu-item-field-02: \"Field 2 value\"\n  },\n  children:[  \n     {  \n        ID: 1717,\n        menu_item_parent: \"1716\",\n        object_id: \"744\",\n        object: \"page\",\n        title: \"Level 2b\",\n        meta : {  \n           vue_component: null\n        }\n     },\n     ...\n  ]\n},\n...\n<\/code><\/pre>\n\n<p><strong>WP filter hooks<\/strong><\/p>\n\n<p>This plugin is quite configurable and provides lots of wp filter hooks from returned data in responses for each endpoint to params validation and endpoint permissions.<\/p>\n\n<pre><code>add_filter( 'wprm\/get_menus\/wp_get_nav_menus\/args', 'my_wp_get_nav_menus', 10, 1 );\n(used in GET \/menus\/v1\/menus)\n\nfunction my_wp_get_nav_menus( $args ) {\n    \/\/ do something with wp_get_nav_menus $args array\n    return $args;\n}\n\n\n\nadd_filter( 'wprm\/get_menus', 'my_get_menus', 10, 1 );\n(used in GET \/menus\/v1\/menus)\n\nfunction my_get_menus( $menus ) {\n    \/\/ do something with $menus array\n\n    return $menus; \/\/ WP_Error|WP_HTTP_Response|WP_REST_Response|mixed\n}\n\n\n\nadd_filter( 'wprm\/get_menu_locations', 'my_get_menu_locations', 10, 1 );\n(used in GET \/menus\/v1\/locations)\n\nfunction my_get_menu_locations( $locations ) {\n    \/\/ You can modify the $locations array response (get_registered_nav_menus())\n\n    return $locations; \/\/ WP_Error|WP_HTTP_Response|WP_REST_Response|mixed\n}\n\n\n\nadd_filter( 'wprm\/get_menu_items', 'my_get_menu_items', 10, 1 );\n(used in GET \/menus\/v1\/menus\/&lt;id&gt;)\n\nfunction my_rest_menu_item_fields( $menu ) {\n    \/\/ You can modify the $menu items\n\n    return $menu;\n}\n\n\n\nadd_filter( 'wprm\/get_location_menu_items', 'my_get_location_menu_items', 10, 1 );\n(used in GET \/menus\/v1\/menus\/&lt;id&gt;)\n\nfunction my_get_location_menu_items( $menu ) {\n    \/\/ You can modify the locations $menu items\n\n    return $menu;\n}\n\n\n\nadd_filter( 'wprm\/get_item_fields\/filter_fields', 'my_filter_fields', 10, 1 );\n(used to filter return field -node edges-)\n\nfunction my_filter_fields( $fields ) {\n    \/\/ You can modify the $fields array so\n    \/\/ you can filter the return fields for all endpoints\n    \/\/ without using the url param ?fields\n\n    $fields = array( 'ID', 'title' );\n    return $fields;\n}\n<\/code><\/pre>\n\n<p>More filters<\/p>\n\n<pre><code>apply_filters('wprm\/get_menus\/permissions', '__return_true', $request );\napply_filters('wprm\/get_menu_locations\/permissions', '__return_true', $request );\napply_filters('wprm\/get_menu_items\/permissions', '__return_true', $request );\napply_filters('wprm\/get_menu_items\/validate\/args\/id', is_numeric( $param ), $param, $request, $key );\napply_filters('wprm\/get_menu_items\/validate\/args\/fields', is_string( $param ), $param, $request, $key );\napply_filters('wprm\/get_menu_items\/validate\/args\/nested', absint( $param ), $param, $request, $key );\napply_filters('wprm\/get_location_menu_items\/permissions', '__return_true', $request );\napply_filters('wprm\/get_location_menu_items\/validate\/args\/slug', is_string( $param ), $param, $request, $key );\napply_filters('wprm\/get_location_menu_items\/validate\/args\/fields', is_string( $param ), $param, $request, $key );\napply_filters('wprm\/get_location_menu_items\/validate\/args\/nested', absint( $param ), $param, $request, $key );\napply_filters('wprm\/get_location_menu_items\/permissions', '__return_true', $request );\napply_filters('wprm\/get_location_menu_items\/validate\/args\/slug', is_string( $param ), $param, $request, $key );\napply_filters('wprm\/get_location_menu_items\/validate\/args\/fields', is_string( $param ), $param, $request, $key );\napply_filters('wprm\/get_location_menu_items\/validate\/args\/nested', absint( $param ), $param, $request, $key );\n<\/code><\/pre>\n\n<p>Supports custom fields and Advanced Custom Fields\nIf ACF is installed the response node edge is <em>acf<\/em> else <em>meta<\/em>\nIn newer version these two edges will co exist and the plugin will separate natively registered custom fields ad acf registered ones.<\/p>\n\n<!--section=installation-->\n<p>There are no requirements other than Wordpress and one active menu. Installation is simple:<\/p>\n\n<ol>\n<li>Upload the <code>wp-rest-menus<\/code> folder to the <code>\/wp-content\/plugins\/<\/code> directory<\/li>\n<li>Activate the plugin through the 'Plugins' menu in WordPress<\/li>\n<\/ol>\n\n<!--section=faq-->\n<dl>\n<dt id='how%20do%20i%20use%20this%20plugin%3F'><h3>How do I use this plugin?<\/h3><\/dt>\n<dd><p>It creates endpoints for wp nav menus to use in your front end.<\/p><\/dd>\n<dt id='can%20i%20contribute%3F'><h3>Can I contribute?<\/h3><\/dt>\n<dd><p>Yes, you can fork it on <a href=\"https:\/\/github.com\/kostasxyz\/wp-rest-menus\">github<\/a>.<\/p><\/dd>\n\n<\/dl>","raw_excerpt":"Add menus endpoints to WP REST API","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/sr.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/88155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sr.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/sr.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/sr.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=88155"}],"author":[{"embeddable":true,"href":"https:\/\/sr.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/skapator"}],"wp:attachment":[{"href":"https:\/\/sr.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=88155"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/sr.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=88155"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/sr.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=88155"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/sr.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=88155"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/sr.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=88155"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/sr.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=88155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}