Improve plugin activate and deactivate hooks
|Reported by:||Otto42||Owned by:||anonymous|
The activate and deactivate hooks are clumsy, at best. Because they rely on the name of the plugin file being a constant, renaming a plugin file will break them. Even worse, the plugin path is part of that name, so putting a plugin in a subdirectory that it was not expecting (for users that want to keep things organized) will also break these.
Instead, how about adding an optional tag to the Plugin header, like so:
<?php /* Plugin Name: Name Of The Plugin Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates Description: A brief description of the plugin. Version: The plugin's Version Number, e.g.: 1.0 Author: Name Of The Plugin Author Author URI: http://URI_Of_The_Plugin_Author Activate: activate_function_hook Deactivate: deactivate_function_hook */ ?>
When a plugin is activated or deactivated, that tag can be read from its header and then the hook specified can be called to trigger that action in the plugin. This provides an absolutely certain way to call activate or deactivate functions in a plugin, without relying on the filename and filepath that the plugin happens to be in.
Change History (6)
comment:1 follow-up: ↓ 5 markjaquith — 7 years ago
- Milestone 2.4 deleted
- Resolution set to invalid
- Status changed from new to closed
- Resolution invalid deleted
- Status changed from closed to reopened