Alter admin notices to remove message that contain a certain string

Yes, this is possible (but a pain).

Admin messages are creating when WordPress runs this line in admin-header.php:

do_action( 'admin_notices' );

The action called before this one is:

do_action( 'in_admin_header' );

So, we can hook in there and run some code to make some changes to filter out messages before WordPress can render them.

First create a new action to bind to the 'in_admin_header' event:

add_action('in_admin_header', 'admin_mods_disable_some_admin_notices');

When a plugin wants to display an admin message they add an admin_notices‘s callback. It would be sensible if these actions returned the HTML to display as opposed to just printing it, however this is not the case, so we’ll need to loop over all the callbacks and set an output buffer for each to collect the generated HTML and then check if that contains a forbidden string. It it does then we can unbind that modules admin_notices callback.

For example:

function admin_mods_disable_some_admin_notices() {

    // This global object is used to store all plugins callbacks for different hooks
    global $wp_filter;

    // Here we define the strings that we don't want to appear in any messages
    $forbidden_message_strings = [
        'The WP scheduler doesn\'t seem to be running correctly for Newsletter'
    ];

    // Now we can loop over each of the admin_notice callbacks
    foreach($wp_filter['admin_notices'] as $weight => $callbacks) {

        foreach($callbacks as $name => $details) {

            // Start an output buffer and call the callback
            ob_start();
            call_user_func($details['function']);
            $message = ob_get_clean();

            // Check if this contains our forbidden string
            foreach($forbidden_message_strings as $forbidden_string) {
                if(strpos($message, $forbidden_string) !== FALSE) {

                     // Found it - under this callback
                     $wp_filter['admin_notices']->remove_filter('admin_notices', $details['function'], $weight);
                }
            }

        }

    }
}

WordPress could really do with implementing something like Druapl’s render arrays to make doing stuff like this much easier.

LIMITATIONS:

As Tom J Nowell pointed out plugins can just spit out HTML at any point and WP javascript will move them to the top of the screen. Not having one API endpoint to add all admin notices make it pretty much impossible to reliably alter all admin messages. However, using this method you can at least target any plugins that utilize the admin_notices action.