TGMPA / TGM-Plugin-Activation

TGM Plugin Activation is a PHP library that allows you to easily require or recommend plugins for your WordPress themes (and plugins). It allows your users to install, update and even automatically activate plugins in singular or bulk fashion using native WordPress classes, functions and interfaces. You can reference bundled plugins, plugins from the WordPress Plugin Repository or even plugins hosted elsewhere on the internet.
http://tgmpluginactivation.com/
GNU General Public License v2.0
1.75k stars 431 forks source link

Workaround for dismissable Notification with recommended and required plugins #733

Open CreativeDive opened 6 years ago

CreativeDive commented 6 years ago

Hey, maybe this is interesting for some people which working with recommended and required plugins. The problem of TGMPA is, with the latest version you can't distinguish between recommended and required plugins, if you want to disable the notification only for recommended plugins.

This is a workaround and it works fine for me:

function dismissable_notice_for_recommended_plugins() {
        global $current_user; 

        if( $current_user ) {
            $activation_notice_dismissed = get_user_meta( $current_user->ID, 'tgmpa_dismissed_notice_your-tgmpa-id', true );

            if ( ! is_plugin_active('required-plugin-folder/required-plugin.php') && $activation_notice_dismissed == true ) {
                update_user_meta( $current_user->ID, 'tgmpa_dismissed_notice_your-tgmpa-id', false, true );
            }
        }
    }
    add_action('admin_notices', 'dismissable_notice_for_recommended_plugins');

A solution to show the notification again only, if a required plugin is inactive.

3pepe3 commented 6 years ago

Good workaround and I think that the user meta 'tgmpa_dismissednotice' must be deleted when we deactivate the plugin and reactivate the plugin... it seems that the delete function is only triggered on switch theme