'adfoin',
'show_status' => true,
'modal_title' => sprintf( __( 'Connect %s', 'advanced-form-integration' ), $title ),
'submit_text' => __( 'Save & Authorize', 'advanced-form-integration' ),
) );
$nonce = wp_create_nonce( 'advanced-form-integration' );
?>
$credential ) {
if ( isset( $credential['id'] ) && $credential['id'] === $new_credentials['id'] ) {
$credentials[ $index ] = array_merge( $credential, $new_credentials );
$updated = true;
break;
}
}
// Add new credential if not updating
if ( ! $updated ) {
$credentials[] = $new_credentials;
}
return update_option( $option_name, $credentials );
}
/**
* Update specific credentials by ID.
*
* @param string $platform Platform slug.
* @param string $id Credential ID.
* @param array $updated_data Updated credential data.
* @return bool True on success, false on failure.
*/
public static function update_credentials( $platform, $id, $updated_data ) {
$option_name = 'adfoin_' . $platform . '_credentials';
$credentials = self::get_credentials( $platform );
foreach ( $credentials as $index => $credential ) {
if ( isset( $credential['id'] ) && $credential['id'] === $id ) {
$credentials[ $index ] = array_merge( $credential, $updated_data );
return update_option( $option_name, $credentials );
}
}
return false;
}
/**
* Outputs the HTML/JS to close the OAuth popup and notify the parent window.
*
* @param bool $success Whether the authorization was successful.
* @param string $message Optional message to send back.
*/
public static function handle_callback_close_popup( $success = true, $message = '' ) {
$status = $success ? 'success' : 'error';
$safe_message = esc_js( $message );
if ( ! headers_sent() ) {
header( 'Content-Type: text/html; charset=utf-8' );
}
echo '
Authorization ' . ucfirst($status) . '
' . ($success ? 'Authorization Successful!' : 'Authorization Failed') . '
' . esc_html( $message ) . '
This window will close automatically...
';
exit;
}
}