The logic on the IF THEN ELSE does seem a bit wonky. If I’m reading it correctly…
The call to get_option( $option_name ) will return FALSE if the option does not exist or if it has no value.
So the IF would be executed:
- when the option doesn’t exist and $new_value != FALSE
- the option has no value and $new_value != FALSE
- the option exists and has a value that is != $new value
The update_option() call would then update the value or create the option with $new_value.
The ELSE would be called if:
- the option exists and has the same value as $new_value
- the option does not exist and the $new_value == FALSE
Related Posts:
- Is the codex no longer actively maintained?
- Why is the use of @uses tag in docblocks discouraged?
- What does the raw value for the get_bloginfo’s filter argument exactly do?
- *Just curious* I erroneously used hook add_action() instead of add_filter() and there was no error and the result was correct. Why is that?
- WordPress Codex has different number of arguments for get_previous_post and get_next_post functions. Why?
- WordPress Codex or equivlent for Kindle use?
- Set $options reference
- Difference between `is_serialized_string` and `is_serialized`
- Wp Super Cache – Function to reset cache of a specific page
- What is the significance of _e(“Some String”, ‘String’)?
- Using Json Schema with wordpress codex
- adding category and tags to admin plugins menu
- How to disable Wp-Page Navigation on Blank Search in WordPress
- Cleanup orphaned wp_terms and wp_term_taxonomy
- Where to find new class reference or function of deprecated one?
- how do i add customizer edit option without plugin in wp
- Next/Previous Url only
- What is the reason to use function strings for callbacks
- How to show all columns’ names on a large pandas dataframe?
- GCC -fPIC option
- How to print the full NumPy array, without truncation?
- Upgrade 4.5.2 to 4.5.3 deleting row in wp_options table
- Is there a flowchart for WordPress loading sequence?
- Are transients garbage collected?
- Get page ID of page that is set as the posts page
- How to get WordPress Time Zone setting?
- framework for plugin/theme options panel? [closed]
- How to get the Date Format and Time Format settings for use in my template?
- Add multiple custom fields to the general settings page
- How do I add CSS options to my plugin without using inline styles?
- Are all options loaded to memory on each request?
- ‘Global’ settings page for multisite plugin
- How does object caching work?
- numberposts? showposts? posts_per_page?
- “Error: Options Page Not Found” on Settings Page Submission for an OOP Plugin
- How to pass arguments from add_settings_field() to the callback function?
- How to use checkbox and radio button in options page?
- how to update serialized options programatically?
- get_option() vs get_theme_mod(): Why is one slower?
- Slow Query for the wp_options table
- How to add Custom Blog Options to new blog setup form?
- Is get_option function cached?
- Will it break my site if I delete all transient records in wp_options table?
- Upload Multiple Files With media_handle_upload
- How to pass variable to add_settings_section() callback?
- How come `wp_options` table does not have an index on `autoload`?
- How to add field for new site-wide option on Network Settings screen?
- Update Option Stored in Multi-Dimensional Array
- Contact form 7 select box different value-text than content-text in option [closed]
- Alternative to query_posts for main loop? [duplicate]
- Performance with autoload and the options table
- Where, When, & How to Properly Flush Rewrite Rules Within the Scope of a Plugin?
- What’s the difference between Options & Settings?
- Using widget options ‘outside’ the widget
- Please explain how WordPress works with MySQL character set and collation at a low level
- What are the advantages to the Settings API?
- Is There a Plugin Life Cycle Documentation?
- What does is_page_template() compare against?
- How to load WordPress on non WP page?
- From a security standpoint, should bloginfo() or get_bloginfo() be escaped?
- Where to securely store API keys and passwords in WordPress?
- Adding Widget form fields dynamically
- Where to store plugin settings fields
- Enable page templates. How?
- How to store widget fields data as an array?
- Using jQuery to delete data stored in wp_options
- Limit the number of inactive widgets
- Is get_option() faster than accessing get_transient()?
- This CSS Stuffing Works, But Is This A Good Practice?
- Modifying a JS file with data from plugin settings
- Add update notification bubble to admin menu item?
- Options for CDN with WordPress Including Supporting Plugins?
- Issues enqueueing parent & child theme stylesheets with revised Codex method
- Option to set static front page disappeared from admin reading settings
- Using get_option() in JavaScript
- WordPress Settings API, Implementing Tabs On Custom Menu Page
- Plugin for editing options on multisite?
- How to set up default values for a plugin?
- What is the purpose of the option name hack_file in the options table?
- Prevent/Disable Automatic Update Check
- Difference between Option_Group and Option_Name in Register_Settings
- How To Add New Option Types To Option Tree?
- How to display admin error notice if settings saved succesfully?
- Best practices for a Style/CSS based theme options page?
- Add on the fly tabs to plugin options
- Why does WordPress use serialize rather than json_encode for the options table? [duplicate]
- Plugin options will not save in database
- What’s the best method for emptying an option created with the Settings API?
- Correct way to serialize the data of options table?
- Releasing new plugin version, how to rename old options keys?
- Is it safe to store a user setting you don’t want the user to ever modify as a user option?
- WordPress updates defined vs add_filter?
- Settings API – easiest way of validating checkboxes?
- Creating Settings Page with dropdowns for Plugin
- Custom plugin: Trying to show saved data on frontend
- No option to allow search engines to index my site in WP 4.3
- Different number of posts in each category
- How to update an ‘array’ option using wp-cli [duplicate]
- How to properly sanitize strings for update_option()
- Plugin options autoloading