Function: swp_get_single_option()

  1. Home
  2. Knowledge Base
  3. Developers
  4. Function: swp_get_single_option()

Not the solution you were looking for?

Click the link below to submit a support ticket. If you are a Social Warfare - Pro license holder, you can log into your Account page to submit a ticket.
Submit Ticket

Description

This function allows you to fetch a single option value that the user has set on the options pages. It will be returned as a single value, unless calling a ‘sortable’ option field, in which case it will return an array sorted in the order that the user has placed them.

Example Usage

if(swp_get_single_option('some_checkbox_option') == true):
    
    // Do something cool since the checkbox was checked

endif;

Parameters

This function accepts one required value.

$key
(string)(required) The key associated with the option of which you wish to receive the value.

Return

The function returns a value for a single option in a format much like this example. However, to see the real values, you’ll want to run a var_dump() prior to utilizing the data.

// A checkbox value
bool(true)

// A textbox value
string(17) "User's Text Input"

// A select value
string(11) "choicethree"

// A color picker value
string(7) "#ffffff"

// A sortable value
array(4) {
    ["trueLove"]=>
    string(9) "True Love"
    ["rhymingIMeanIt"]=>
    string(17) "Rhyming I mean it"
    ["toBlave"]=>
    string(8) "To Blave"
    ["revenge"]=>
    string(7) "Revenge"
}

Was this article helpful?

Related Articles