add_action( 'bricks/form/custom_action', function( $form ) { $fields = $form->get_fields(); // 1. Map Text Fields (Ensures we handle prefixes correctly) $email = $fields['form-field-567c3b'] ?? ''; $first_name = $fields['form-field-22edfb'] ?? ''; $last_name = $fields['form-field-kpipky'] ?? ''; $phone = $fields['form-field-noxrbn'] ?? ''; $company = $fields['form-field-kbywak'] ?? ''; if ( empty( $email ) ) return; // 2. Create the User $password = wp_generate_password( 12, true ); $user_id = wp_create_user( $email, $password, $email ); if ( is_wp_error( $user_id ) ) { $form->set_result([ 'action' => 'register_magtex_distributor', 'type' => 'danger', 'message' => 'Error: ' . $user_id->get_error_message(), ]); return; } // 3. Update Standard & Custom User Meta wp_update_user([ 'ID' => $user_id, 'first_name' => $first_name, 'last_name' => $last_name, 'role' => 'distribuidor-magtex' ]); update_user_meta( $user_id, 'dist_company_name', $company ); update_user_meta( $user_id, 'dist_phone', $phone ); update_user_meta( $user_id, 'is_approved', '0' ); // 4. Handle File Binding using attachment_url_to_postid $uploaded_files = $form->get_uploaded_files(); // Mapping Bricks Field IDs to Meta Box Meta Keys $file_mapping = [ 'form-field-csmohn' => 'constancia_de_situacion_fiscal', 'form-field-gwimhu' => 'ine' ]; foreach ( $uploaded_files as $field_id => $files ) { if ( isset( $file_mapping[$field_id] ) ) { $meta_key = $file_mapping[$field_id]; foreach ( $files as $file ) { // Bricks has already moved the file to the uploads folder. // We construct the URL to find its ID in the database. $upload_dir = wp_upload_dir(); $file_url = $upload_dir['url'] . '/' . sanitize_file_name($file['name']); // Lookup the ID based on the URL $attachment_id = attachment_url_to_postid( $file_url ); if ( $attachment_id ) { // Force the binding as a single integer for Meta Box "File" type update_user_meta( $user_id, $meta_key, (int) $attachment_id ); error_log("MAGTEX BINDING SUCCESS: ID $attachment_id linked to $meta_key"); } else { error_log("MAGTEX BINDING ERROR: Could not find ID for URL $file_url"); } } } } $form->set_result([ 'action' => 'register_magtex_distributor', 'type' => 'success', 'message' => '¡Registro exitoso! Validaremos tu información y documentos pronto.', ]); }, 10, 1 ); Playera Cuello Redondo Manga Larga - MAGTEX

Playera Cuello Redondo Manga Larga