Options Panels


There are some settings that you add to your plugin that not all users need. To keep the user interface clean and organized for the majority of users you can nest and organized fields in a variety of ways.

The simplest method is to add an options panel. Here we will add an options panel to nest the price postfix in an expandable accordion.

$my_addon->add_field( 'property_price', 'Property Price', 'text', null, 'Only digits, example: 435000' );

$my_addon->add_options(
        null,
        'Price Settings', 
        array(
                $my_addon->add_field( 'property_price_postfix', 'Price Postfix', 'text', null, 'Example: Per Month' )
        )
);

You can choose to add such an options panel attached to the price field.

$my_addon->add_options( 
        $my_addon->add_field( 'property_price', 'Property Price', 'text', null, 'Only digits, example: 435000' ),
        'Price Settings', 
        array(
                $my_addon->add_field( 'property_price_postfix', 'Price Postfix', 'text', null, 'Example: Per Month' ),
                $my_addon->add_field( 'property_price_currency', 'Currency Symbol', 'text', null, 'Example: $, or €' )
        )
);

Nested Radio Fields


You can also nest fields within the radio field. You can add as many fields as you like to the radio field’s options array.

$my_addon->add_field(
        'property_location',
        'Property Location',
        'radio', 
        array(
                'enter_address' => array(
                        'Enter Address',
                        $my_addon->add_field( 'property_address', 'Property Address', 'text' )
                ),
                'enter_coordinates' => array(
                        'Enter Coordinates',
                        $my_addon->add_field( 'property_coordinates', 'Property Coordinates', 'text' )
                ),
        )
);

No Limits


You can even get a little crazy. There is no limit to how you can combine options panels and nested radio fields.

$my_addon->add_field(
        'location_settings',
        'Property Location',
        'radio', 
        array(
                'search_by_address' => array(
                        'Search by Address',
                        $my_addon->add_options( 
                                $my_addon->add_field( 'property_address','Property Address','text' ),
                                'Google Geocode API Settings', 
                                array(
                                        $my_addon->add_field(
                                                'geocode_method',
                                                'Request Method',
                                                'radio',
                                                array(
                                                        'key_false' => array(
                                                                'No API Key',
                                                                'Limited number of requests.'
                                                        ),
                                                        'key_true' => array(
                                                                'Google Developers API Key',
                                                                $my_addon->add_field( 'api_key', 'API Key', 'text' ),
                                                                'Up to 2,500 requests per day and 5 requests per second.'
                                                        )
                                                )
                                        ) 
                                ) // end Google Geocode API Settings fields
                        ) 
                ), // end Search by Address radio field
                'enter_coordinates' => array(
                        'Enter Coordinates',
                        $my_addon->add_field( 'property_latitude', 'Latitude', 'text' ),
                        $my_addon->add_field( 'property_longitude', 'Longitude', 'text' )
                )
        )
);