AI Verified

Name

Disable admin notices by text string

About

In $forbidden_message_strings array, provide a list of keywords or phrases that you want to disable. Provide a longer phrase to increase specificity

Language

PHP

Rating

Voted: 2 by 2 user(s)

How to Setup Snippet

1. Install 2. Adjust $forbidden_message_strings array 3. Activate

Codevault

hoofer

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: Not Specified

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

17/04/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Disable admin notices by text string

 
                    
1add_action('admin_init', function(){
2 add_action('in_admin_header', function(){
3 
4 // This global object is used to store all plugins callbacks for different hooks
5 global $wp_filter;
6 
7 // Here we define the strings that we don't want to appear in any messages
8 $forbidden_message_strings = [
9 'LearnDash LMS',
10 'Elementor',
11 'CartFlows',
12 'WooCommerce',
13 ];
14 
15 // Now we can loop over each of the admin_notice callbacks
16 foreach($wp_filter['admin_notices'] as $weight => $callbacks) {
17 
18 foreach($callbacks as $name => $details) {
19 
20 // Start an output buffer and call the callback
21 ob_start();
22 call_user_func($details['function']);
23 $message = ob_get_clean();
24 
25 // Check if this contains our forbidden string
26 foreach($forbidden_message_strings as $forbidden_string) {
27 if(strpos($message, $forbidden_string) !== FALSE) {
28 // Found it - under this callback
29 $wp_filter['admin_notices']->remove_filter('admin_notices', $details['function'], $weight);
30 }
31 }
32 
33 }
34 
35 }
36 });
37});

2

Related Snippets

Please see some snippets below related to this snippet..

WordPress Admin

AI Verified

2

Company Screen Option

Added: 7 months ago

Last Updated: 4 months ago

Add your Logo and Company Details to the WordPress Dashboard as a Screen Option

WordPress Admin

AI Verified

1

Save in WP Admin with CTRL + S

Added: 1 year ago

Last Updated: 1 month ago

Save time by hitting CTRL/CMD + S instead of scrolling to find the Save/Update/Publish button

WordPress Admin

AI Verified

0

Show content to logged in User only

Added: 9 months ago

Last Updated: 9 months ago

Show content to logged in User only

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

General

AI Verified

3

Autopopulate menu item with posts by post type

Added: 1 year ago

Last Updated: 11 months ago

Autopopulate menu item with posts by post type as submenu items

WordPress Admin

AI Verified

2

Disable admin notices by text string

Added: 1 year ago

Last Updated: 1 year ago

In $forbidden_message_strings array, provide a list of keywords or phrases that you want to disable. Provide a longer phrase to increase specificity

WordPress Admin

AI Verified

1

Save in WP Admin with CTRL + S

Added: 1 year ago

Last Updated: 1 month ago

Save time by hitting CTRL/CMD + S instead of scrolling to find the Save/Update/Publish button