How can I have default values for options for a WordPress Plugin?

Or how can I populate wordpress database with default plugin values, add option doesnt works for me, like http://codex.wordpress.org/Function_Reference/add_option

I am sure my syntax is correct, what I want is, when the user goes to the settings menu of my plugin, he/she doesn’t see the blank input field, rather see it filled with default data.

Related posts

Leave a Reply

3 comments

  1. If you store plugin settings in an array like I do, passing defaults to get_option won’t be enough if you change your settings in the future or add new keys to the array because the database value already exists and you defaults won’t be loaded. Instead you could use a mix of get_option and wp_parse_args

    For example check this bit of code:

        $defaults = array(
            'wsi_license_key'   => '',
        );
        $settings = wp_parse_args( get_option( 'wsi_settings', $defaults), $defaults );