Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upon Plugin Activation Save Default Settings #6

Closed
DevinWalker opened this issue Mar 18, 2015 · 5 comments
Closed

Upon Plugin Activation Save Default Settings #6

DevinWalker opened this issue Mar 18, 2015 · 5 comments

Comments

@DevinWalker
Copy link
Contributor

We are using CMB2 to create a tabbed plugin admin panel. When a new user installs and activates the plugin they have to manually save the options before they are stored in the database. Do you know of a quick way to save default values so they are immediately available post installation?

@DevinWalker
Copy link
Contributor Author

LMK if this issue is more appropriate in CMB2 core

@dustyf
Copy link

dustyf commented Mar 18, 2015

You should be able to use the register_activation_hook function (http://codex.wordpress.org/Function_Reference/register_activation_hook) to perform actions on the activation of your plugin. Run update_option here and save values under the meta keys you use for your fields and they will be available once the plugin is activated.

@DevinWalker
Copy link
Contributor Author

I figured as much, the issue though is how to exactly do this... I'm guessing two foreach loops like so:

// Populate some default values
    $give_settings = new Give_Plugin_Settings();
    foreach ( $give_settings->give_settings( null ) as $tab => $settings ) {

        foreach ( $settings as $option ) {

            if ( isset( $option['default'] ) ) {

                $options[ $option['id'] ] = $option['default'];
            }

        }

    }

    update_option( 'give_settings', array_merge( $give_options, $options ) );

I'm having trouble getting to work though...

@jtsternberg
Copy link
Member

This question is quite a bit out of scope for this project. Also, your example assumes we know what Give_Plugin_Settings is, what give_settings outputs, where $give_options is coming from and what hook this is happening on.

@DevinWalker
Copy link
Contributor Author

I agree it's a bit of a strange issue and I haven't provided too much context. Let me poke around a bit more on this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants