From b7c6bb79e7987fc33870fb369db01399b5bd93b4 Mon Sep 17 00:00:00 2001 From: Viktor Miller Date: Wed, 4 Feb 2026 13:37:20 +0900 Subject: [PATCH] fix: repair job_type dropdown options and remove job_logo from forms The job_type select field had empty options because Formidable stores them in a top-level `options` key, not nested inside `field_options`. The job_logo field is removed from both submission and edit forms since the logo is managed per-provider on the dashboard. Includes a one-time repair migration that fixes existing fields in the database (updates job_type options, deletes job_logo fields). Co-Authored-By: Claude Opus 4.5 --- includes/class-acf-fields.php | 11 ---- includes/class-formidable.php | 108 +++++++++++++++++----------------- 2 files changed, 54 insertions(+), 65 deletions(-) diff --git a/includes/class-acf-fields.php b/includes/class-acf-fields.php index b7204ca..2c30d26 100644 --- a/includes/class-acf-fields.php +++ b/includes/class-acf-fields.php @@ -68,17 +68,6 @@ class DDHH_JM_ACF_Fields { 'type' => 'email', 'required' => 1, ), - // Job Logo - array( - 'key' => 'field_job_logo', - 'label' => __( 'Logo', 'ddhh-job-manager' ), - 'name' => 'job_logo', - 'type' => 'image', - 'required' => 0, - 'return_format' => 'id', - 'preview_size' => 'thumbnail', - 'library' => 'all', - ), // Job Deactivation Reason (internal, admin-only) array( 'key' => 'field_job_deactivation_reason', diff --git a/includes/class-formidable.php b/includes/class-formidable.php index 634d67d..4acb257 100644 --- a/includes/class-formidable.php +++ b/includes/class-formidable.php @@ -156,6 +156,7 @@ class DDHH_JM_Formidable { add_action( 'init', array( __CLASS__, 'create_registration_form' ), 11 ); add_action( 'init', array( __CLASS__, 'create_job_submission_form' ), 11 ); add_action( 'init', array( __CLASS__, 'create_job_edit_form' ), 11 ); + add_action( 'init', array( __CLASS__, 'repair_job_form_fields' ), 12 ); add_action( 'init', array( __CLASS__, 'create_job_deactivation_form' ), 11 ); add_action( 'init', array( __CLASS__, 'create_job_application_form' ), 11 ); @@ -808,19 +809,13 @@ class DDHH_JM_Formidable { 'field_order' => 3, ), array( - 'name' => 'Art', - 'field_key' => 'job_type', - 'type' => 'select', - 'required' => '1', - 'form_id' => $form_id, - 'field_order' => 4, - 'field_options' => array( - 'options' => array( - 'Vollzeit' => 'Vollzeit', - 'Teilzeit' => 'Teilzeit', - 'Ehrenamt' => 'Ehrenamt', - ), - ), + 'name' => 'Art', + 'field_key' => 'job_type', + 'type' => 'select', + 'required' => '1', + 'form_id' => $form_id, + 'field_order' => 4, + 'options' => array( '', 'Vollzeit', 'Teilzeit', 'Ehrenamt' ), ), array( 'name' => 'Bewerbungsfrist', @@ -841,19 +836,6 @@ class DDHH_JM_Formidable { 'form_id' => $form_id, 'field_order' => 6, ), - array( - 'name' => 'Logo', - 'field_key' => 'job_logo', - 'type' => 'file', - 'required' => '0', - 'form_id' => $form_id, - 'field_order' => 7, - 'field_options' => array( - 'restrict' => '1', - 'allowed_types' => 'image/jpeg,image/png', - 'max_size' => '2', - ), - ), ); // Store field IDs for form action mapping @@ -879,7 +861,6 @@ class DDHH_JM_Formidable { array( 'meta_name' => 'job_type', 'field_id' => $field_ids['job_type'] ), array( 'meta_name' => 'job_deadline', 'field_id' => $field_ids['job_deadline'] ), array( 'meta_name' => 'job_contact_email', 'field_id' => $field_ids['job_contact_email'] ), - array( 'meta_name' => 'job_logo', 'field_id' => $field_ids['job_logo'] ), ); $action_control->save_settings( $new_action ); } @@ -950,19 +931,13 @@ class DDHH_JM_Formidable { 'field_order' => 3, ), array( - 'name' => 'Art', - 'field_key' => 'job_type', - 'type' => 'select', - 'required' => '1', - 'form_id' => $form_id, - 'field_order' => 4, - 'field_options' => array( - 'options' => array( - 'Vollzeit' => 'Vollzeit', - 'Teilzeit' => 'Teilzeit', - 'Ehrenamt' => 'Ehrenamt', - ), - ), + 'name' => 'Art', + 'field_key' => 'job_type', + 'type' => 'select', + 'required' => '1', + 'form_id' => $form_id, + 'field_order' => 4, + 'options' => array( '', 'Vollzeit', 'Teilzeit', 'Ehrenamt' ), ), array( 'name' => 'Bewerbungsfrist', @@ -983,19 +958,6 @@ class DDHH_JM_Formidable { 'form_id' => $form_id, 'field_order' => 6, ), - array( - 'name' => 'Logo', - 'field_key' => 'job_logo', - 'type' => 'file', - 'required' => '0', - 'form_id' => $form_id, - 'field_order' => 7, - 'field_options' => array( - 'restrict' => '1', - 'allowed_types' => 'image/jpeg,image/png', - 'max_size' => '2', - ), - ), ); // Store field IDs for form action mapping @@ -1021,12 +983,50 @@ class DDHH_JM_Formidable { array( 'meta_name' => 'job_type', 'field_id' => $field_ids['job_type'] ), array( 'meta_name' => 'job_deadline', 'field_id' => $field_ids['job_deadline'] ), array( 'meta_name' => 'job_contact_email', 'field_id' => $field_ids['job_contact_email'] ), - array( 'meta_name' => 'job_logo', 'field_id' => $field_ids['job_logo'] ), ); $action_control->save_settings( $new_action ); } } + /** + * Repair existing job form fields in the database. + * + * Fixes the job_type select options and removes the job_logo field + * from both the submission and edit forms. Runs once and stores a + * version flag in wp_options to avoid re-running. + */ + public static function repair_job_form_fields() { + if ( ! class_exists( 'FrmField' ) ) { + return; + } + + $repair_version = '1'; + if ( get_option( 'ddhh_jm_form_repair_version' ) === $repair_version ) { + return; + } + + // Fix job_type options on both forms. + $correct_options = array( '', 'Vollzeit', 'Teilzeit', 'Ehrenamt' ); + foreach ( array( 'job_type', 'job_type2' ) as $key ) { + $field = FrmField::getOne( $key ); + if ( $field ) { + FrmField::update( $field->id, array( + 'options' => serialize( $correct_options ), + ) ); + } + } + + // Remove job_logo fields from both forms. + foreach ( array( 'job_logo', 'job_logo2' ) as $key ) { + $field = FrmField::getOne( $key ); + if ( $field ) { + FrmField::destroy( $field->id ); + } + } + + update_option( 'ddhh_jm_form_repair_version', $repair_version ); + } + /** * Pre-populate edit form fields with existing post data *