In the previous post, I alluded to a place to store options (basically, any arbitrary data) in the database. Plugin developers shouldn’t try to access that data directly; we’ve got an API for you.

bb_get_option( $option_name )

This one function grabs data from all the different places bbPress uses to store such data: hardcoded data, “softcoded” data, and data stored in the database.

First, the function checks to see if $option_name corresponds to some hardcoded value like version, language, or text-direction. If $option_name doesn’t match an hardcoded value, it looks to see if it matches what I call a “softcoded” value. These are the names of the options stored in the global $bb variable such as domain, path, akismet_key and so forth. Finally, if it still hasn’t found anything, it queries the database for $option_name.

It returns the value of the option filtered through the filter bb_get_option_{$option_name}. (So if you asked for the option named “blue”, you could filter the results with the bb_get_option_blue filter.)

bb_get_option_from_db( $option_name )

If you want to bypass all the hardcoded and softcoded data queries that bb_get_option() performs and go straight to the database, use this function. Its results are filtered through bb_get_option_from_db_{$option_name}. In conjunction with the bb_get_option_{} filter, a plugin could use this function to override softcoded data with data from the database.

NOTE: bb_get_option() calls bb_get_option_from_db() when it decides to grab data from the database. So both bb_get_option_{$option_name} and bb_get_option_from_db_{$option_name} may be run on the same result.

bb_update_option( $option_name, $value )

Updates (or adds) the option named $option_name with value $value to the database. You can store any type of variable except NULL.

NOTE: Option names are unique in bbPress.

bb_delete_option( $option_name, $value = '' )

Deletes the option from the database. If you want a sanity check, you may include the value of the option. $value has no other use here, however, since option names are unique; bb_delete_option( $option_name ) works just fine.

bb_cache_all_options()

Options are not loaded into cache by default when bbPress starts up. Each option is cached only after it is queried for the first time; if you grab several options from the database, you will query the database once for each option. This function caches all options from the database in one large query. You may find it increases performance for some applications.