method_mapbox_map_styles
apply_filters( 'method_mapbox_map_styles', array $styles )
Filters the map styles the Mapbox Map block’s Style option offers.
Description
method_mapbox_get_styles() returns the prebuilt Mapbox styles keyed by the value the block stores in mapStyle, each with a label for the dropdown and the mapbox://styles/… url the map loads. The filtered list reaches the editor as methodMapboxData.styles and the page through method_mapbox_resolve_style(), which also falls back to standard (then the first entry) for an unknown key. Add a Mapbox Studio style here to offer it by name instead of asking editors to paste its URL into Custom style URL.
Parameters
$styles (array) :
Key ⇒ array( 'label' => string, 'url' => string ). Default keys: standard, standard-satellite, streets-v12, outdoors-v12, light-v11, dark-v11, satellite-v9, satellite-streets-v12, navigation-day-v1, navigation-night-v1.
Source
File: lib/blocks/method-mapbox-map/method-mapbox-map.php, function method_mapbox_get_styles()
return apply_filters( 'method_mapbox_map_styles', $styles );
Usage
add_filter( 'method_mapbox_map_styles', function ( array $styles ) {
$styles['brand'] = array(
'label' => __( 'Brand', 'child' ),
'url' => 'mapbox://styles/your-account/cl1234567890abcdef',
);
return $styles;
} );
Notes
- Keep
standard: it is the block.json default and the fallback for unknown keys. Removing a key leaves blocks that stored it rendering the fallback style. customis reserved — it is the key that tells the block to usecustomStyleUrl.- A
urlis used as given; a style URL from another account needs the token to have access to it.
Related
- Mapbox Map block — the block
method_mapbox_token— the site tokenmethod_mapbox_map_config— the resolved style reaches the page through this
Changelog
| Version | Description |
|---|---|
| 2.0.0-beta27 | Introduced, with the Mapbox Map block (fddeba0). |