Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am new to wordpress and learning to create plugins. I want to know how wordpress itself create options in 'wp_options' table for plugin during plugin installation or activation? How wordpress decide about these option values, which is sometimes serialized data?

share|improve this question

2 Answers 2

There are some functions associated with manipulating the variables found in the wp_options table.

add_option(): Create a new value in the table. Example add_option('var_name', 'value') will store option_name = 'var_name' and option_value = 'value'. add_option() is used only when saving a value for the first time. Has an autoload parameter.

get_option(): Retrieve that value. Example: get_option('var_name') will return the string value.

update_option(). Will update the value of an option. Can also be used instead of add_option(), but it lacks the autoload parameter.

As for serializing data, Wordpress will do it automatically if you use the above options with an array.

share|improve this answer

WordPress includes a Settings API, that handles all aspects of registering and updating options. I would strongly recommend using the Settings API rather than using add_option()/update_option() directly.

I've written a tutorial on implementing the Settings API in Themes; Plugins would be almost identical, except they would use add_options_page() instead of add_appearance_page().

More specific answers would require a more specific question.

share|improve this answer
    
Sir, thanks for your reply. –  user24726 Dec 13 '12 at 4:52
    
Sir, thanks for your reply. My specific question is, when I created one small plugin 'The Wall' given in book 'WordPress Plugin Development Beginner's Guide' by 'Vladimir Prelovac' and activated it, I found 'wp_wall' option get created in 'wp_options' table. I want to know, how wordpress created this option itself and how it decide about content of 'wp_wall' option? –  user24726 Dec 13 '12 at 4:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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