Participants Database - Source Excerpt 02
Summary
This source excerpt preserves a bounded section of Anti-Christ.org/wp-content/plugins/fftac-foundation-core/inc/participants-database.php so readers can inspect the evidence without opening the full source file.
**Source path:** Anti-Christ.org/wp-content/plugins/fftac-foundation-core/inc/participants-database.php
foreach (antichrist_engine_foundation_participants_database_expected_fields() as $field_name => $definition) {
if (antichrist_engine_foundation_participants_database_field_exists($field_name)) {
continue;
}
$definition['name'] = $field_name;
$definition['validation'] = $definition['validation'] ?? 'no';
if (Participants_Db::add_blank_field($definition)) {
$result['added']++;
antichrist_engine_foundation_participants_database_flush_field_cache();
}
}
foreach (array_keys(antichrist_engine_foundation_participants_database_expected_fields()) as $field_name) {
if (!antichrist_engine_foundation_participants_database_field_exists($field_name)) {
$result['missing'][] = $field_name;
}
}
return $result;
}
/**
* Bootstraps the bridge after Participants Database initializes.
*
* @return void
*/
function antichrist_engine_foundation_participants_database_bootstrap()
{
antichrist_engine_foundation_participants_database_ensure_schema();
}
add_action('participants-database_initialized', 'antichrist_engine_foundation_participants_database_bootstrap', 20);
/**
* Splits a display name into fields Participants Database already understands.
*
* @param string $name Display name.
* @return array<string, string>
*/
function antichrist_engine_foundation_participants_database_split_name($name)
{
$name = antichrist_engine_security_sanitize_text_field($name, 120);
if ('' === $name) {
return array();
}
$parts = preg_split('/\s+/', $name) ?: array();
$parts = array_values(array_filter($parts, static function ($part) {
return '' !== trim((string) $part);
}));
if (1 === count($parts)) {
return array('first_name' => $parts[0]);
}
$last_name = array_pop($parts);
return array(
'first_name' => implode(' ', $parts),
'last_name' => (string) $last_name,
);
}
/**
* Resolves a WordPress user object for participant profile mirroring.
*
* @param int|WP_User $user User ID or object.
* @return WP_User|null
*/
function antichrist_engine_foundation_participants_database_get_user($user)
{
if ($user instanceof WP_User) {
return $user;
}
$user_id = absint($user);
if (!$user_id) {
return null;
}
if (function_exists('get_userdata')) {
$resolved_user = get_userdata($user_id);
if ($resolved_user instanceof WP_User) {
return $resolved_user;
}
}
$resolved_user = get_user_by('id', $user_id);
return $resolved_user instanceof WP_User ? $resolved_user : null;
}
/**
* Builds the Participants Database payload for one WordPress member profile.
*
* @param int|WP_User $user User ID or object.
* @return array<string, string>
*/
function antichrist_engine_foundation_participants_database_build_member_payload($user)
{
$user = antichrist_engine_foundation_participants_database_get_user($user);
if (!$user instanceof WP_User || empty($user->ID)) {
return array();
}
$user_login = antichrist_engine_security_sanitize_text_field((string) ($user->user_login ?? ''), 120);
$display_name = antichrist_engine_security_sanitize_text_field((string) ($user->display_name ?? ''), 120);
$description = antichrist_engine_security_sanitize_textarea_field((string) ($user->description ?? ''), 1000);
$registered_at = antichrist_engine_security_sanitize_text_field((string) ($user->user_registered ?? ''), 80);
$status = user_can($user, 'edit_posts') ? __('Staff account', 'antichrist-engine') : __('Active member', 'antichrist-engine');
$payload = array(
'first_name' => antichrist_engine_security_sanitize_text_field((string) ($user->first_name ?? ''), 80),
'last_name' => antichrist_engine_security_sanitize_text_field((string) ($user->last_name ?? ''), 80),
'email' => antichrist_engine_security_sanitize_email_field((string) ($user->user_email ?? ''), 190),
'fftac_site_project' => 'Anti-Christ.org',
'fftac_record_kind' => 'Member profile',
'fftac_member_record_id' => 'member:' . (int) $user->ID,
'fftac_wp_user_id' => (string) (int) $user->ID,
'fftac_wp_user_login' => $user_login,
'fftac_member_status' => antichrist_engine_security_sanitize_text_field($status, 80),
'fftac_member_registered_at' => $registered_at,
'fftac_member_public_alias' => $display_name ?: $user_login,
'fftac_member_profile_summary' => $description,
);
return array_filter($payload, static function ($value) {
return '' !== (string) $value;
});
}
/**
* Builds the Participants Database payload for one local intake post.
*
* @param int $post_id Local private intake post ID.
* @param string $source_key Intake source key.
* @return array<string, string>
*/
function antichrist_engine_foundation_participants_database_build_payload($post_id, $source_key)
{
$post = get_post($post_id);
if (!$post instanceof WP_Post) {
return array();
}
$source_key = antichrist_engine_foundation_normalize_intake_source_key($source_key);
if ('all' === $source_key) {
return array();
}
$row = antichrist_engine_foundation_get_intake_export_row($post, $source_key);
$name = (string) ($row['name'] ?? '');
$payload = antichrist_engine_foundation_participants_database_split_name($name);
$record_key = $source_key . ':' . (int) $post_id;
$message = (string) ($row['message'] ?? '');
$notes = (string) ($row['notes'] ?? '');
$payload['email'] = antichrist_engine_security_sanitize_email_field((string) ($row['email'] ?? ''), 190);
$payload['fftac_site_project'] = 'Anti-Christ.org';
$payload['fftac_record_kind'] = 'Intake mirror';
$payload['fftac_intake_source'] = antichrist_engine_security_sanitize_text_field((string) ($row['intake_source'] ?? ''), 120);
$payload['fftac_intake_record_id'] = antichrist_engine_security_sanitize_text_field($record_key, 120);
$payload['fftac_intake_post_id'] = (string) (int) $post_id;
$payload['fftac_intake_lane'] = antichrist_engine_security_sanitize_text_field((string) ($row['lane'] ?? ''), 180);
$payload['fftac_intake_context'] = antichrist_engine_security_sanitize_text_field((string) ($row['context'] ?? ''), 180);
$payload['fftac_intake_subject'] = antichrist_engine_security_sanitize_text_field((string) ($row['subject'] ?? ''), 180);
$payload['fftac_intake_message'] = antichrist_engine_security_sanitize_textarea_field($message, 2000);
$payload['fftac_intake_notes'] = antichrist_engine_security_sanitize_textarea_field($notes, 2000);
if ('signals' === $source_key) {
$payload['mailing_list'] = 'Yes';
}
return array_filter($payload, static function ($value) {
return '' !== (string) $value;
});
}
/**
* Looks up an existing Participants Database mirror record for one intake post.
*
* @param int $post_id Local private intake post ID.
* @param string $source_key Intake source key.
* @return int
*/
function antichrist_engine_foundation_participants_database_get_record_id($post_id, $source_key)
{
$stored_id = absint(get_post_meta((int) $post_id, '_antichrist_participants_database_id', true));
if ($stored_id && class_exists('Participants_Db') && method_exists('Participants_Db', 'id_exists') && Participants_Db::id_exists($stored_id)) {
return $stored_id;
}
$record_key = antichrist_engine_foundation_normalize_intake_source_key($source_key) . ':' . (int) $post_id;
if (!antichrist_engine_foundation_participants_database_field_exists('fftac_intake_record_id')) {
return 0;
}
global $wpdb;
if (is_object($wpdb) && class_exists('Participants_Db') && method_exists($wpdb, 'get_var') && method_exists($wpdb, 'prepare')) {
$record_id = $wpdb->get_var($wpdb->prepare(
'SELECT `id` FROM ' . Participants_Db::participants_table() . ' WHERE `fftac_intake_record_id` = %s LIMIT 1',
$record_key
));
if ($record_id) {
return (int) $record_id;
}
}
return 0;
}
/**
* Looks up an existing Participants Database mirror record for one member.
*
* @param int|WP_User $user User ID or object.
* @return int
*/
function antichrist_engine_foundation_participants_database_get_member_record_id($user)
{
$user = antichrist_engine_foundation_participants_database_get_user($user);
if (!$user instanceof WP_User || empty($user->ID)) {
return 0;
}
$stored_id = absint(get_user_meta((int) $user->ID, '_antichrist_member_participants_database_id', true));