Giter Site home page Giter Site logo

unfulvio / wp-api-menus Goto Github PK

View Code? Open in Web Editor NEW
140.0 13.0 59.0 230 KB

:abcd: Menu routes for WordPress JSON REST API.

Home Page: https://wordpress.org/plugins/wp-api-menus

License: GNU General Public License v2.0

PHP 89.46% JavaScript 10.54%
wordpress wp-api php json-rest

wp-api-menus's Introduction

Menu routes for WordPress JSON REST API

GitHub version Scrutinizer Code Quality Join the chat at https://gitter.im/unfulvio/wp-api-menus

WordPress plugin that extends the JSON REST WP API with new routes pointing to WordPress registered menus. Read the WP API documentation.

Download from WordPress.org

New routes available:

  • /menus list of every registered menu.
  • /menus/<id> data for a specific menu.
  • /menu-locations list of all registered theme locations.
  • /menu-locations/<location> data for menu in specified menu in theme location.

Currently, the menu-locations/<location> route for individual menus will return a tree with full menu hierarchy, with correct menu item order and listing children for each menu item. The menus/<id> route will output menu details and a flat array of menu items. Item order or if each item has a parent will be indicated in each item attributes, but this route won't output items as a tree.

You can alter the V1 data arrangement of each individual menu items and children using the filter hook json_menus_format_menu_item.

WP API V2

In V1 of the REST API the routes are located by default at wp-json/menus/ etc.

In V2 the routes by default are at wp-json/wp-api-menus/v2/ (e.g. wp-json/wp-api-menus/v2/menus/, etc.) since V2 encourages prefixing and version namespacing.

You can alter the V2 data arrangement of the REST response using the filter hooks

  1. rest_menus_format_menus to alter the list of menu items returned (e.g from wp-json/wp-api-menus/v2/menus/)
  2. rest_menus_format_menu to alter a single menu returned (e.g wp-json/wp-api-menus/v2/menus/<id>)
  3. rest_menus_format_menu_item to alter the menu items returned (e.g wp-json/wp-api-menus/v2/menus/<id> items property)

Contributing

  • Submit a pull request or open a ticket here on GitHub.

wp-api-menus's People

Contributors

dobbler avatar fahrradflucht avatar gitter-badger avatar josh-taylor avatar k1sul1 avatar mattheu avatar pdufour avatar puredazzle avatar sarahannnicholson avatar sathyapulse avatar stirtingale avatar tdlm avatar thefrosty avatar unfulvio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-api-menus's Issues

Future of this plugin development

Hey there,

I'm sorry if I have unanswered many issues opened here, or support requests on WordPress.org.

It's a shame, I just don't have the time to maintain the plugin.

In the past few years I've added some collaborators to this project:

Please let me know if you're still actively monitoring this project as collaborators and if you'd like to coordinate with each other.

If there's interest, I would recommend that the project has a coordinator or a lead. So I'd advise for some of you to commit to that role than just patching the plugin.

Eventually this person could also get authorship on WordPress.org and publish updates moving forward.

Cheers and thanks for having shown interest and support for a plugin born out of a side project to support some personal/work projects I had back then several years ago! :)

How to display a menu?

Hi, the plugin works fine but I do not see how to handle the rendering of the menu. A small example please?

Push a new release

I want to use the items slug implemented in #28 but there has not been a new release since it was merged.
Can you make a new release and make it available as an update of the plugin?

WP API menus & Polylang

Hi.
First at all, thanks for your plugin, it work very well.

i use the plugin Polylang to manage my website in 2 languages.

Do you know how i can retrieve a menu location with a language param, to get the menu in the correct language ?
or,

it will be great to retireve a menu by it slug...
http://www.horsepilot.dev/wp-json/wp-api-menus/v2/menus/49 => http://www.horsepilot.dev/wp-json/wp-api-menus/v2/menus/main-nav

thanks for youtr help.

In wordpress v 4.4.2 menu items is empty

Hi !
For request
http://localhost/wordpress/wp-json/wp-api-menus/v2/menus/3

Result contains empty items (
{ "ID": 3, "name": "Main menu", "slug": "main-menu", "description": "", "count": 1, "items": [], "meta": { "links": { "collection": "http://localhost/wordpress/wp-json/wp/v2/menus/", "self": "http://localhost/wordpress/wp-json/wp/v2/menus/3" } } }

Relative URL's / Slug names

Hi there,

Im trying to work this into a prototype im making atm, and im doing some custom routes to navigate my content such as localhost/:page

I want to be able to generate a menu with the slugs that i can then use to look up the pages rather than getting the absolute url.

I can do that with custom url's but it would be great if it could include the slug of the page when automaticly adding new pages to the menu

Empty Items Array

On WP 4.4.1 with WP API v2 and this plugin, I get an empty array in the items prop. The count still says 5, interestingly enough.

{
    ID: 10,
    name: "Footer",
    slug: "footer",
    description: "",
    count: 5,
    items: [ ],
    meta: {
        links: {
            collection: "http://localhost:8888/wp-json/wp/v2/menus/",
            self: "http://localhost:8888/wp-json/wp/v2/menus/10"
        }
    }
}

This issue has already been reported on Wordpress.org, but I'm reporting it here in hopes of support.

Help? :)

PHP 5.2 Compatability

I tried to activate this on a site running PHP 5.2.17, and got an error due to the use of anonymous functions. I'm going to try to upgrade the PHP for the site, but you should note in the readme what the minimum tested PHP version is.

Error, for reference:

Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in wp-content/plugins/wp-api-menus/includes/wp-api-menus-v2.php on line 185

https://github.com/unfulvio/wp-api-menus/blob/master/includes/wp-api-menus-v2.php#L185

Show post count in json output

Is it possible to add support for post_count of a category if the menu item is category (object: "category")??
will show total number of posts a category/children category contains.

WordPress 5.5 Support

You can read about the REST changes here: https://make.wordpress.org/core/2020/07/22/rest-api-changes-in-wordpress-5-5/

In [48526] a _doing_it_wrong notice has been added when a permission callback is omitted. For REST API routes that are intended to be public, it is recommended to set the permission callback to the __return_true built in function.

Running WordPress 5.5 beta4.

See example notice:

PHP Notice:  register_rest_route was called <strong>incorrectly</strong>. 
The REST API route definition for <code>wp-api-menus/v2/menus</code> 
is missing the required <code>permission_callback</code> argument. 
For REST API routes that are intended to be public, use <code>__return_true</code> 
as the permission callback. Please see 
<a href="https://wordpress.org/support/article/debugging-in-wordpress/">Debugging in WordPress</a> 
for more information. (This message was added in version 5.5.0.) 
in /usr/local/wordpress/wp-includes/functions.php on line 5225

ID or id in menu array

Hello,

Since the WP rest API uses lowercase for id's it might be a good idea that the menu api also uses id instead of ID?

Best regards,
Chris

Children

Why should I have to define a theme-defined menu location instead of being able to call a slugified version of a menu I've already created in appearances? I'm able to call an ID of a non-theme-defined menu, so I should be able to do the same for a location.

Personally, if I'm going to call a menu by ID I should be able to define a &children=true/false filter on it instead of calling it via location... it just makes it easier.

Thanks in advance for the readover.

wp menu caching?

Hello,

I wanted to first say thank you for the plugin, it has helped me immensely.

I noticed there was a certain delay between when the api response updates with any modifications to the menu. Is there some internal caching going on, or is this dictated by wp or wp-api? I am relatively new to the wordpress world and learning all these things, so apologize if this question seems ignorant.

Thank you.

Menu nesting with depth > 2 creates duplicate items

Having a menu structure in WordPress as:

screen shot 2015-03-12 at 12 08 19

Outputs the following JSON (hidden items not related to the problem):

[{
    "ID":1746,
    "order":1,
    "parent":0,
    "title":"Projects",
    "//": "...",
    "children": [{
          "ID":1747,
          "order":2,
          "parent":1746,
          "title":"Education",
          "//": "...",
          "children": [{
               "ID":1750,
               "order":3,
               "parent":1747,
               "title":"Westwood College",
               "//": "...",
               "children":[]}
          ]
     }, {
          "ID":1750,
          "order":3,
          "parent":1747,
          "title":"Westwood College",
          "//": "...",
          "children":[]
     }]
}]

The Westwood College item is duplicated on the same level as Education.

WPML support

WP-API supports WPML out of the box, so API queries with the parameter lang=CODE or similar just works. This doesn't seem to work in this plugin. Are there any plans to implement this support or am I missing some way it's already implemented?

Support for custom metas/ACF fields

Hi there,

Great plugin! Just wondering if there's any way I could add in support for displaying custom metas attached to a menu? Since 5.6.0, Advanced Custom Fields has added support for adding custom fields to menus, would be great to be able to pull this into the API.

If you're looking for contributors I'm happy to get involved on this. Cheers

Create Menu

Hi, couple months ago I have asked question about creating menu, as that absent in old version. Do you have that in new version. Can we send POST request?

Doesn't seem to be working

I have this installed alongside v 2 of the WordPress REST API.

When I try and hit '/wp-json/wp/v2/menus/' I'm getting a 404 error:

{
  "code": "rest_no_route",
  "message": "No route was found matching the URL and request method",
  "data": {
    "status": 404
  }
}

Any ideas?

Evan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.