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.

SlugLabelClassWidth
smSmallmodal-sm300px
defaultDefault''500px
lgLargemodal-lg800px
xlExtra largemodal-xl1140px
fullscreenFull screenmodal-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_sizes filter. default and fullscreen are expected to stay: the block falls back to default, and fullscreen is what switches off the per-tier full-screen rule.
  • Labels are translatable (method text domain).

Changelog

VersionDescription
2.0.0-beta26Introduced (e12c9c0).