Filter
uncanny-automator
give_telemetry_form_uses_addon_form_field_manager
Filters whether the Add-on Form Field Manager is used for a specific GiveWP form.
add_filter( 'give_telemetry_form_uses_addon_form_field_manager', $callback, 10, 1 );
Description
Filters whether Give uses the Add-on Form Field Manager for rendering custom form fields. Developers can return `true` to enforce Add-on Form Field Manager usage or `false` to allow standard Give field rendering. This hook fires when retrieving custom fields for a Give donation form.
Usage
add_filter( 'give_telemetry_form_uses_addon_form_field_manager', 'your_function_name', 10, 1 );
Parameters
-
$form_id(mixed) - This parameter's initial value is false, likely serving as a default or placeholder before being potentially modified by the filter.
Return Value
The filtered value.
Examples
<?php
/**
* Detect if the form uses the GiveWP Form Field Manager addon.
*
* This filter allows developers to programmatically determine if a GiveWP form
* is being managed by the Form Field Manager addon. The default behavior is to
* check for specific markers within the form's meta data.
*
* @param bool $uses_addon_form_field_manager Whether the form uses the addon.
* @param int $form_id The ID of the GiveWP form.
*
* @return bool True if the form uses the addon, false otherwise.
*/
add_filter( 'give_telemetry_form_uses_addon_form_field_manager', function( $uses_addon_form_field_manager, $form_id ) {
// If the default check already determined it's using the addon, return true.
if ( $uses_addon_form_field_manager ) {
return true;
}
// Attempt to retrieve form builder fields from meta.
$form_builder_fields = give_get_meta( $form_id, 'formBuilderFields', true );
// If form builder fields are present and contain the FFM identifier,
// it's highly likely the addon is in use.
if ( ! empty( $form_builder_fields ) && strpos( $form_builder_fields, 'givewp-form-field-manager' ) !== false ) {
// Further validation: decode the JSON and check if it's a valid array.
$decoded_fields = json_decode( $form_builder_fields, true );
if ( is_array( $decoded_fields ) ) {
return true;
}
}
// If none of the above conditions are met, assume the addon is not in use.
return false;
}, 10, 2 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/give/helpers/give-helpers.php:189
if ( method_exists( 'Give_FFM_Render_Form', 'get_input_fields' ) ) {
$custom_fields = Give_FFM_Render_Form::get_input_fields( $form_id );
} elseif ( class_exists( 'GiveFormFieldManagerHelpersForm' ) && method_exists( 'GiveFormFieldManagerHelpersForm', 'get_input_fields' ) ) {
$custom_fields = GiveFormFieldManagerHelpersForm::get_input_fields( $form_id );
}
if ( ! empty( $custom_fields ) && empty( $custom_fields[2] ) ) {
if ( apply_filters( 'give_telemetry_form_uses_addon_form_field_manager', false, $form_id ) ) {
$form_builder_fields = give()->form_meta->get_meta( $form_id, 'formBuilderFields', true );
if ( ! empty( $form_builder_fields ) && strpos( $form_builder_fields, 'givewp-form-field-manager' ) !== false ) {
$decoded = json_decode( $form_builder_fields, true );
if ( is_array( $decoded ) ) {
$custom_fields[2] = $this->get_give_form_fields_from_form_builder( $decoded );
}
}