diff --git a/includes/admin/class-dt-import.php b/includes/admin/class-dt-import.php index 4ef94e0..9c7f435 100644 --- a/includes/admin/class-dt-import.php +++ b/includes/admin/class-dt-import.php @@ -50,6 +50,11 @@ class DT_Import { * @var string */ private $post_label_plural = ''; + /** + * This array stores the required fields for a given post type. + * @var array + */ + private $required_fields = []; /** * DT_Import constructor. @@ -104,6 +109,11 @@ public function __construct( $post_type ) { 'comments' ]; + $this->required_fields = [ + 'common_fields' => [ // Common fields across post_types. + 'name' + ] + ]; } private function dt_sanitize_post_request_array_field( $post, $key ) { @@ -174,7 +184,7 @@ private function main_column() { 'assigned_to' => $file_assigned_to, 'data' => $this->mapping_process( $temp_name ), 'selected_geocode_api' => $selected_geocode_api, - 'check_for_duplicates' => isset( $_POST['check_for_duplicates'] ), + 'check_for_duplicates' => isset( $_POST['check_for_duplicates'] ) ]; set_transient( 'disciple_tools_import_settings', $import_settings, 3600 * 24 ); @@ -910,6 +920,15 @@ public function preview( $mapping_data = [], $value_mapperi_data = [], $value_ma $mapped_data = $this->process_data( $import_settings, $mapping_data, $value_mapperi_data, $value_mapper_data ); set_transient( 'disciple_tools_import_settings', $import_settings, 3600 * 24 ); + + /** + * Ensure required fields are present. + */ + + $has_required_fields = true; + if ( !empty( $this->required_fields['common_fields'] ) ) { + $has_required_fields = count( array_intersect( $this->required_fields['common_fields'], $mapping_data ) ) > 0; + } ?> @@ -921,25 +940,50 @@ public function preview( $mapping_data = [], $value_mapperi_data = [], $value_ma @@ -1630,7 +1674,7 @@ public function display_data( $data ) { $ch ) {
+ display_data( $mapped_data ); - display_data( $mapped_data );?> + ?> +
+ - + - + /> - +
+ /> + } else { + ?> + +
+
    + required_fields['common_fields'] ?? [] as $field ) { + ?> +
  1. post_field_settings[$field]['name'] ?? $field ); ?>
  2. + +
+
+
-
+ + + +
- +