Bird
0
0

You want to create a settings page that saves a user preference 'display_mode'. Which sequence correctly saves and retrieves this setting?

hard📝 Application Q8 of 15
Wordpress - WordPress Settings and Configuration
You want to create a settings page that saves a user preference 'display_mode'. Which sequence correctly saves and retrieves this setting?
AUse add_option('display_mode', value), then register_setting(), then get_option('display_mode')
BUse register_setting(), then update_option('display_mode', value), then get_option('display_mode')
CUse get_option('display_mode'), then update_option('display_mode', value), then register_setting()
DUse update_option('display_mode', value), then add_option('display_mode', value), then get_option('display_mode')
Step-by-Step Solution
Solution:
  1. Step 1: Register setting for settings API

    register_setting() prepares the setting for the settings page.
  2. Step 2: Save user preference with update_option()

    update_option() saves or updates the value in the database.
  3. Step 3: Retrieve saved value with get_option()

    get_option() reads the saved value for use.
  4. Final Answer:

    Use register_setting(), then update_option('display_mode', value), then get_option('display_mode') -> Option B
  5. Quick Check:

    Register, update, then get for settings [OK]
Quick Trick: Register setting first, then update and get option [OK]
Common Mistakes:
  • Calling add_option() after update_option()
  • Getting option before registering setting
  • Skipping register_setting() for settings page

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes