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
  • Example usage
  • Note on passing non-existent IDs
  • Params
  1. Javascript

getNetworkOption

PreviousgetOptionNextgetPostMeta

Last updated 6 years ago

Function getNetworkOption is similar to . It allows you to get the saved value of a network option. Uses as a promises polyfill.

Enqueue a script and . This will give you the global alchemyOptions variable.

For server-side use .

Example usage

alchemyOptions
    .getNetworkOption('my-network-option-id')
    .then(value => {
        //value is a JSON string like {"success":true,"data":42}
    });

getNetworkOption returns the kew defer, so you can deal with the promise later.

const myOption = alchemyOptions.getNetworkOption('my-network-option-id');

//later in the code
myOption.promise.then(value => {
    // do something with the value
});

If for some reason getNetworkOption fails, you can deal with it in the fail method. It can happen if the AJAX request errored or was aborted.

alchemyOptions
    .getNetworkOption('my-network-option')
    .then(value => {
        // value is a JSON string like {"success":true,"data":42}
    })
    .fail(response => {
        // failed to get the value
    });

Note on passing non-existent IDs

Most of the time getNetworkOption will be successful, even if you pass non-existent ID to it. Consider the following example:

alchemyOptions
    .getNetworkOption('some-non-existent-option')
    .then(value => {
        // value is a JSON string like {"success":true,"data":""}
    })

If you pass the option ID that doesn't exist, the call will still be successful, the data property will be an empty string.

Params

Name

Type

Description

id

string

Unique ID that will be used to retrieve the value (required)

More info on how to use promises can be found in the .

getOption
kew
add alchemy-options-client-scripts as its dependency
alch_get_network_option
kew documentation