Basically to distinguish between false
boolean value and ''
empty string you must use more strict comparison operator.
var_dump( '' == false ); // this is 'true', treated like two 'empty()' values
var_dump( '' === false ); // this is 'false', because values are both 'empty()' BUT of different type
But there is more. Since what you want is very typical – get_option()
already can provide default value on its own. So your code can be simplified to:
$myOption = get_option( 'myOption', $myOption_def );
Note that this will correctly determine empty string and won’t apply default value in that case.
Related Posts:
- Update Option Error: Notice: Undefined index
- Redirect to another page using contact form 7? [closed]
- Saving an array to get_options
- add action wp_head not working
- Why is the Settings API is not saving my array of options
- Sanitizing, Validating and Escaping in WordPress (Plugin)
- Escape when echoed
- Scope for PHP Variables Assigned in functions.php or a plugin
- Plugin exceeds memory limit
- Default Plugin Settings Not Writing to Database
- Write to / remove from default .htaccess file from plugin?
- Plugin Development sqlite or WordPress’ database
- How to cancel WordPress’ action/filter when using OOP with anonymous callback
- WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page
- Serialize data for wp options
- How to trigger $_GET request within admin plugin page?
- How to generate video out of images via WordPress plugin
- How can I add an options page for my class based plugin?
- How can I get WordPress to save comments in markdown format?
- problems with wordpress and php version 5.3.3-1
- WooCommerce get_price returning wrong price when used via ajax
- How to ‘clone’ a wp plugin to make small changes
- Open Post Thumbnail in New Child Theme File in WordPress
- Where should I save an API key of my user when installing my plugin?
- Is Wrapping intval() Around esc_attr() Redundant for Escaping Input?
- Programatically download a plugin
- Redirecting to home page after login as custom role WordPress
- Add keywords meta to index.php page
- Custom form action to handle data inside a plugin
- Self deactivate plugins after an action occurs
- Pulling data from custom plugin settings using PHP shortcode and Javascript
- How to periodically scrape and cache strings from remote txt files. – My First Plugin
- WP Post Template – Templates in own folder
- Get plugin option in another PHP file
- Avoid class name collision when using third party libraries in plugins?
- wordpress plugin is not activating from widget
- Edit Yoast SEO breadcrumbs output [closed]
- How would I go about creating a user ranked post popularity page?
- How to get specific setting by settings_fields()?
- Redirection of users away from wp-admin (but not administrators)
- Using a custom plugin to capture input data via Ajax and PHP
- code is working properly in Core PHP but writing coding in WordPress
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- Add Plugin options as subpage to Theme options page
- Image upload and download from front-end
- Show admin notice on incorrect value on form field
- wp_remote_get() returns 403 while file_get_contents() does not
- How to output CMB2 select options from repeated groups select elements?
- Creating a Callback URL for WordPress Woocommerce to update Order Status
- 306 MB of wp_options occupied by WordPress SEO Plugin, is that normal? [closed]
- What are the specifics of WordPress development I need to know? [closed]
- Ajax call returning 0
- php page not found for plugin options menu
- How to deal with WordPress and Pocket API to automate content curation on my hosted wordpress blog? [closed]
- WP All Import – Execute Imports
- How to replace WordPress Media Upload Window with user’s device window?
- Conditional attributes and logic per product category
- add tabs in rdp-plugin/includes/settings.php and get settings saved
- How to create a custom post type that contains another custom post type?
- Perform internal redirect in WordPress?
- How to prevent plugins from loading jQuery
- WordPress get_avatar function not correct working
- Setup wp_schedule_event within a custom plugin
- Create a plugin from within WordPress
- Class variables not correct on page
- Why is one phpunit test throwing an error on one class when all other classes are similar without error?
- Create Array from data in the OPTIONS table
- Autoloading a PHP class – working outside, but not inside WordPress plugin
- Plugin Hook: Get posts
- Validating values using Settings API?
- Saving plugin data returns “You do not have sufficient permissions to access this page.”
- Plugin Breaking WordPress Login
- How to get site homepage from plugin?
- How to add a handler for a button in plugin?
- Can anyone tell me why I can’t edit a plugin when it is installed without having to re-install?
- Building a simple “settings” plugin to change textstrings on the home page
- Doing action based on input from options menu
- My first plugin doesn’t save the data in options
- Undefined variable _POST
- Help me with my first very basic plugin
- Load my plugin before cache
- How use Dynamic hyperlink on each wordpress post?
- Unable to show 4 products in a row
- How to fix ‘Call to undefined function do_settings()’ error?
- What is the source outline for a basic word press plugin?
- My wordpress website admin panel loads very slow, what can i do about that? [closed]
- Submit posts in two different post types with the same form
- wordpress select multiple options and illegal string offset ‘timeslot’ [closed]
- how to search through plugin in wordpress cimy-user-extra-fields?
- How to create post comparison in wordpress
- What can I do to customize a widget provided with this plugin? from where have I to start?
- How to add custom html to the Media > Attachment Details modal?
- Displaying Category Feature image on loop
- Function not being called on form submit, only blank admin-post.php page
- How to access values from your own settings page in javascript?
- wp_handle_upload – specified file failed upload test
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- How to override plugin function in code snippets WordPress