WordPress.org

Ready to get started?Download WordPress

Forums

Settings in plugin. (5 posts)

  1. Loueen
    Member
    Posted 1 year ago #

    If I have to save some settings, will I have to create a new tabele, or can I save the setting by any function in wp_options?

    Thank you !

  2. Chris
    Member
    Posted 1 year ago #

    wp_options, respectively all functions like add_option(), delete_option(), update_option(), etc are suited also for plugin settings.

    I would also recommend organizing all settings for a plugin in a single array and only store this one in the wp options. This way you will get all settings with only one query, even when using get_option();
    And it's also easier to keep track of it when you want to uninstall the plugin and therefore delete the settings.

  3. michael.mariart
    Member
    Posted 1 year ago #

    You don't need to do any of that to save the widgets values, and that's actually the wrong way to save the values. The functions like update_option() are meant for system-wide values, not individual values for widgets.

    Raed the Widgets API page and look at the update() function. That is what stores the widgets values with no other code needed and no extra DB tables (unless you're doing something special).

  4. Chris
    Member
    Posted 1 year ago #

    Loueen was talking about plugins, not widgets in particular. And since you can specify if an option shall be loaded automatically or manually I think the option functions are just fine.

  5. michael.mariart
    Member
    Posted 1 year ago #

    Oops... Yes that is right. I must have been looking at something else at the same time and gotten confused.

    The *_option() functions are the way to store basic settings. If there's a huge range of info that needs to be saved you can add in DB tables if the complexity of the data warrents it, but that's completely up to exactly what you want to store.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.