Control: Section Open Close - 10quality/wpmvc-addon-metaboxer GitHub Wiki

Controls used as field types to open and close a fieldset (fields section) wrapper.

It is recommended to use fieldsets (section) because the spacing between fields will be reduced.

Usage

This control doesn't need a specific id, so you can use uniqid() as field ID, see an example:

class Post extends Model
{
    // Class properties and methods...

    protected function init()
    {
        $this->metaboxes = [
            'metabox_id' => [
                'tabs' => [
                    'tab_id' => [
                        'fields' => [

                            uniqid() => [
                                'type' => 'section_open',

                                // Optional. Default: Empty
                                'title' => __( 'Section title', 'my-domain' ),

                                // Optional. Default: Empty
                                'description' => __( 'Section description', 'my-domain' ),
                            ],

                            'field_id1' => [...],
                            'field_id2' => [...],

                            uniqid() => [
                               'type' => 'section_close',
                            ],
                            // Other fields...
                        ],
                    ],
                ],
            ],
        ];
    }
}

Auto close

The add-on is intelligent enough to catch open sections without defined closure and will close them automatically.

// Namespace and use statement...

class Post extends Model
{
    // Class properties and methods...

    protected function init()
    {
        $this->metaboxes = [
            'metabox_id' => [
                'tabs' => [
                    'tab_id' => [
                        'fields' => [

                            uniqid() => [
                                'type' => 'section_open',

                                // Optional. Default: Empty
                                'title' => __( 'Section title', 'my-domain' ),

                                // Optional. Default: Empty
                                'description' => __( 'Section description', 'my-domain' ),
                            ],
                            'field_id1' => [...],
                            'field_id2' => [...],

                            // <=== ADD-ON will close the section here
                        ],
                    ],
                ],
            ],
        ];
    }
}

Separator

Use control type section_separator to render a line between fieldsets (sections), see an example:

class Post extends Model
{
    // Class properties and methods...

    protected function init()
    {
        $this->metaboxes = [
            'metabox_id' => [
                'tabs' => [
                    'tab_id' => [
                        'fields' => [

                            uniqid() => [
                                'type' => 'section_open',

                                // Optional. Default: Empty
                                'title' => __( 'Section title', 'my-domain' ),

                                // Optional. Default: Empty
                                'description' => __( 'Section description', 'my-domain' ),
                            ],

                            'field_id1' => [...],
                            'field_id2' => [...],

                            uniqid() => [
                               'type' => 'section_separator',
                            ],

                            uniqid() => [
                                'type' => 'section_open',
                                'title' => __( 'Section 2', 'my-domain' ),
                            ],

                            // Other fields...
                        ],
                    ],
                ],
            ],
        ];
    }
}