Challenge - 5 Problems
WordPress Plugin Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when a WordPress plugin with this header is activated?
Consider this plugin header in a PHP file placed in the WordPress plugins folder. What will WordPress do when this plugin is activated?
/*
Plugin Name: Simple Logger
Description: Logs a message on activation.
Version: 1.0
Author: Dev
*/
register_activation_hook(__FILE__, function() {
error_log('Simple Logger activated');
});Wordpress
/* Plugin Name: Simple Logger Description: Logs a message on activation. Version: 1.0 Author: Dev */ register_activation_hook(__FILE__, function() { error_log('Simple Logger activated'); });
Attempts:
2 left
💡 Hint
Think about what register_activation_hook does and where it runs.
✗ Incorrect
The register_activation_hook function registers a callback that runs only once when the plugin is activated. Here, it writes a message to the PHP error log. It does not display messages in the admin dashboard automatically.
📝 Syntax
intermediate1:30remaining
Identify the correct plugin header syntax
Which of the following plugin headers is correctly formatted so WordPress recognizes it as a valid plugin?
Attempts:
2 left
💡 Hint
WordPress plugin headers must be inside a PHP comment block at the top of the main plugin file.
✗ Incorrect
WordPress expects the plugin header inside a PHP block comment (/* ... */) at the top of the plugin file. Other comment styles or HTML comments are not recognized.
🔧 Debug
advanced2:30remaining
Why does this activation hook not run?
A developer wrote this plugin code but the activation hook never runs. Why?
/*
Plugin Name: Test Plugin
*/
function activate_test_plugin() {
error_log('Activated');
}
register_activation_hook('test-plugin.php', 'activate_test_plugin');Wordpress
/* Plugin Name: Test Plugin */ function activate_test_plugin() { error_log('Activated'); } register_activation_hook('test-plugin.php', 'activate_test_plugin');
Attempts:
2 left
💡 Hint
Check the first argument of register_activation_hook carefully.
✗ Incorrect
register_activation_hook requires the full path to the main plugin file, which is best provided by __FILE__. Passing just the filename string will not work because WordPress cannot locate the file.
❓ state_output
advanced2:00remaining
What is the output after plugin activation and deactivation?
Given this plugin code, what will be logged after activating and then deactivating the plugin?
/*
Plugin Name: Logger Plugin
*/
register_activation_hook(__FILE__, function() {
error_log('Plugin activated');
});
register_deactivation_hook(__FILE__, function() {
error_log('Plugin deactivated');
});Wordpress
/* Plugin Name: Logger Plugin */ register_activation_hook(__FILE__, function() { error_log('Plugin activated'); }); register_deactivation_hook(__FILE__, function() { error_log('Plugin deactivated'); });
Attempts:
2 left
💡 Hint
Activation and deactivation hooks run only on those specific events.
✗ Incorrect
register_activation_hook runs the callback only when the plugin is activated. Similarly, register_deactivation_hook runs only when the plugin is deactivated. Both write their messages to the PHP error log at those times.
🧠 Conceptual
expert3:00remaining
Why is the plugin header required for activation?
Why does WordPress require a properly formatted plugin header comment block at the top of a plugin file before it can be activated?
Attempts:
2 left
💡 Hint
Think about how WordPress shows plugins in the admin area.
✗ Incorrect
The plugin header comment block provides metadata WordPress reads to display the plugin in the admin interface. Without it, WordPress does not recognize the file as a plugin and won't allow activation.