Challenge - 5 Problems
WordPress Settings Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this WordPress settings retrieval code?
Consider this code snippet that reads a setting from the WordPress options table:
Assuming the option 'my_plugin_setting' is not set in the database, what will be printed?
$value = get_option('my_plugin_setting', 'default');
echo $value;Assuming the option 'my_plugin_setting' is not set in the database, what will be printed?
Wordpress
$value = get_option('my_plugin_setting', 'default'); echo $value;
Attempts:
2 left
💡 Hint
Check what the second parameter of get_option does.
✗ Incorrect
The second parameter of get_option is the default value returned if the option does not exist. Here, it returns 'default'.
❓ state_output
intermediate2:00remaining
What is the value of the option after this code runs?
Given this code snippet:
What will be the output?
update_option('my_plugin_setting', 'blue');
update_option('my_plugin_setting', 'red');
$color = get_option('my_plugin_setting');
echo $color;What will be the output?
Wordpress
update_option('my_plugin_setting', 'blue'); update_option('my_plugin_setting', 'red'); $color = get_option('my_plugin_setting'); echo $color;
Attempts:
2 left
💡 Hint
Think about what update_option does when called twice with the same key.
✗ Incorrect
update_option overwrites the existing option value. The last call sets it to 'red'.
📝 Syntax
advanced2:00remaining
Which option causes a syntax error when saving settings?
Which of the following code snippets will cause a syntax error when trying to save a setting in WordPress?
Attempts:
2 left
💡 Hint
Look carefully at the commas between function arguments.
✗ Incorrect
Option C is missing a comma between the two arguments, causing a syntax error.
🔧 Debug
advanced2:00remaining
Why does this code fail to save the setting?
This code tries to save a setting but it does not persist:
What is the reason?
$setting = 'dark_mode';
update_option($setting, true);
if(get_option('darkmode')) {
echo 'Enabled';
} else {
echo 'Disabled';
}
What is the reason?
Wordpress
$setting = 'dark_mode'; update_option($setting, true); if(get_option('darkmode')) { echo 'Enabled'; } else { echo 'Disabled'; }
Attempts:
2 left
💡 Hint
Check the option names used in update_option and get_option calls.
✗ Incorrect
update_option saves the value under the option name 'dark_mode' (from $setting), but get_option('darkmode') checks a different name without the underscore. Thus, get_option returns a falsey value (empty string or false), causing 'Disabled' to be printed, making it seem like the setting wasn't saved.
🧠 Conceptual
expert3:00remaining
Which option best describes how WordPress stores settings saved with update_option?
When you use update_option('my_setting', $value) in WordPress, how is the data stored internally?
Attempts:
2 left
💡 Hint
Think about where WordPress stores options by default.
✗ Incorrect
WordPress stores options in the wp_options database table. Complex data types are serialized before storage.