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.
$this->add_on->add_field( 'property_price', 'Property Price', 'text', null, 'Only digits, example: 435000' );
$this->add_on->add_options(
null,
'Price Settings',
array(
$this->add_on->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.
$this->add_on->add_options(
$this->add_on->add_field( 'property_price', 'Property Price', 'text', null, 'Only digits, example: 435000' ),
'Price Settings',
array(
$this->add_on->add_field( 'property_price_postfix', 'Price Postfix', 'text', null, 'Example: Per Month' ),
$this->add_on->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.
$this->add_on->add_field(
'property_location',
'Property Location',
'radio',
array(
'enter_address' => array(
'Enter Address',
$this->add_on->add_field( 'property_address', 'Property Address', 'text' )
),
'enter_coordinates' => array(
'Enter Coordinates',
$this->add_on->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.
$this->add_on->add_field(
'location_settings',
'Property Location',
'radio',
array(
'search_by_address' => array(
'Search by Address',
$this->add_on->add_options(
$this->add_on->add_field( 'property_address','Property Address','text' ),
'Google Geocode API Settings',
array(
$this->add_on->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',
$this->add_on->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',
$this->add_on->add_field( 'property_latitude', 'Latitude', 'text' ),
$this->add_on->add_field( 'property_longitude', 'Longitude', 'text' )
)
)
);
Related
Add-On Structure
Text Fields
Radio Fields
Image Fields