Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save faisalahammad/2e103685f4fe64ddc854ff9fe6cc1662 to your computer and use it in GitHub Desktop.

Select an option

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
<?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 );
@faisalahammad
Copy link
Copy Markdown
Author

faisalahammad commented Apr 1, 2026

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:

  1. Access Your Site Files
    Use FTP, SFTP, or your hosting file manager to access your WordPress installation files.

  2. Create mu-plugins Folder (if not exists)
    Navigate to wp-content/ and check if a folder named mu-plugins exists.
    If not, create a new folder named mu-plugins.

  3. Create the MU-Plugin File
    Inside the mu-plugins folder, create a new PHP file, e.g., gf-pods-integration.php.

  4. Paste the Provided Code
    Open the new PHP file and paste the entire PHP code you received.

  5. Save and Upload
    Save the file and ensure it is uploaded inside wp-content/mu-plugins/.

  6. 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.php

Note:

Using this method means the code runs only when that child theme is active.

Steps:

  1. Access Your Child Theme Folder
    Use FTP or file manager to go to wp-content/themes/your-child-theme/.

  2. Edit functions.php
    Open the functions.php file in the child theme folder.

  3. Paste the PHP Code
    Paste the provided PHP code at the end of the functions.php file (after the closing PHP tag if exists, or just append it).

  4. Save Changes
    Save and upload the updated functions.php file.

  5. Verify
    The code will run as part of your child theme functions.


Summary

Method Location Auto Load Activation Required
MU-Plugin wp-content/mu-plugins/*.php Yes No
Child Theme Code wp-content/themes/child-theme/functions.php Yes (with theme) No

If you want the integration always active regardless of theme, MU-Plugin is preferred.

Screenshots

image image image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment