Participants Database - Source Excerpt 03
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
if ($stored_id && class_exists('Participants_Db') && method_exists('Participants_Db', 'id_exists') && Participants_Db::id_exists($stored_id)) {
return $stored_id;
}
$record_key = 'member:' . (int) $user->ID;
if (!antichrist_engine_foundation_participants_database_field_exists('fftac_member_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_member_record_id` = %s LIMIT 1',
$record_key
));
if ($record_id) {
return (int) $record_id;
}
}
return 0;
}
/**
* Mirrors one WordPress member profile into Participants Database.
*
* @param int|WP_User $user User ID or object.
* @return array<string, mixed>
*/
function antichrist_engine_foundation_participants_database_sync_member($user)
{
$user = antichrist_engine_foundation_participants_database_get_user($user);
if (!$user instanceof WP_User || empty($user->ID)) {
return array('status' => 'skipped', 'message' => 'Missing WordPress user.');
}
$user_id = (int) $user->ID;
if (!antichrist_engine_foundation_participants_database_is_available()) {
update_user_meta($user_id, '_antichrist_member_participants_database_status', 'unavailable');
return array('status' => 'unavailable', 'message' => 'Participants Database is not active.');
}
antichrist_engine_foundation_participants_database_ensure_schema();
$payload = antichrist_engine_foundation_participants_database_build_member_payload($user);
if (!$payload) {
update_user_meta($user_id, '_antichrist_member_participants_database_status', 'empty');
return array('status' => 'skipped', 'message' => 'No member payload could be built.');
}
$record_id = antichrist_engine_foundation_participants_database_get_member_record_id($user);
$saved_id = Participants_Db::write_participant($payload, $record_id ?: '', 'FFTAC Anti-Christ.org member profile sync');
if (!$saved_id) {
update_user_meta($user_id, '_antichrist_member_participants_database_status', 'failed');
update_user_meta($user_id, '_antichrist_member_participants_database_error', 'Participants Database write_participant returned false.');
return array('status' => 'failed', 'message' => 'Participants Database member write failed.');
}
update_user_meta($user_id, '_antichrist_member_participants_database_id', (int) $saved_id);
update_user_meta($user_id, '_antichrist_member_participants_database_record_key', 'member:' . $user_id);
update_user_meta($user_id, '_antichrist_member_participants_database_status', 'synced');
update_user_meta($user_id, '_antichrist_member_participants_database_error', '');
update_user_meta($user_id, '_antichrist_member_participants_database_synced_at', gmdate(DATE_ATOM));
return array('status' => 'synced', 'record_id' => (int) $saved_id);
}
/**
* Syncs WordPress members to the roster mirror when accounts are created or edited.
*
* @param int $user_id WordPress user ID.
* @return void
*/
function antichrist_engine_foundation_participants_database_sync_member_hook($user_id)
{
antichrist_engine_foundation_participants_database_sync_member((int) $user_id);
}
add_action('user_register', 'antichrist_engine_foundation_participants_database_sync_member_hook', 20);
add_action('profile_update', 'antichrist_engine_foundation_participants_database_sync_member_hook', 20);
/**
* Returns front-end status details for one member's Participants Database mirror.
*
* @param int|WP_User $user User ID or object.
* @return array<string, mixed>
*/
function antichrist_engine_foundation_participants_database_get_member_status($user)
{
$user = antichrist_engine_foundation_participants_database_get_user($user);
if (!$user instanceof WP_User || empty($user->ID)) {
return array(
'status' => 'attention',
'summary' => __('No member account could be resolved for the participant mirror.', 'antichrist-engine'),
'action' => __('Sign in again before updating profile details.', 'antichrist-engine'),
);
}
$user_id = (int) $user->ID;
$installed = antichrist_engine_foundation_participants_database_is_installed();
$available = antichrist_engine_foundation_participants_database_is_available();
$stored_status = sanitize_key((string) get_user_meta($user_id, '_antichrist_member_participants_database_status', true));
$record_id = absint(get_user_meta($user_id, '_antichrist_member_participants_database_id', true));
$record_key = (string) get_user_meta($user_id, '_antichrist_member_participants_database_record_key', true);
$synced_at = (string) get_user_meta($user_id, '_antichrist_member_participants_database_synced_at', true);
$error = (string) get_user_meta($user_id, '_antichrist_member_participants_database_error', true);
if (!$available) {
return array(
'installed' => $installed,
'available' => false,
'status' => 'attention',
'record_id' => $record_id,
'record_key' => $record_key,
'synced_at' => $synced_at,
'summary' => $installed
? __('Participants Database is installed, but not active for member profile mirroring.', 'antichrist-engine')
: __('Participants Database is not installed, so member profiles stay in WordPress only.', 'antichrist-engine'),
'action' => __('Activate Participants Database to mirror member profiles into the working roster.', 'antichrist-engine'),
);
}
if ('synced' === $stored_status && $record_id) {
return array(
'installed' => $installed,
'available' => $available,
'status' => 'ready',
'record_id' => $record_id,
'record_key' => $record_key,
'synced_at' => $synced_at,
'summary' => sprintf(
/* translators: %d is the Participants Database record ID. */
__('Participant profile mirror is linked to roster record #%d.', 'antichrist-engine'),
$record_id
),
'action' => __('Profile saves will refresh the roster mirror automatically.', 'antichrist-engine'),
);
}
return array(
'installed' => $installed,
'available' => $available,
'status' => 'attention',
'record_id' => $record_id,
'record_key' => $record_key,
'synced_at' => $synced_at,
'summary' => $error
? sprintf(
/* translators: %s is the latest Participants Database sync error. */
__('Participant profile mirror needs review: %s', 'antichrist-engine'),
$error
)
: __('Participant profile mirror has not synced yet.', 'antichrist-engine'),
'action' => __('Save the profile again or run the Participants Database backfill from launch readiness.', 'antichrist-engine'),
);
}
/**
* Mirrors one local private intake post into Participants Database.
*
* @param int $post_id Local private intake post ID.
* @param string $source_key Intake source key.
* @return array<string, mixed>
*/
function antichrist_engine_foundation_participants_database_sync_intake_post($post_id, $source_key)
{
$post_id = absint($post_id);
$source_key = antichrist_engine_foundation_normalize_intake_source_key($source_key);
if (!$post_id || 'all' === $source_key) {
return array('status' => 'skipped', 'message' => 'Missing intake post or source.');
}
if (!antichrist_engine_foundation_participants_database_is_available()) {
update_post_meta($post_id, '_antichrist_participants_database_status', 'unavailable');
return array('status' => 'unavailable', 'message' => 'Participants Database is not active.');
}
antichrist_engine_foundation_participants_database_ensure_schema();
$payload = antichrist_engine_foundation_participants_database_build_payload($post_id, $source_key);
if (!$payload) {
update_post_meta($post_id, '_antichrist_participants_database_status', 'empty');
return array('status' => 'skipped', 'message' => 'No intake payload could be built.');
}
$record_id = antichrist_engine_foundation_participants_database_get_record_id($post_id, $source_key);
$saved_id = Participants_Db::write_participant($payload, $record_id ?: '', 'FFTAC Anti-Christ.org intake sync');