1

So I want to have defaults set up for each of my plugins settings, and I'm using wp_parse_args to do so which I believe is the correct way, but I'm hitting a roadblock.

Here's my code at the moment:

function eddslider_options_each( $edd_slider_options ) {

$edd_slider_options = get_option( 'eddslider_options' );

/**
 * Define the array of defaults
 */ 
$defaults = array(
    'slider_insert'     => 0,
    'slider_arrows'     => 0,
    'slider_bullets'    => 0,
    'slider_effect'     => 'fade',
    'slider_theme'      => 'default'
);
/**
 *  Parse incomming $args into an array and merge it with $defaults
 */ 
$edd_slider_options = wp_parse_args( $edd_slider_options, $defaults );

/**
 * OPTIONAL: Declare each item in $args as its own variable i.e. $type, $before.
 */ 
extract( $edd_slider_options, EXTR_SKIP );

}

Now if I add something like:

$output = $slider_insert;
return $output;

I'm able to use <?php echo eddslider_options_each('slider_insert'); ?> and it will have the defined default set and work well. How do I do this for every option though? Thank you.

1 Answer 1

2

Try:

function eddslider_options_each( $key ) {

    $edd_slider_options = get_option( 'eddslider_options' );

     /* Define the array of defaults */ 
    $defaults = array(
        'slider_insert'     => 0,
        'slider_arrows'     => 0,
        'slider_bullets'    => 0,
        'slider_effect'     => 'fade',
        'slider_theme'      => 'default'
    );

    $edd_slider_options = wp_parse_args( $edd_slider_options, $defaults );

    if( isset($edd_slider_options[$key]) )
         return $edd_slider_options[$key];

    return false;
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.