Created
December 1, 2025 20:44
-
-
Save nathaningram/405c7fddc1f55f6e9cf552ad2ec4e1e3 to your computer and use it in GitHub Desktop.
Starter Site 2025 - MU Gravity Forms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| Plugin Name: Custom Functions for Gravity Forms | |
| Plugin URI: https://wpnathan.com | |
| Description: Customize Gravity Forms Default Behavior | |
| Version: 1.0 | |
| Author: Nathan Ingram | |
| Author URI: https://wpnathan.com | |
| License: GPL2 | |
| */ | |
| // Security Check | |
| if (!defined('ABSPATH')) { | |
| die(); | |
| } | |
| // Give Editors Partial Gravity Forms Access | |
| function ni_add_grav_forms_partial_access() { | |
| $role = get_role('editor'); | |
| if ($role && !$role->has_cap('gform_full_access')) { | |
| $role->add_cap('gform_full_access'); | |
| } | |
| } | |
| add_action('admin_init', 'ni_add_grav_forms_partial_access'); | |
| // Remove Specific Gravity Forms Menu Items for Editors | |
| function ni_remove_gravity_forms_menu_items() { | |
| if (current_user_can('editor') && !current_user_can('administrator')) { | |
| // Remove specific submenu pages under Gravity Forms | |
| remove_submenu_page('gf_edit_forms', 'gf_settings'); // Settings | |
| remove_submenu_page('gf_edit_forms', 'gf_system_status'); // System Status | |
| remove_submenu_page('gf_edit_forms', 'gf_help'); // Help | |
| } | |
| } | |
| add_action('admin_menu', 'ni_remove_gravity_forms_menu_items', 11); | |
| //Start GF Multi Page Progress Bar at 0% | |
| add_filter( 'gform_progressbar_start_at_zero', '__return_true' ); | |
| // Change Default Send to and From Email Addresses for All Forms | |
| add_filter('gform_notification', function($notification, $form, $entry) { | |
| // Extract the domain dynamically from the site URL | |
| $site_domain = parse_url(get_site_url(), PHP_URL_HOST); | |
| $custom_from_email = "website@$site_domain"; // Custom "From" email | |
| $custom_to_email = "info@$site_domain"; // Custom "To" email | |
| // Get the actual admin email address | |
| $admin_email = get_bloginfo('admin_email'); | |
| // Override the "From" email if it is set to {admin_email} or matches the admin email | |
| if ( | |
| $notification['from'] === '{admin_email}' || | |
| $notification['from'] === $admin_email | |
| ) { | |
| $notification['from'] = $custom_from_email; | |
| } | |
| // Override the "To" email if it is set to {admin_email} or matches the admin email | |
| if ( | |
| $notification['to'] === '{admin_email}' || | |
| $notification['to'] === $admin_email | |
| ) { | |
| $notification['to'] = $custom_to_email; | |
| } | |
| return $notification; // Return the modified notification | |
| }, 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment