General hooks
This section covers hooks aimed to improve your Modern Fields experience as developer and site creator.
Change the display value of a field
modern-fields/get_field/value
Since: 1.1.0
Functions like get_field() and the_field() retrieve the raw meta value, but you can change that with this filter.
You can also set the name of the field directly in the field name:
Change the minimum role to access Modern Fields
modern-fields/permissions
Since: 1.0.2
By default, only administrators or user with manage_options capability can access Modern Fields admin pages.
To change that, use the permission hook:
Remove blocks from field group editor
modern-fields/blocks/disabled_blocks
Since: 1.0.0
Disable unwanted blocks in the field group editor. Check the full core blocks list on the official WordPress documentation.
By default, Modern Fields already filters most of the useless blocks in the fields context.
Add a new menu to Modern Fields admin pages
modern-fields/admin/nav_items
Since: 1.0.2
Adds a menu entry on the Modern Fields admin pages. This hook is useful for add-on creators.
Provide the WordPress page slug as defined in add_menu_page function.
Send additional data to block editor
modern-fields/admin/script_data
Since: 1.0.2
Send additional data from PHP to modernFields JS global in the editor.
Change who can use the fields in the editor
modern-fields/editor_permissions
Since: 1.4.0
The Field value block, the Query Loop filters and the other tools used while editing content ask for the edit_posts capability by default. Return another capability to change that. Which field groups a user sees is still decided by the roles set on each group.
Change the meta key of a bidirectional relation
modern-fields/bidirectional/meta_key
Since: 1.4.0
A bidirectional field records the reverse relation in a post meta named mf_linked_from_{field_name}. This filter changes that key. Change it before the field is used: relations already recorded under the old key are not moved.
Move or rename the JSON sync folder
modern-fields/sync/json_path
Since: 1.6.0
The theme sync writes its JSON files to mf-json/, at the root of the active theme. This filter receives and returns the absolute path of that folder. The folder still has to exist for the sync to run.
Hooks for add-ons
This section cover all the hooks useful for creating a Modern Fields add-on.
Register a screen in Modern fields settings
modern-fields/admin/menu_tabs
Since: 1.1.0
This PHP filters allows you to register a new screen along with a menu entry the Modern Fields settings.
Sanitize and describe the value of a custom field
modern-fields/meta/sanitize_callback and modern-fields/meta/schema
Since: 1.0.0
The first one changes the function sanitizing the value of a field before it is saved. The second one describes the content of an array or object value. Both receive the field as an object. See Create a custom field type.
Map field hooks
These filters configure the Map field: which provider draws the maps, and the credentials and services it uses. Each one runs after its matching constant, so it wins.
| Filter | Since | Arguments | Role |
|---|---|---|---|
modern-fields/maps/provider | 1.4.0 | string $id | The provider drawing the maps: google or osm. Constant: MODERN_FIELDS_MAPS_PROVIDER (since 1.5.0) |
modern-fields/maps/api_key | 1.4.0 | string $key, string $providerId | The Google Maps API key. Constant: MODERN_FIELDS_GOOGLE_MAPS_API_KEY |
modern-fields/maps/map_id | 1.4.0 | string $mapId, string $providerId | The site-wide Google Map ID. Constant: MODERN_FIELDS_GOOGLE_MAPS_MAP_ID |
modern-fields/maps/providers | 1.4.0 | array $providers | Register another map provider, keyed by id |
modern-fields/maps/osm/tile_url | 1.5.0 | string $url, string $providerId | The OpenStreetMap tile URL. Constant: MODERN_FIELDS_OSM_TILE_URL |
modern-fields/maps/osm/geocoder_url | 1.5.0 | string $url, string $providerId | The Nominatim-compatible geocoder. Constant: MODERN_FIELDS_OSM_GEOCODER_URL |
modern-fields/maps/osm/attribution | 1.5.0 | string $html | The credit line shown on OpenStreetMap maps |
For example, to use a different Google key outside production: