0
0
Wordpressframework~20 mins

Plugin header and activation in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WordPress Plugin Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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');
});
AWordPress will display 'Simple Logger activated' as a message on the admin dashboard after activation.
BWordPress will log 'Simple Logger activated' to the PHP error log when the plugin is activated.
CThe plugin will fail to activate because register_activation_hook cannot be used inside the plugin file.
DNothing happens because the activation hook is not properly registered.
Attempts:
2 left
💡 Hint
Think about what register_activation_hook does and where it runs.
📝 Syntax
intermediate
1:30remaining
Identify the correct plugin header syntax
Which of the following plugin headers is correctly formatted so WordPress recognizes it as a valid plugin?
A
/*
Plugin Name: My Plugin
Description: Does something useful
Version: 1.0
Author: Me
*/
B
// Plugin Name: My Plugin
// Description: Does something useful
// Version: 1.0
// Author: Me
C
<!-- Plugin Name: My Plugin -->
<!-- Description: Does something useful -->
<!-- Version: 1.0 -->
<!-- Author: Me -->
D
# Plugin Name: My Plugin
# Description: Does something useful
# Version: 1.0
# Author: Me
Attempts:
2 left
💡 Hint
WordPress plugin headers must be inside a PHP comment block at the top of the main plugin file.
🔧 Debug
advanced
2: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');
AThe function activate_test_plugin is missing a required parameter.
BThe plugin header is missing the Version field, so activation hooks don't run.
CThe error_log function cannot be used inside activation hooks.
DThe first argument to register_activation_hook must be __FILE__, not a string filename.
Attempts:
2 left
💡 Hint
Check the first argument of register_activation_hook carefully.
state_output
advanced
2: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');
});
AOnly 'Plugin activated' will be logged; deactivation hook does not run automatically.
BNothing will be logged because error_log is disabled in WordPress plugins.
CThe PHP error log will contain 'Plugin activated' after activation and 'Plugin deactivated' after deactivation.
DBoth hooks run immediately when the plugin file loads, logging both messages at once.
Attempts:
2 left
💡 Hint
Activation and deactivation hooks run only on those specific events.
🧠 Conceptual
expert
3: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?
ABecause WordPress uses the header to identify the plugin's name, version, and author to list it in the admin plugins page.
BBecause the header comment block contains PHP code that runs the activation hook automatically.
CBecause without the header, WordPress cannot load the plugin's PHP functions into memory.
DBecause the header comment block is where WordPress stores the plugin's database connection details.
Attempts:
2 left
💡 Hint
Think about how WordPress shows plugins in the admin area.