<?php
/**
 * Wrapper for GravityForms Integration
 *
 * @link https://personalizewp.com/
 * @since 3.2.0
 *
 * @package PersonalizeWP
 * @subpackage PersonalizeWP/Integrations
 */

namespace PersonalizeWP\Integrations\GravityForms;

use GFAddOn;
use PersonalizeWP\Integrations\GravityForms\GravityForms;

/**
 * Register the GravityForms integation, and setup various actions/filters.
 *
 * @param \PersonalizeWP\PersonalizeWP $personalizewp Instance of plugin
 *
 * @return void
 */
function register_integration( $personalizewp ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found

	// Use WP functions to check activeness.
	require_once ABSPATH . 'wp-admin/includes/plugin.php';

	// Check for plugin.
	if ( ! is_plugin_active( 'gravityforms/gravityforms.php' ) ) {
		return;
	}

	add_action(
		'gform_loaded',
		function () {
			if ( ! method_exists( '\GFForms', 'include_addon_framework' ) ) {
				return;
			}
			GFAddOn::register( GravityForms::class );

			$gravityforms = GravityForms::get_instance();
		},
		5
	);
}
add_action( 'personalizewp_register_integrations', __NAMESPACE__ . '\register_integration' );
