WordPress Developer 4 — Questions and Answers
Question 1: When creating a Gutenberg block, which file format defines the block's metadata including name, title, and supported features?
- block.json (Correct answer)
- block-metadata.php
- index.js
- register.json
Correct answer: block.json
block.json is the standard manifest file for Gutenberg blocks, containing all metadata and used for server-side registration.
Question 2: Which WordPress function adds a settings field to an existing settings section on an admin page?
- add_settings_field() (Correct answer)
- register_setting()
- add_settings_section()
- add_options_page()
Correct answer: add_settings_field()
add_settings_field() adds an individual form field to a section created by add_settings_section() on a settings page.
Question 3: What is the purpose of the 'save' function in a Gutenberg block's JavaScript definition?
- It defines the static HTML output stored in post_content when the block is saved (Correct answer)
- It sends block data to the WordPress REST API
- It registers the block with the block editor registry
- It validates block attributes before storing them
Correct answer: It defines the static HTML output stored in post_content when the block is saved
The save function returns the JSX/HTML that WordPress serializes into post_content, persisted in the database.
Question 4: Which PHP function in WordPress checks if the current user has a specific capability before performing an action?
- current_user_can() (Correct answer)
- user_has_capability()
- check_user_role()
- wp_check_capability()
Correct answer: current_user_can()
current_user_can() checks whether the currently logged-in user has the specified capability or role.
Question 5: In multisite WordPress, which function checks whether the current site is the main/primary site of the network?
- is_main_site() (Correct answer)
- is_primary_site()
- is_network_home()
- is_root_site()
Correct answer: is_main_site()
is_main_site() returns true when the current site is the main site of a WordPress multisite network.
Question 6: What does the 'transient' API in WordPress primarily use for storage by default?
- The WordPress options table in the database (Correct answer)
- A flat file cache on the server filesystem
- Redis memory store
- Browser localStorage via JavaScript
Correct answer: The WordPress options table in the database
WordPress transients are stored in the wp_options table by default, but can use external object caches like Redis if configured.
Question 7: Which WordPress action hook is the recommended place to run code that requires the WordPress environment but should run as early as possible?
- init (Correct answer)
- plugins_loaded
- wp
- template_redirect
Correct answer: init
The 'init' hook fires after WordPress is fully loaded and is the standard place for registering post types, taxonomies, and most initialization code.
When creating a Gutenberg block, which file format defines the block's metadata including name, title, and supported features?