Using Gravity Forms ‘gform_slack_icon’ PHP filter

The gform_slack_icon filter allows you to change the icon displayed with the Slack message. The icon image size should be 48×48.

Usage

add_filter('gform_slack_icon', 'change_slack_icon', 10, 4);

Parameters

  • $icon_url (string): The current icon being used for the Slack message.
  • $feed (Feed Object): The current feed object.
  • $entry (Entry Object): The current entry object.
  • $form (Form Object): The current form object.

More information

See Gravity Forms Docs: gform_slack_icon

Examples

Change icon URL for form ID 4

This example changes the icon URL if the form ID is 4.

add_filter('gform_slack_icon', 'change_slack_icon', 10, 4);

function change_slack_icon($icon_url, $feed, $entry, $form) {
    if ($form['id'] == 4) {
        $icon_url = 'http://placehold.it/48';
    }

    return $icon_url;
}

Change icon URL based on entry value

This example changes the icon URL based on a specific entry value.

add_filter('gform_slack_icon', 'change_slack_icon_based_on_entry_value', 10, 4);

function change_slack_icon_based_on_entry_value($icon_url, $feed, $entry, $form) {
    if ($entry['1'] == 'Important') {
        $icon_url = 'http://example.com/important-icon.png';
    }

    return $icon_url;
}

Use different icons for multiple forms

This example demonstrates using different icons for multiple forms.

add_filter('gform_slack_icon', 'different_icons_for_forms', 10, 4);

function different_icons_for_forms($icon_url, $feed, $entry, $form) {
    switch ($form['id']) {
        case 1:
            $icon_url = 'http://example.com/form1-icon.png';
            break;
        case 2:
            $icon_url = 'http://example.com/form2-icon.png';
            break;
        default:
            $icon_url = 'http://example.com/default-icon.png';
    }

    return $icon_url;
}

Change icon URL based on feed meta

This example changes the icon URL based on a custom feed meta value.

add_filter('gform_slack_icon', 'change_slack_icon_based_on_feed_meta', 10, 4);

function change_slack_icon_based_on_feed_meta($icon_url, $feed, $entry, $form) {
    if (isset($feed['meta']['custom_icon_url']) && !empty($feed['meta']['custom_icon_url'])) {
        $icon_url = $feed['meta']['custom_icon_url'];
    }

    return $icon_url;
}

Use user avatar as icon

This example uses the user’s avatar as the icon for the Slack message.

add_filter('gform_slack_icon', 'use_user_avatar_as_icon', 10, 4);

function use_user_avatar_as_icon($icon_url, $feed, $entry, $form) {
    if (isset($entry['created_by'])) {
        $user = get_userdata($entry['created_by']);
        $icon_url = get_avatar_url($user->ID);
    }

    return $icon