Using Gravity Forms ‘gform_paypal_ipn_url’ PHP filter

The gform_paypal_ipn_url filter allows you to modify the PayPal IPN URL to which data is being posted.

Usage

add_filter('gform_paypal_ipn_url', 'your_function_name', 10, 1);

Parameters

  • $url (string): The IPN URL.

More information

See Gravity Forms Docs: gform_paypal_ipn_url

Examples

Change IPN URL to sandbox

Send all requests to the PayPal sandbox for testing purposes.

add_filter('gform_paypal_ipn_url', 'change_ipn_url', 10, 1);

function change_ipn_url($url) {
    // Send all requests to the sandbox
    return "https://www.sandbox.paypal.com/cgi-bin/webscr/";
}

Add custom parameter to IPN URL

Add a custom parameter to the IPN URL for tracking purposes.

add_filter('gform_paypal_ipn_url', 'add_custom_parameter', 10, 1);

function add_custom_parameter($url) {
    // Add a custom parameter to the IPN URL
    return $url . "?custom_param=value";
}

Switch IPN URL based on environment

Switch the IPN URL based on the environment variable in your WordPress configuration.

add_filter('gform_paypal_ipn_url', 'switch_ipn_url', 10, 1);

function switch_ipn_url($url) {
    if (defined('WP_ENV') && WP_ENV == 'sandbox') {
        return "https://www.sandbox.paypal.com/cgi-bin/webscr/";
    } else {
        return "https://www.paypal.com/cgi-bin/webscr/";
    }
}

Change IPN URL for a specific form

Change the IPN URL only for a specific form with a given form ID.

add_filter('gform_paypal_ipn_url', 'change_ipn_url_for_form', 10, 2);

function change_ipn_url_for_form($url, $entry) {
    // Check if the form ID is 5
    if ($entry['form_id'] == 5) {
        return "https://custom-url.com/ipn/";
    }
    return $url;
}

Modify IPN URL based on user role

Modify the IPN URL based on the user role, sending transactions from users with a specific role to a different IPN URL.

add_filter('gform_paypal_ipn_url', 'change_ipn_url_based_on_user_role', 10, 2);

function change_ipn_url_based_on_user_role($url, $entry) {
    $user = get_user_by('id', $entry['created_by']);
    if (in_array('special_role', $user->roles)) {
        return "https://custom-url.com/ipn/special_role/";
    }
    return $url;
}