method_get_modal_sizes()
method_get_modal_sizes()
The sizes the Modal block offers, each with its label, Bootstrap dialog class and maximum width.
Description
Returns the size map behind the Modal block’s Size option and the registry’s markup. The block editor receives it as methodModalData.sizes; Method_Modals::get_markup() looks a modal’s size option up in it for the dialog class and prints the width as --method-modal-width on the modal, where the stylesheet caps it to the viewport. An unknown size falls back to default.
Parameters
None.
Return
(array[]) Size slug ⇒ array( 'label' => string, 'class' => string, 'width' => string ). class is added to .modal-dialog ('' for the default size); width is the maximum width, '' for none.
| Slug | Label | Class | Width |
|---|---|---|---|
sm | Small | modal-sm | 300px |
default | Default | '' | 500px |
lg | Large | modal-lg | 800px |
xl | Extra large | modal-xl | 1140px |
fullscreen | Full screen | modal-fullscreen | '' |
Source
File: lib/class-method-modals.php
Usage
PHP
add_filter( 'method/modal_sizes', function ( array $sizes ) {
$sizes['narrow'] = array(
'label' => __( 'Narrow', 'child' ),
'class' => 'modal-narrow',
'width' => '360px',
);
return $sizes;
} );
Notes
- The result passes through the
method/modal_sizesfilter.defaultandfullscreenare expected to stay: the block falls back todefault, andfullscreenis what switches off the per-tier full-screen rule. - Labels are translatable (
methodtext domain).
Changelog
| Version | Description |
|---|---|
| 2.0.0-beta26 | Introduced (e12c9c0). |