The gform_has_admin_notices filter in Gravity Forms PHP is used to determine whether to display the “WordPress has new notifications.” notice at the top of Gravity Forms admin pages.
Usage
To use the filter on Gravity Forms admin pages, you can add the following code:
add_filter('gform_has_admin_notices', 'your_function_name');
Parameters
- $has_notices (bool): Defaults to false; there are no notifications to display.
More information
See Gravity Forms Docs: gform_has_admin_notices
Examples
Enable the notice
To enable the “WordPress has new notifications.” notice, use the following code:
add_filter('gform_has_admin_notices', '__return_true');
Disable the notice
To disable the “WordPress has new notifications.” notice, use the following code:
add_filter('gform_has_admin_notices', '__return_false');
Custom function to show notice based on user role
To display the notice only for administrators, create a custom function like this:
function show_notice_for_admins($has_notices) { if (current_user_can('administrator')) { return true; } return $has_notices; } add_filter('gform_has_admin_notices', 'show_notice_for_admins');
Custom function to show notice on specific pages
To display the notice only on specific Gravity Forms admin pages, create a custom function like this:
function show_notice_on_specific_pages($has_notices) { $current_screen = get_current_screen(); // Show notice on form list and form settings pages if (in_array($current_screen->id, array('toplevel_page_gf_edit_forms', 'gravityforms_page_gf_settings'))) { return true; } return $has_notices; } add_filter('gform_has_admin_notices', 'show_notice_on_specific_pages');
Custom function to show notice based on date
To display the notice only within a specific date range, create a custom function like this:
function show_notice_within_date_range($has_notices) { $start_date = '2023-05-01'; $end_date = '2023-05-31'; $current_date = date('Y-m-d'); if ($current_date >= $start_date && $current_date <= $end_date) { return true; } return $has_notices; } add_filter('gform_has_admin_notices', 'show_notice_within_date_range');