Function: swp_add_option_after()

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

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 easily add or remove options from the middle of existing option page tabs.

In some instances, you may not want to create a whole new options tab for your plugins functionality. For example, if you want to add a new social network button, you will most likely want to add the on/off toggle for that button right next to the on/off toggles for all the other buttons. The example below shows how you can search for an existing option on an existing tab and place your option array immediately after it on the same page.

Note: This function must be called inside of an add_filter: swp_options hook.

Example Usage

add_filter('swp_options', 'swp_options_function',10);
function swp_options_function($swp_options) {

    // Create the new option in a variable to be inserted
    $reddit = array(
        'reddit' => array(
             'type' => 'checkbox',
             'content' => 'Reddit',
             'default' => 1
        )
    );
 
    // Call the swp_add_option_after() function
    return swp_add_option_after($swp_options,'displaySettings','facebook',$reddit);

};

Parameters

$swp_options
(array)(required) You must pass the swp_options array into the function. For more information about this array and the filter that passes this array into your function, see this article: swp_options.

$tabName
(string)(required) The key in the swp_options array that corresponds to the options page tab into which you want to insert your new options content.

$optionName
(string)(required) The key in the swp_options array that corresponds to the existing option after which you want to insert your new options content.

$newOptionsArray
(array)(required) An array containing the necessary information to construct a new option

Was this article helpful?

Related Articles