0
0
Wordpressframework~20 mins

Plugin file structure in Wordpress - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Plugin Structure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Identify the main plugin file in a WordPress plugin structure
Given a WordPress plugin folder with these files:

- my-plugin.php
- readme.txt
- includes/functions.php
- assets/style.css

Which file is the main plugin file that WordPress uses to activate the plugin?
Aincludes/functions.php
Breadme.txt
Cmy-plugin.php
Dassets/style.css
Attempts:
2 left
💡 Hint
The main plugin file is the one that contains the plugin header comment and is directly inside the plugin folder.
component_behavior
intermediate
1:30remaining
What happens if the main plugin file is missing?
If a WordPress plugin folder does not contain a main PHP file with the plugin header, what will WordPress do when you try to activate it?
AWordPress will not list the plugin in the admin plugins page.
BWordPress will activate the plugin but show a warning.
CWordPress will activate the plugin without any issues.
DWordPress will delete the plugin folder automatically.
Attempts:
2 left
💡 Hint
WordPress needs the main plugin file to recognize a plugin.
📝 Syntax
advanced
2:00remaining
Identify the correct plugin header format
Which of the following plugin header comments is correctly formatted for WordPress to recognize the plugin?
A
<?php
/*
Plugin-Name: My Plugin
Description: Does something useful.
Version: 1.0
*/
B
<?php
/*
Plugin Name: My Plugin
Description: Does something useful.
Version: 1.0
*/
C
<?php
// Plugin Name: My Plugin
// Description: Does something useful.
// Version: 1.0
D
<?php
/*
Plugin Name My Plugin
Description: Does something useful.
Version: 1.0
*/
Attempts:
2 left
💡 Hint
The plugin header must be inside a block comment with exact field names.
🔧 Debug
advanced
2:00remaining
Why does the plugin not load the included PHP file?
A plugin has this structure:

- my-plugin.php
- includes/functions.php

Inside my-plugin.php there is this code:
include 'includes/functions.php';

But when activating the plugin, functions from functions.php are not available. What is the likely cause?
AThe include path is relative to the current working directory, not the plugin file, so it fails.
BThe functions.php file has a syntax error preventing it from loading.
CThe include statement should use require_once instead of include.
DThe plugin header is missing in functions.php.
Attempts:
2 left
💡 Hint
Relative paths in PHP includes depend on the current working directory, not the file location.
state_output
expert
2:30remaining
What is the output of the plugin activation hook?
Consider this plugin main file code:
/*
Plugin Name: Test Plugin
*/

register_activation_hook(__FILE__, function() {
  update_option('test_plugin_activated', time());
});

add_action('admin_notices', function() {
  if ($time = get_option('test_plugin_activated')) {
    echo '<div class="notice notice-success">Plugin activated at: ' . date('H:i:s', $time) . '</div>';
    delete_option('test_plugin_activated');
  }
});

What will the admin see immediately after activating this plugin?
AA blank page because the plugin exits after activation.
BNo notice because the option is deleted before admin_notices runs.
CAn error because update_option cannot be called in activation hook.
DA success notice showing the exact time of activation in H:i:s format.
Attempts:
2 left
💡 Hint
The activation hook sets an option with the current time, which is then read and shown in the admin notices.