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()

PHP
return apply_filters( 'method_mapbox_map_styles', $styles );

Usage

PHP
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.
  • custom is reserved — it is the key that tells the block to use customStyleUrl.
  • A url is used as given; a style URL from another account needs the token to have access to it.

Related


Changelog

VersionDescription
2.0.0-beta27Introduced, with the Mapbox Map block (fddeba0).