@@ -545,18 +545,11 @@ private function edit_field( $field_key, $post_type ){
545545 <?php
546546 $ custom_fields = dt_get_option ( 'dt_field_customizations ' );
547547 $ custom_field = $ custom_fields [ $ post_type ][ $ field_key ] ?? [];
548- $ accepted_file_types = $ custom_field ['accepted_file_types ' ] ?? [
549- 'image/* ' ,
550- 'application/pdf ' ,
551- 'audio/* ' ,
552- 'video/* ' ,
553- 'application/msword ' ,
554- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document ' ,
555- 'application/vnd.ms-excel ' ,
556- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ' ,
557- 'text/plain ' ,
558- 'text/markdown ' ,
559- ];
548+ $ file_type_categories = dt_get_file_type_categories ();
549+ $ has_stored_types = isset ( $ custom_field ['accepted_file_types ' ] );
550+ $ stored_types = $ custom_field ['accepted_file_types ' ] ?? [];
551+ $ all_category_types = array_merge ( ...array_column ( $ file_type_categories , 'types ' ) );
552+ $ other_types = $ has_stored_types ? array_values ( array_diff ( $ stored_types , $ all_category_types ) ) : [];
560553 $ max_file_size = $ custom_field ['max_file_size ' ] ?? '' ;
561554 $ delete_enabled = isset ( $ custom_field ['delete_enabled ' ] ) ? $ custom_field ['delete_enabled ' ] : true ;
562555 $ display_layout = $ custom_field ['display_layout ' ] ?? 'grid ' ;
@@ -567,19 +560,32 @@ private function edit_field( $field_key, $post_type ){
567560 <h3><?php esc_html_e ( 'Field Options ' , 'disciple_tools ' ) ?> </h3>
568561 <table id="file_upload_options">
569562 <tr>
570- <td style="vertical-align: middle ">
571- <label for="accepted_file_types">< b><?php esc_html_e ( 'Accepted File Types ' , 'disciple_tools ' ) ?> </b></label >
563+ <td style="vertical-align: top ">
564+ <b><?php esc_html_e ( 'Accepted File Types ' , 'disciple_tools ' ) ?> </b>
572565 </td>
573566 <td>
574- <input type="text" name="accepted_file_types" id="accepted_file_types"
575- value="<?php echo esc_attr ( implode ( ', ' , $ accepted_file_types ) ) ?> "
576- placeholder="e.g., image/*, audio/*, video/*, application/pdf, .docx"
577- style="width: 100%;" />
567+ <?php foreach ( $ file_type_categories as $ cat_key => $ cat ) :
568+ $ is_checked = ! $ has_stored_types || empty ( array_diff ( $ cat ['types ' ], $ stored_types ) );
569+ ?>
570+ <label style="margin-right: 1em;">
571+ <input type="checkbox" name="accepted_file_categories[]"
572+ value="<?php echo esc_attr ( $ cat_key ) ?> "
573+ <?php echo $ is_checked ? 'checked ' : '' ; ?> >
574+ <?php echo esc_html ( $ cat ['label ' ] ) ?>
575+ </label>
576+ <?php endforeach ; ?>
577+ <div style="margin-top: 6px;">
578+ <label for="other_file_types"><b><?php esc_html_e ( 'Other ' , 'disciple_tools ' ) ?> </b></label>
579+ <input type="text" name="other_file_types" id="other_file_types"
580+ value="<?php echo esc_attr ( implode ( ', ' , $ other_types ) ) ?> "
581+ placeholder="<?php esc_attr_e ( 'e.g., application/zip, .csv ' , 'disciple_tools ' ) ?> "
582+ style="width: 100%;" />
583+ <p style="font-size: 11px; color: #666; margin-top: 3px;">
584+ <?php esc_html_e ( 'Comma-separated MIME types or file extensions for additional file types. ' , 'disciple_tools ' ); ?>
585+ </p>
586+ </div>
578587 <p style="font-size: 11px; color: #666; margin-top: 5px;">
579- <?php esc_html_e ( 'Optional. Comma-separated list of MIME types or file extensions to override the default set (images, PDFs, audio, video, common documents). Leave empty to use the default types. ' , 'disciple_tools ' ); ?>
580- <a href="<?php echo esc_url ( 'https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types ' ); ?> " target="_blank" rel="noopener noreferrer">
581- <?php esc_html_e ( 'View common MIME types. ' , 'disciple_tools ' ); ?>
582- </a>
588+ <?php esc_html_e ( 'Select which file type categories are allowed for upload. If none are selected, all types will be accepted. ' , 'disciple_tools ' ); ?>
583589 </p>
584590 </td>
585591 </tr>
@@ -1045,16 +1051,33 @@ private function process_edit_field( $post_submission ){
10451051
10461052 // file_upload field options
10471053 if ( $ field ['type ' ] === 'file_upload ' ) {
1048- // Accepted file types
1049- if ( isset ( $ post_submission ['accepted_file_types ' ] ) ) {
1050- $ raw_accepted = trim ( $ post_submission ['accepted_file_types ' ] );
1051- if ( $ raw_accepted === '' ) {
1052- // Clear any previously saved override so defaults are used
1053- unset( $ custom_field ['accepted_file_types ' ] );
1054- } else {
1055- $ types = array_map ( 'sanitize_text_field ' , array_map ( 'trim ' , explode ( ', ' , $ raw_accepted ) ) );
1056- $ custom_field ['accepted_file_types ' ] = $ types ;
1054+ // Accepted file types from category checkboxes
1055+ $ category_mime_map = array_map ( function ( $ cat ) {
1056+ return $ cat ['types ' ];
1057+ }, dt_get_file_type_categories () );
1058+ $ selected_categories = isset ( $ post_submission ['accepted_file_categories ' ] )
1059+ ? array_map ( 'sanitize_text_field ' , $ post_submission ['accepted_file_categories ' ] )
1060+ : [];
1061+
1062+ $ raw_other = isset ( $ post_submission ['other_file_types ' ] ) ? trim ( $ post_submission ['other_file_types ' ] ) : '' ;
1063+ $ other_types = $ raw_other !== ''
1064+ ? array_map ( 'sanitize_text_field ' , array_map ( 'trim ' , explode ( ', ' , $ raw_other ) ) )
1065+ : [];
1066+
1067+ $ all_categories_selected = count ( $ selected_categories ) === count ( $ category_mime_map );
1068+ if ( $ all_categories_selected && empty ( $ other_types ) ) {
1069+ unset( $ custom_field ['accepted_file_types ' ] );
1070+ } else if ( empty ( $ selected_categories ) && empty ( $ other_types ) ) {
1071+ unset( $ custom_field ['accepted_file_types ' ] );
1072+ } else {
1073+ $ types = [];
1074+ foreach ( $ selected_categories as $ cat_key ) {
1075+ if ( isset ( $ category_mime_map [ $ cat_key ] ) ) {
1076+ $ types = array_merge ( $ types , $ category_mime_map [ $ cat_key ] );
1077+ }
10571078 }
1079+ $ types = array_merge ( $ types , $ other_types );
1080+ $ custom_field ['accepted_file_types ' ] = $ types ;
10581081 }
10591082
10601083 // Max file size
0 commit comments