Hide rows or modules based on field connections (Themer)

There may be times when you don't want rows or modules to show up when a field connection is empty. 

You can use the following code to hide any rows or modules that have empty field connections. Add it to your child theme's functions.php file.

function check_field_connections( $is_visible, $node ) {
	
	if ( isset( $node->settings->connections ) ) {
		foreach ( $node->settings->connections as $key => $connection ) {
			if ( ! empty( $connection ) && empty( $node->settings->$key ) ) {
				return false;
			}
		}
	}
	
	return $is_visible;
}

add_filter( 'fl_builder_is_node_visible', 'check_field_connections', 10, 2 );

Savvy developers can extend this code using the $node variable to choose which rows or modules are hidden based on a number of circumstances such as $node->type or $node->settings.