Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save uamv/62c6cf9f494bc86f545f33d183ccdf20 to your computer and use it in GitHub Desktop.
Save uamv/62c6cf9f494bc86f545f33d183ccdf20 to your computer and use it in GitHub Desktop.
// remap nested forms for multisite global forms
add_filter( 'gform_form_post_get_meta', function( $form ) {
if ( ! class_exists( 'GH_MGF' ) || is_main_site() ) {
return $form;
}
$primary_form_id = GH_MGF::get_primary_form_id( rgar( $form, 'id' ) );
foreach ( $form['fields'] as &$field ) {
if ( $field->get_input_type() === 'form' ) {
$primary_matching_field = GH_MGF::do_network_request( SITE_ID_CURRENT_SITE, [ 'GFAPI', 'get_field' ], [ $primary_form_id, $field->id ] );
$matching_child_form_id = GH_MGF::get_child_form_id( $field->gpnfForm );
if ( $matching_child_form_id ) {
$field->gpnfForm = $matching_child_form_id;
}
}
}
return $form;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment