-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Navigation Screen: Menu item custom ACF options #31551
Comments
Hi all 👋. Elliot here representing the Advanced Custom Fields plugin. We are very interested to know what plans are in place to handle backwards compatibility for the PHP wp_nav_menu_item_custom_fields action introduced in WP 5.4 allowing custom HTML to be added into menu items. Please note that ACF is not the only plugin using this action 👍. |
Thanks again for raising this @amir2mi. @elliotcondon This is on the project board and we'll be testing this shortly in order to review ways in which we can support the |
@getdave Absolutely. Where can I sign-up and stay notified on these upcoming changes? |
@elliotcondon That's great - thank you. Perhaps it's easiest if we use this Issue. I will ping you for review once we get to resolving this. Also you might be interested in the Navigation Editor and Navigation Block project boards (but don't feel obliged to dive in there). Thanks for agreeing to be involved. Much appreciated. |
Just performed a quick test to illustrate what I believe we're discussing here. Screen.Capture.on.2021-05-10.at.12-51-39.movEssentially with ACF (and other Plugins) you can register fields (of many types) to appear on the Menus screen. That data is then saved as post meta and rendered as required on the Menus screen or on the Theme front end. In ACFs case they are making use of it here to render additional form fields for each menu item on the Menus screen. |
As part of this discussion, let's also explore the alternatives that the Nav Editor / Gutenberg can expose which will mirror the same functionality. |
At a guess, all these custom fields are stored in post meta on the menu item. So have you considered using the As for rendering form inputs, I have a couple of idea.
|
One thing I'm considering is that I wonder whether if (as you suggest) we were to render the HTML within an iframe (like we do for Legacy Widgets) we might be able to provide backwards compatibility in all cases. Trying to guess whether the developer is rendering a Also worth noting that Gutenberg provides APIs to add fields to blocks out of the box and as a result developers can/will be able to add fields to all the blocks that are available in the Nav Editor. I'm not saying that's good enough as a solution, but we should start to signpost developers towards these new APIs early in order that they can provide their users with the best possible experience. Perhaps it would be good to get input from folks who were heavily involved in the Widgets project - @noisysocks @draganescu? |
Hey @spacedmonkey @getdave. I've been following this thread for the ACF team. Switching to We only had to make a small change for an issue with verifying nonces (as we don't have access to $_POST) with the new widget block editor which maintains backwards compatibility like @getdave said, so that route feels like the best if it's viable. |
Hm, very tricky!
Yes I think this is all that we can realistically do. Perhaps display the output of The form would have to contain all of the same hidden Something sensible that results in backend hooks firing would have to happen on form submit2. Perhaps the This approach wouldn't be 100% backwards compatible3 but should hopefully make transition easier as @lgladdy says.
We shouldn't need to deduct anything from the output of 1 An iframe might not be necessary. Legacy Widget doesn't use one for the form. |
I strongly recommend you do this in general, not only for menu items, but for all data that you save in meta ( user / post / comment etc). I believe it would map pretty easily and would add some massive benefits to compatibility with core and your users. @lgladdy @elliotcondon , do feel free to reach out privately via slack or email, I can create a proof of concept PR for you, if you so wish. I understand this is a long term goal and isn't a solution this direct problem, just something I believe you should do. For context, I have worked a lot on register meta in core, so will be able to help a lot here.
We don't need to guess this, we know that core wraps it is <form tag. See the action in core, there are buttons and fieldsets line below, it is in a form. Regarding I have the following recommendation.
This is just rough idea for now that has some holes, like how it might work in the customize but a solution like this may work. Thoughts? |
For some extra context, there is a new tracking ticket for backwards compat #35157 |
For some extra context, I have prototyped added support for Checkout my branch. To test, create some menu items and call Sadly in my testing, my workaround didn't work. I believe there is some conditional logic in the ACF plugin that means that fields not loading the REST API. I couldn't work it out in my limited tests. I did however see this PR work, by installing menu-icons @lgladdy any idea why this fields would not be showing on the rest api if we using the |
@spacedmonkey Can't see anything obvious that would stop us rendering so long as at least 4 parameters are passed into I'll try and get your branch running and test this further with ACF. |
@spacedmonkey Because ACF supports different fields based on the menu, we also need to know what menu ID is currently being edited when we render the fields for it. Currently, we do this with this code on a Could this be passed through as part of argument 4 ( |
@lgladdy I think the data being passed to |
@spacedmonkey Yeh - agreed the data is correct, but ACF uses other filters prior to My request to add the menu ID to the Whilst we can probably work around it not being there in the case of existing menu items by using the term meta lookup to get the menu ID; New menu items added would need to be assigned to a menu before we could detect the fields required, unless we can get the menu ID into that filter. Edit: Specifically, this code is trying to use the existing loaded context to know what menu ID is being displayed. This isn't set, so ACF never believes there are any fields assigned to that nav menu. |
@lgladdy Correct me if I am wrong, but can't you already get the menu id from the wp_nav_menu_item_custom_fields action. The last param on this action is |
@spacedmonkey Weirdly, that Here's a build of ACF 5.10.2 which adds support for using it to know the menu ID, and this is working with your branch now and our fields are rendered in your item_custom_fields[rendered] key. |
I'm closing this issue since the navigation screen is no longer actively developed. Related: #43620. |
Advanced Custom Fields (ACF) is a popular plugin which developers use for their themes.
It has the feature to add custom options to each menu item, therefore, users can customize that menu item and the theme will show the menu depends on that settings, these options can be menu item color, icon, and so on.
I found that the new Navigation editor does not support those custom options.
Classic navigation:
New navigation:
The text was updated successfully, but these errors were encountered: