- 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?
The main plugin file is the PHP file located directly inside the plugin folder that contains the plugin header comment. WordPress uses this file to recognize and activate the plugin.
Without a main plugin file containing the plugin header, WordPress does not recognize the folder as a plugin and will not list it on the plugins page.
The plugin header must be inside a block comment /* ... */ with exact field names like Plugin Name. Option B follows this format correctly.
- 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?PHP includes use paths relative to the current working directory, which may not be the plugin file's folder. Using a relative path without adjusting for this causes the include to fail silently.
/*
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?
The activation hook stores the current time in an option. The admin_notices action reads this option and shows a success message with the activation time, then deletes the option so the notice only shows once.