'POST',
'callback' => array( self::class, 'handleClaimRequest' ),
'permission_callback' => static function () {
return current_user_can( 'manage_options' );
},
)
);
}
/**
* REST callback — server-side wrapper around the Forge12 grandfather endpoint.
*
* @param \WP_REST_Request $request
* @return \WP_REST_Response
*/
public static function handleClaimRequest( $request ) {
$client = new GrandfatherLicenseClient();
$response = $client->claimAvada(
home_url(),
get_option( 'admin_email', '' ),
self::buildAttestation()
);
if ( $response['success'] ) {
update_option( self::OPTION_GRANDFATHER_LICENSE, $response['licenseKey'] );
}
return new \WP_REST_Response( $response );
}
/**
* Build the self-reported attestation payload that accompanies the claim.
*
* @return array
*/
private static function buildAttestation(): array {
return array(
'avadaDetected' => self::isAvadaActive(),
'doiConfiguredOnAvadaForm' => self::doiConfiguredOnAvadaForm(),
'lastActivity' => gmdate( 'Y-m-d' ),
);
}
/**
* Cache-backed check: does this site have at least one Avada form with
* DOI settings configured?
*/
public static function isAvadaInUseWithDoi(): bool {
$cached = get_transient( self::TRANSIENT_AVADA_USED );
if ( $cached === 'yes' ) {
return true;
}
if ( $cached === 'no' ) {
return false;
}
$result = self::isAvadaActive() && self::doiConfiguredOnAvadaForm();
set_transient( self::TRANSIENT_AVADA_USED, $result ? 'yes' : 'no', DAY_IN_SECONDS );
return $result;
}
public static function isAvadaActive(): bool {
return class_exists( '\\Fusion_Forms' ) || function_exists( 'fusion_builder_init' );
}
/**
* Expensive query — only call via the cached isAvadaInUseWithDoi().
*
* Counts posts of post_type `fusion_form` that have a DOI settings
* meta entry. A single row is enough to qualify the site for the notice.
*/
public static function doiConfiguredOnAvadaForm(): bool {
global $wpdb;
$sql = $wpdb->prepare(
"SELECT COUNT(*) FROM {$wpdb->postmeta} pm
INNER JOIN {$wpdb->posts} p ON p.ID = pm.post_id
WHERE p.post_type = %s
AND pm.meta_key = %s
AND pm.meta_value != ''
LIMIT 1",
'fusion_form',
'f12-cf7-doubleoptin'
);
return (int) $wpdb->get_var( $sql ) > 0;
}
private static function isCore5OrLater(): bool {
if ( ! defined( 'FORGE12_OPTIN_VERSION' ) ) {
return false;
}
return version_compare( FORGE12_OPTIN_VERSION, '5.0.0', '>=' );
}
}