Is it possible to stop a theme activation when a certain plugin is not activated

Using after_switch_theme will activate the theme (which is fine as we want to run the check within the context of the new theme). If the dependencies are not fulfilled ($missing_dependencies = true;) we’re instantly switching back to the theme previously used (passed via after_switch_theme and $oldtheme). add_action( ‘after_switch_theme’, ‘check_theme_dependencies’, 10, 2 ); function check_theme_dependencies( $oldtheme_name, … Read more

Viewing output when the “The plugin generated x characters of unexpected output during activation” error is triggered

Interestingly the ability to display errors and output from a plugin on activation seems to be build in to WordPress. If you take a look at wp-admin/plugins.php there’s a case in the $action switch statement that says error_scrape — hinted at in Lars’ answer. Looks like this: <?php // wp-admin/plugins.php case ‘error_scrape’: if ( ! … Read more

Show a confirm message before plug-in activation

You can read more about the details of activation on this answer. Basically you need to hook a function to register_activation_hook() – assuming, that this is from within your main plugin folder and not a subfolder: register_activation_hook( __FILE__, ‘on_activation’ ); function wpse65190_on_activation() { // Add an admin notice: add_action( ‘admin_notices’, ‘wpse65190_on_activation_note’ ); // Then you … Read more

__NAMESPACE__ with register_activation_hook

The reason that the plugin activation hook wasn’t working in the code provided in the question is that on plugin activation the plugins_loaded hook is never run. Since the register_activation_hook hook was hooked from plugins_loaded it was never run on activation. And since it’s never fired ever again, this way of hooking results in register_activation_hook … Read more

Pluggable function and activation check?

Don’t do the check on activation? Seriously, the best way I can think of is not to check for this on activation, but only in the normal plugin load process. And instead of throwing a warning (I assume you mean a PHP E_WARNING), perhaps putting an admin error box up would make more sense.