Open b4after-pl opened 8 years ago
I'm not quite sure what you are having an issue with. The boilerplate by itself doesn't force you to add your actions at any particular point.
Yes, but in main plugin class (WordPress-Plugin-Boilerplate/plugin-name/plugin-name.php) You have on line 75:
run_plugin_name();
If You put function like is_super_admin() anywhere in plugin it will casue server error:
PHP Fatal error: Call to undefined function wp_get_current_user() in YOUR_PATH_TO_WP/wp-includes/capabilities.php on line 1373
So instead runing plugin by simple function, start it by adding action:
add_action('plugins_loaded', 'run_plugin_name');
Plugin will start after all other WP resources will be loaded.
That would then prevent the plugin from modifying anything before that point.
The boilerplate is never going to be the perfect solution for every instance. It should however not default to limiting a build. So in your case if you added a check for is_super_admin then you could put that into a method that only runs after all plugins are loaded or you could change the entire plugin to run after plugins_loaded as you noted above.
To @b4after-pl point, in the spirit of the boilerplate it does makes sense. here's why:
1) for consistency. you can also pick an earlier action if you want. but at least you know you should. which leads me to...
2) such things might not be so obvious to a WP n00b. shouldn't they be? i would say so. i'm pretty sure the first time i saw "PHP Fatal error: Call to undefined function wp_get_current_user..." i ended up with a bloody forehead, matching (blood stained) keyboard and too many hours lost to a time suck.
i understand and apprecaite the desire for lean and KISS but this action is pretty crucial and it should be purposely defined, and therefore also self-documenting.
When plugin class is running just by function, wordpress core functions like is_super_admin(), current_user_ca() cause problem with require capabilities.php. Plugin should be run by add_action: