Alchemy Options Docs
v1.0
v1.0
  • Read Me
  • Installation
  • Configuration
  • Meta Boxes
  • Samples
  • Field types
    • Text
    • Password
    • URL
    • Email
    • Tel
    • Textarea
    • Editor (WYSIWYG)
    • Datepicker
    • Image upload
    • Radio buttons
    • Select
    • Checkbox
    • Colorpicker
    • Image radio
    • Post type select
    • Datalist
    • Sections
    • Repeater
    • Button group
    • Slider
    • Taxonomy select
    • Field group
  • Functions
    • alch_options_id
    • alch_network_options_id
    • alch_get_option
    • alch_get_network_option
    • alch_delete_value
    • alch_get_post_meta
  • Javascript
    • getOption
    • getNetworkOption
    • getPostMeta
  • Filters
    • alch_options_id
    • alch_default_page_capabilities
    • alch_default_page_icon
    • alch_default_page_position
    • alch_network_options_id
    • alch_options_id() . '_args'
    • alch_network_options_id() . '_args'
    • alch_allowed_editor_html_tags
    • alch_allowed_editor_protocols
    • alch_{ $optionsPageID }_capabilities
    • alch_{ $optionsPageID }_icon
    • alch_{ $optionsPageID }_position
    • alch_value_{ $optionID }
    • alch_network_value_{ $optionID }
Powered by GitBook
On this page
  • Creating option pages
  • Creating option pages with subpages
  • Adding options to option pages
  • Grouping

Configuration

PreviousInstallationNextMeta Boxes

Last updated 2 years ago

Make sure you have Alchemy Options .

Creating option pages

To create an Alchemy Options option page use the alch_options_pages hook:

function add_custom_options_pages( $pages ) {
    $myPages = array(
        array(
            'id' => 'my-options-page',
            'name' => 'My options page',
        )
    );

    return array_merge( $pages, $myPages );
}

add_filter( 'alch_options_pages', 'add_custom_options_pages' );

This will add an options page to the WordPress sidebar.

Creating option pages with subpages

An Alchemy Options option page can have subpages, you can specify them in the subpages array like so:

function add_custom_options_pages( $pages ) {
    $myPages = array(
        array(
            'id' => 'my-options-page',
            'name' => 'My options page',
            'subpages' => array(
                array(
                    'id' => 'my-options-subpage',
                    'name' => 'My options subpage',
                ),
            ),
        )
    );

    return array_merge( $pages, $myPages );
}

add_filter( 'alch_options_pages', 'add_custom_options_pages' );

This adds an options page with a subpage to the WordPress sidebar.

By default, the top-level page gets duplicated as a subpage producing 2 identical page titles. You can modify them like so:

function add_custom_options_pages( $pages ) {
    $myPages = array(
        array(
            'id' => 'my-options-page',
            'name' => 'My options page',
            'subpages' => array(
                array(
                    'id' => 'my-options-page',
                    'name' => 'General',
                ),
                array(
                    'id' => 'my-options-subpage',
                    'name' => 'My options subpage',
                ),
            ),
        )
    );

    return array_merge( $pages, $myPages );
}

add_filter( 'alch_options_pages', 'add_custom_options_pages' );

This will produce nicer page names without title duplication.

Notice that in order for it to work the top-level and subpage ids should be the same.

Adding options to option pages

To add options to Alchemy Options option pages use the alch_options hook:

function add_custom_options( $options ) {
    $myOptions = array(
        /* options will go here */
    );

    return array_merge( $options, $myOptions );
}

add_filter( 'alch_options', 'add_custom_options' );

Grouping

If there's a need to split options into several groups, Alchemy Options has got you covered. You may add the tabs section to the config that looks like this:

...
'tabs' => array(
    array(
        'id' => 'tab-1',
        'name' => 'Name'
    ),
    array(
        'id' => 'tab-2',
        'name' => 'Name 2'
    ),
)
...

IDs of the tabs should be unique, these values will be used in configuring of each option with the tab key. If no tab key is found in the option's settings it will be rendered in each tab.

By default, top-level pages are added after the Appearance section, but you can filter the page , as well as its and via respective hooks.

That's it, just add instead of /* options will go here */ and see them appear on the page.

If there's a need to split options even further, there's a type for visual splitting of fields into togglable sections and a type to group related fields together for an easier .

position
capabilities
icon
some options
sections
field-group
value retrieval
installed