sc0ttkclark / wordpress-fields-api

The 2024 Fields API proposal for WordPress Core
https://make.wordpress.org/core/tag/fields-api/
361 stars 42 forks source link

Rules to set visibility of sections and fields based on page template, post category, and more #9

Closed nickcernis closed 9 years ago

nickcernis commented 9 years ago

Advanced Custom Fields and similar plugins offer rules for meta box visibility such as these:

add_new_field_group_ _my_blog_ _wordpress

This is very powerful because it allows the creation of meta boxes that:

To accomplish this, there are a couple of approaches we could take:

  1. Let the first parameter of the add_field and add_section methods take an optional array instead of the default string, which would allow users to specify in more detail exactly where fields and sections appear.
  2. Add an additional 'visibility' parameter that would work alongside 'capability' to allow users to filter areas where fields would appear. (This may be more legible than option one.)

I appreciate that the Fields API may not be a complete functional replacement for ACF. But if it's to become widely adopted and loved by all, it probably needs to take on some of the more advanced functionality that developers are currently gaining from third-party plugins.

danielbachhuber commented 9 years ago

Fieldmanager has a similar display_ifattribute. The logic is such that the field will display if the value of another field is N.

helen commented 9 years ago

The aim as far as plugins are concerned is not to replace plugins like ACF - it's to enable those plugins that provide more complex UI and/or UI builders for fields to use a common API. The project in its current status is rightfully focusing on the PHP side of the API, and I would not endorse the inclusion of this functionality via UI in core itself.

sc0ttkclark commented 9 years ago

Definitely what I was about to say @helenhousandi :)

I will make every effort to ensure something like this will be easy to hook into for plugin purposes though, so anyone with a vested interest feel free to follow up on this.

pimschaaf commented 9 years ago

Just to clarify, in the above comments at least two types of visibility dependencies are discussed. ACF discerns the two as Custom location rules and Conditional Logic.

Drawing a parallel between ACF and WP Fields API I think the first would apply to $wp_fields->add_section, while the second would apply to $wp_fields->add_field.

Custom location rules are discussed above by @nickcernis. In addition, Conditional Logic works based on the values of 'sibling' fields (i.e. fields that are in the same section).

References: http://www.advancedcustomfields.com/resources/custom-location-rules http://www.advancedcustomfields.com/resources/field-settings/ (it appears little documentation is available for ACFs Conditional Logic)

nickcernis commented 9 years ago

Thanks for the feedback, @helenhousandi and @sc0ttkclark!

To clarify, I wasn't proposing that this be added via a new UI – I was suggesting that it be possible without a lot of additional code via the new API.

sc0ttkclark commented 9 years ago

Then request granted :)