Melapress / admin-notices-manager

Admin notices manager is a WordPress plugin that allows you to better manage the admin notices in the WordPress dashboard so you read them at your own convenience and never miss an important message.
https://www.wpwhitesecurity.com/wordpress-plugins/admin-notices-manager/
Other
0 stars 0 forks source link

WP Mail SMTP settings disappear on Multisite with ANM #63

Closed robert81 closed 1 year ago

robert81 commented 2 years ago

1) Install WP Mail SMTP on the network 2) Install ANM 3) The settings do not load up:

image

4) Without ANM all works well:

image

Let's fix this and also test it on the single site once at it.

martinkrcho commented 2 years ago

This is an interesting one. I am not quite sure how we can fix it.

The WP Mail SMTP plugin tries to remove all notices not related to their plugin. It does this by removing all actions registered with hooks user_admin_notices, admin_notices and all_admin_notices - see the code below.

We use the all_admin_notices to print the closing DIV tag of our wrapper with CSS class anm-notices-wrapper. The hook doesn't run and therefore our DIV is not closed propelrly.

https://github.com/awesomemotive/WP-Mail-SMTP/blob/master/src/Admin/Area.php#L1197-L1212

/**
 * Remove all non-WP Mail SMTP plugin notices from our plugin pages.
 *
 * @since 1.0.0
 */
public function hide_unrelated_notices() {

    // Bail if we're not on our screen or page.
    if ( ! $this->is_admin_page() ) {
        return;
    }

    $this->remove_unrelated_actions( 'user_admin_notices' );
    $this->remove_unrelated_actions( 'admin_notices' );
    $this->remove_unrelated_actions( 'all_admin_notices' );
}

I can see two possible solutions.

  1. Get in touch with plugin authors and ask them to clear network_admin_notices hook along with the other three.
  2. Try to detect that we are on "WP Mail SMTP" admin page and don't try to hide notices here. We could use some of their code to do the detection.

What would you like to do here, @robert81?

capuderg commented 2 years ago

Hi @martinkrcho,

I'm the lead developer for WP Mail SMTP plugin.

Since your plugin is managing admin notices and we are removing all other ones on our pages, I would recommend going with option 2, because there won't be any notices to manage, except our own :)

You could of course hook into our code and disable the hide_unrelated_notices, like so:

add_action( 'network_plugin_loaded', function () {

    if ( ! function_exists( 'wp_mail_smtp' ) ) {
        return;
    }

    remove_action( 'admin_print_scripts', [ wp_mail_smtp()->get_admin(), 'hide_unrelated_notices' ] );
} );

Have a nice day!

martinkrcho commented 2 years ago

/cib

create-issue-branch[bot] commented 2 years ago

Branch issue-63-WP_Mail_SMTP_settings_disappear_on_Multisite_with_ANM created!

martinkrcho commented 2 years ago

You could of course hook into our code and disable the hide_unrelated_notices

Thanks for the advice, @capuderg . We're going to add this to our plugin.

capuderg commented 2 years ago

As I said, we would prefer option 2, because this change will display all admin notices on our plugin pages (because you are removing the hook where we originally remove all other admin notices). This would actually make our user's experience worse because they would see all the admin notices on our admin pages by default if your plugin would be active.

With the code above I just wanted to provide a way on how to hook in our code, if you'll ever need it in the future.

martinkrcho commented 2 years ago

I see. No problem.

How about my suggestion number 1?

Get in touch with plugin authors and ask them to clear network_admin_notices hook along with the other three.

Is there any reason why you're not removing actions hooked into network_admin_notices?

capuderg commented 2 years ago

Oh, I misunderstood you first point. You are suggesting that we also clear network_admin_notices, like so:

$this->remove_unrelated_actions( 'network_admin_notices' );?

I'll open a GH issue in our repository, and if everything is OK after our testing, we'll add this to the next plugin update (should be around early/mid April -> but no promises on the actual date :) ).

martinkrcho commented 2 years ago

Thanks, @capuderg . For now we are going to stop hiding notices on WP Mail SMTP's admin pages.

alexander-sakal commented 2 years ago

Hi @martinkrcho,

I'm the developer for WP Mail SMTP plugin.

We have implemented your first suggestion about clearing network_admin_notices hook. We plan to release our 3.4 version with this implementation the next week.

It would be great if you can remove this fix in your upcoming release.

robert81 commented 2 years ago

Thank you @alexander-sakal

We will indeed take care of this in the next release.

DannyWPWS commented 1 year ago

/cib

create-issue-branch[bot] commented 1 year ago

Branch issue-63-WP_Mail_SMTP_settings_disappear_on_Multisite_with_ANM created!

jwjsystem commented 1 year ago

@DannyWPWS @robert81 Performed basic checks for this one and can confirm it's solved in the latest build.