Created
April 1, 2026 11:17
-
-
Save faisalahammad/2e103685f4fe64ddc854ff9fe6cc1662 to your computer and use it in GitHub Desktop.
Gravity Forms Pods Integration MU Plugin for User Registration Add-On | Auto Sync User Meta Fields & Boolean Casting
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: Gravity Forms + Pods Integration | |
| * Description: Automatically adds Pods User fields to the User Registration Add-On meta keys list, and properly casts mapped Checkbox values into strict booleans (1/0) for Pods boolean fields. | |
| * Author: Faisal Ahammad <[email protected]> | |
| */ | |
| // 1. Add Pods User fields to the GF User Registration Meta Key dropdown | |
| add_filter( 'gform_user_registration_user_meta_options', function( $keys ) { | |
| if ( ! function_exists( 'pods_api' ) ) { | |
| return $keys; | |
| } | |
| $api = pods_api(); | |
| // Load the Extended User pod (if it exists) | |
| $pod = $api->load_pod( [ 'name' => 'user' ], false ); | |
| if ( ! empty( $pod ) && ! empty( $pod['fields'] ) ) { | |
| if ( ! is_array( $keys ) ) { | |
| $keys = []; | |
| } | |
| foreach ( $pod['fields'] as $field ) { | |
| $keys[] = [ | |
| 'label' => '[Pods] ' . $field['label'], | |
| 'name' => $field['name'], | |
| 'value' => $field['name'], | |
| 'required' => false | |
| ]; | |
| } | |
| } | |
| return $keys; | |
| }, 10, 1 ); | |
| // 2. Intercept boolean values to ensure they save as 1/0 for Pods | |
| add_filter( 'gform_user_registration_meta_value', function( $value, $meta_key, $meta, $form, $entry ) { | |
| if ( ! function_exists( 'pods_api' ) ) { | |
| return $value; | |
| } | |
| $api = pods_api(); | |
| $pod = $api->load_pod( [ 'name' => 'user' ], false ); | |
| if ( empty( $pod ) || empty( $pod['fields'] ) || empty( $pod['fields'][ $meta_key ] ) ) { | |
| return $value; // Not a Pods field or not registered. | |
| } | |
| $field = $pod['fields'][ $meta_key ]; | |
| // Only apply processing to boolean fields | |
| if ( 'boolean' === $field['type'] ) { | |
| if ( is_array( $value ) ) { | |
| $value = empty( $value ) ? 0 : 1; | |
| } else { | |
| // In Gravity Forms, an unchecked string is usually empty "". | |
| // A explicitly false string could be "false" or "no". | |
| // Valid labels are considered truthy. | |
| $value = ( empty( $value ) || '0' === $value || false === filter_var( $value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ) ) ? 0 : 1; | |
| } | |
| } | |
| return $value; | |
| }, 10, 5 ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to Use the Gravity Forms + Pods Integration Code
This guide explains how to add the provided PHP code as a Must-Use (MU) Plugin or in a child theme for your WordPress site.
Option 1: Install as MU-Plugin
What is an MU-Plugin?
MU-Plugins are "Must Use" plugins that load automatically without activation and cannot be disabled via the admin dashboard.
Steps:
Access Your Site Files
Use FTP, SFTP, or your hosting file manager to access your WordPress installation files.
Create
mu-pluginsFolder (if not exists)Navigate to
wp-content/and check if a folder namedmu-pluginsexists.If not, create a new folder named
mu-plugins.Create the MU-Plugin File
Inside the
mu-pluginsfolder, create a new PHP file, e.g.,gf-pods-integration.php.Paste the Provided Code
Open the new PHP file and paste the entire PHP code you received.
Save and Upload
Save the file and ensure it is uploaded inside
wp-content/mu-plugins/.Verify
The plugin runs automatically. There is no need to activate it in the admin panel.
Option 2: Add Code to Child Theme's
functions.phpNote:
Using this method means the code runs only when that child theme is active.
Steps:
Access Your Child Theme Folder
Use FTP or file manager to go to
wp-content/themes/your-child-theme/.Edit
functions.phpOpen the
functions.phpfile in the child theme folder.Paste the PHP Code
Paste the provided PHP code at the end of the
functions.phpfile (after the closing PHP tag if exists, or just append it).Save Changes
Save and upload the updated
functions.phpfile.Verify
The code will run as part of your child theme functions.
Summary
wp-content/mu-plugins/*.phpwp-content/themes/child-theme/functions.phpIf you want the integration always active regardless of theme, MU-Plugin is preferred.
Screenshots