Unique ID as Site Address and Site Title

Validate Unique ID Field Used as Site Address and Site Title.

Read the Walkthrough

Code

Filename: gpuid-site-address-title-validation.php

<?php
/**
 * Gravity Perks // Unique ID // Unique ID as Site Address and Site Title
 * https://gravitywiz.com/documentation/gravity-forms-unique-id/
 *
 * The Unique ID field is populated on submission, after validation. This snippet runs post-validation to allow User Registration feeds with a Unique ID
 * field mapped as the site address and/or site title to still pass validation.
 *
 * Plugin Name:  GP Unique ID - Unique ID as Site Address and Site Title
 * Plugin URI:   https://gravitywiz.com/documentation/gravity-forms-unique-id/
 * Description:  Validate Unique ID Field Used as Site Address and Site Title.
 * Author:       Gravity Wiz
 * Version:      0.1
 * Author URI:   https://gravitywiz.com/
 */
add_filter( 'gform_user_registration_validation', 'gp_unique_id_for_site_validation', 11, 2 );
function gp_unique_id_for_site_validation( $form, $feed ) {

	$site_address_field_id = rgars( $feed, 'meta/multisite_options/site_address' );
	$site_name_field_id    = rgars( $feed, 'meta/multisite_options/site_title' );

	foreach ( $form['fields'] as &$field ) {

		if ( $field['type'] == 'uid' && in_array( $field['id'], array( $site_address_field_id, $site_name_field_id ) ) ) {
			$field['failed_validation'] = false;
		}
	}

	return $form;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.