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?
Leave a Reply
You must be logged in to post a comment.
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 storeoption_name = 'var_name'
andoption_value = 'value'
.add_option()
is used only when saving a value for the first time. Has anautoload
parameter.get_option(): Retrieve that value. Example:
get_option('var_name')
will return the stringvalue
.update_option(). Will update the value of an option. Can also be used instead of
add_option()
, but it lacks theautoload
parameter.As for serializing data, WordPress will do it automatically if you use the above options with an array.
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 ofadd_appearance_page()
.More specific answers would require a more specific question.