Performance: Plugin header and activation
This affects the initial load time and responsiveness of the WordPress admin dashboard when plugins are activated or loaded.
<?php /* Plugin Name: Efficient Plugin Description: Minimal header and fast activation. Version: 1.0 */ register_activation_hook(__FILE__, function() { // Minimal setup, defer heavy tasks update_option('efficient_plugin_activated', true); // Schedule heavy tasks with wp_cron if (!wp_next_scheduled('efficient_plugin_deferred_task')) { wp_schedule_single_event(time() + 10, 'efficient_plugin_deferred_task'); } });
<?php /* Plugin Name: Heavy Plugin Description: Loads many resources and runs slow activation tasks. Version: 1.0 */ register_activation_hook(__FILE__, function() { // Heavy database queries and external API calls sleep(5); update_option('heavy_plugin_activated', true); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy activation hook with blocking tasks | Minimal DOM impact | 0 | 0 | [X] Bad |
| Light activation hook with deferred tasks | Minimal DOM impact | 0 | 0 | [OK] Good |
and ending with */ ?>.register_activation_hook(__FILE__, function() {
update_option('my_plugin_activated', true);
});update_option to set 'my_plugin_activated' to true in the WordPress options table.register_activation_hook(__FILE__, 'activate_plugin');
function activate_plugin() {
add_option('plugin_activated', true);
}add_option adds a new option only if it does not exist. If the option exists, it fails silently. update_option adds or updates the option.add_option will not update the value, possibly causing unexpected behavior.Pass the test and this pattern moves unknown