0
0
Wordpressframework~10 mins

Settings API in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to register a new settings section using the Settings API.

Wordpress
add_settings_section('my_section', 'My Section Title', [1], 'my_plugin_page');
Drag options to blanks, or click blank then click option'
Anull
Bfalse
Ctrue
Dcallback_function
Attempts:
3 left
💡 Hint
Common Mistakes
Passing null or a boolean instead of a callback function.
Omitting the callback function parameter.
2fill in blank
medium

Complete the code to register a setting field with the Settings API.

Wordpress
add_settings_field('my_field', 'My Field', [1], 'my_plugin_page', 'my_section');
Drag options to blanks, or click blank then click option'
Avalidation_function
Brender_callback
Csanitize_callback
Ddisplay_callback
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing the render callback with sanitization or validation functions.
Passing a non-callable value.
3fill in blank
hard

Fix the error in the code to properly register a setting with sanitization.

Wordpress
register_setting('my_plugin_options', 'my_option_name', array('sanitize_callback' => [1]));
Drag options to blanks, or click blank then click option'
A'sanitize_text_field'
B'sanitize_option'
C'validate_text'
D'sanitize_html'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent or incorrect sanitization function names.
Confusing validation with sanitization.
4fill in blank
hard

Fill both blanks to create a settings page and add a settings section.

Wordpress
add_options_page('My Plugin Settings', 'My Plugin', [1], [2]);
Drag options to blanks, or click blank then click option'
A'manage_options'
B'edit_posts'
C'my_plugin_slug'
D'my_plugin_callback'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect capabilities like 'edit_posts' for admin settings.
Confusing the slug with the callback function.
5fill in blank
hard

Fill all three blanks to register a setting, add a section, and add a field with proper callbacks.

Wordpress
register_setting('my_group', [1], array('sanitize_callback' => [2]));
add_settings_section('my_section', 'Section Title', [3], 'my_page');
Drag options to blanks, or click blank then click option'
A'my_option_name'
B'sanitize_text_field'
C'my_section_callback'
D'my_field_callback'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up option names with callback function names.
Using invalid sanitization callbacks.