0

I am currently developing a plugin, which depends on another plugin (json-api). I use the following code to check for the presence during startup and in the constructor, in case the json-api plugin is deactivated later on:

require_once (ABSPATH . '/wp-admin/includes/plugin.php');

class MyPlugin {
    public function __construct() {
        // ... 
        // register a check for dependency
        add_action('plugins_loaded', array( $this, 'dependency_check' ));

    }

    public function dependency_check() {
        if (!class_exists('DEP_CLASS'))
            $this->dependency_failed();
    }

    protected function dependency_failed() {
        if (current_user_can( 'activate_plugins' ))
            deactivate_plugins( plugin_basename ( __FILE__ ) );

        add_action('admin_notices', array ($this, 'notify_dependency_problem') );
    }

    public static function notify_dependency_problem() { /* ... error message shown ... */ }

    public function activate() {
        if (!is_plugin_active('dep_plugin/start.php')) {
            $this->dependency_failed();
            return false;
        }
    }
}

register_activation_hook(__FILE__, array('MyPlugin', 'activate'));
new MyPlugin();

This works fine so far - however, Wordpress additionally shows a "Plugin Activated" notice, which is misleading to the user. Additionally, the buttons ("Activate", "Edit", "Delete") below the plugin are now missing as well.

  1. How is it possible to get rid of the "Plugin Activated" Message (Note: Thanks to @toscho, this has been resolved via a unset($_GET['activate'])) and
  2. how to get the buttons back?
  • 1
    You need unset( $_GET['activate'] );. See the linked topic. – fuxia May 2 '14 at 14:40
  • Thanks, @toscho, that fixes the message. Still, the buttons are missing. Any further ideas? – Lars May 2 '14 at 14:48
  • That is probably some PHP error. Enable the debug mode and try to find it. – fuxia May 2 '14 at 15:33
  • It's not a php error by itself and the debug mode doesn't show anything. The question is not a duplicate of the linked question, because it does contain more than one problem. However, since it's now marked a duplicate, everyone will skip this one. Please make sure you do use your moderation rights correctly next time. – Lars May 2 '14 at 17:45
  • Then edit your question to ask really just one question, and we will reopen it. – fuxia May 2 '14 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.