B. Nothing happens because the callback function is missing
C. A new top-level menu named 'My Plugin' appears in admin, showing 'Hello Admin!' when clicked
D. The menu appears but clicking it shows a blank page
Solution
Step 1: Analyze the add_menu_page parameters
The code adds a menu titled 'My Plugin' with capability 'manage_options' and a callback that echoes 'Hello Admin!'.
Step 2: Understand the callback behavior
When the menu is clicked, the callback runs and outputs 'Hello Admin!'. No errors occur because capability and callback are valid.
Final Answer:
A new top-level menu named 'My Plugin' appears in admin, showing 'Hello Admin!' when clicked -> Option C
Quick Check:
Valid add_menu_page with callback shows output [OK]
Hint: Callback echoes content on menu page click [OK]
Common Mistakes:
Assuming callback is missing
Confusing capability with missing parameter
Expecting blank page without callback
4. Identify the error in this code snippet:
add_action('admin_menu', 'register_my_menu');
function register_my_menu() {
add_menu_page('Sample', 'Sample', 'manage_options');
}
medium
A. Callback function is missing but required
B. Missing menu slug parameter in add_menu_page
C. Capability 'manage_options' is invalid
D. Wrong hook used for adding menu page
Solution
Step 1: Check add_menu_page parameters
The function call has only three parameters: page title, menu title, and capability.
Step 2: Verify required parameters
The menu slug parameter is missing, which is required as the fourth argument.
Final Answer:
Missing menu slug parameter in add_menu_page -> Option B
Quick Check:
add_menu_page needs menu slug [OK]
Hint: add_menu_page needs 4+ parameters including slug [OK]
Common Mistakes:
Forgetting the menu slug argument
Assuming callback is mandatory (optional)
Using wrong hook instead of admin_menu
5. You want to add a top-level admin menu page visible only to users who can edit posts, with the menu slug 'custom-editor'. Which code snippet correctly achieves this?