0
0
Wordpressframework~20 mins

Options API for site-wide settings in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Options API Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does this code output when retrieving an option?
Consider this WordPress code snippet that retrieves a site-wide setting using the Options API. What will be the output of echo $site_name; if the option 'site_name' was previously saved as 'My Cool Site'?
Wordpress
<?php
$site_name = get_option('site_name', 'Default Site');
echo $site_name;
?>
AMy Cool Site
BDefault Site
Csite_name
DNULL
Attempts:
2 left
💡 Hint
Think about what get_option returns when the option exists.
📝 Syntax
intermediate
2:00remaining
Which option correctly updates a site-wide option?
You want to update the option 'homepage_message' to 'Welcome!' using the Options API. Which code snippet correctly performs this update?
Aupdate_option('homepage_message', 'Welcome!');
Bsave_option('homepage_message', 'Welcome!');
Cset_option('homepage_message', 'Welcome!');
Dput_option('homepage_message', 'Welcome!');
Attempts:
2 left
💡 Hint
Check the official function name for updating options.
🔧 Debug
advanced
2:00remaining
Why does this code fail to save the option?
This code tries to save a new option but it does not work as expected. What is the reason?
Wordpress
<?php
add_option('footer_text', 'Thank you for visiting!');
add_option('footer_text', 'New footer text');
?>
Aadd_option must be called inside a function hooked to init
Badd_option requires a third parameter for autoload, missing here
Cadd_option cannot save strings, only arrays
Dadd_option only adds if the option does not exist; second call fails silently
Attempts:
2 left
💡 Hint
Think about what happens if you try to add an option that already exists.
state_output
advanced
2:00remaining
What is the value of $result after this code runs?
Given this code snippet, what will be the value of $result?
Wordpress
<?php
update_option('color_scheme', 'dark');
$result = get_option('color_scheme', 'light');
?>
ANULL
B'light'
C'dark'
Dfalse
Attempts:
2 left
💡 Hint
Remember what update_option does and what get_option returns.
🧠 Conceptual
expert
2:00remaining
Which statement about the Options API is TRUE?
Select the correct statement about the WordPress Options API for site-wide settings.
AOptions API can only store numeric values, not strings or arrays.
BOptions API stores data in the wp_options table and is best for small pieces of data.
COptions API requires manual database queries to retrieve options.
DOptions API automatically encrypts all stored options for security.
Attempts:
2 left
💡 Hint
Think about where WordPress stores options and what kind of data it handles.