-
-
Notifications
You must be signed in to change notification settings - Fork 0
Docs Understanding Options
One of the main features of the framework is the easy creation of options in the admin. Options can be added to admin pages, meta boxes or the theme customer. The code to insert an option into these areas are all the same.
An option can be inserted by using the function createOption( $settingsArray )
. For example:
$areaToPlaceTheOption->createOption( array(
'name' => 'Name', // The name label of the option
'id' => 'option_id', // The ID of the option, this is used to get the saved value
'type' => 'text', // The type of the option
'default' => 'default value',
'desc' => 'A description' // A description shown near the option
) );
In the code above, the variable $areaToPlaceTheOption
corresponds to an admin page, meta box or theme customiser section object created earlier.
The arguments name
, id
, type
, default
, and desc
are common arguments to all the available options. Some options may have additional arguments available for them. For example, the select drop down option has an additional setting called options
which can be used to add an array of choices for the drop down option.
NOTE: Refer to the documentation for the complete list of all the options and their settings.
Getting saved values differ (only slightly) depending on where the option is placed. If the option is in an admin page or the theme customizer, you can get the value with this:
echo $titan->getOption( 'option_id' );
Meta box options on the other hand, are tied to the post they belong to. While inside a loop, you can get the option value by specifying the post ID in the function call:
echo $titan->getOption( 'option_id', get_the_ID() );
NOTE: Make sure you only perform your
getOption
calls from inside WordPress hooks and filters, or inside your theme template files. If the function is called earlier – for example, within the first lines in yourfunctions.php
– the framework might not have initialized yet.
Ajax Button Checkbox Code Color Custom Date EDD License Editor Enable File Upload Font Gallery Heading Iframe Multicheck Multicheck Categories Multicheck Pages Multicheck Post-Types Multicheck Posts Note Number Radio Radio Image Radio Palette Save Select Select Categories Select Pages Select Post-Types Select Posts Select Users Sortable Text Textarea Upload