Hi, Chang! Thanks for a quick reply!
Well, maybe, it’s not concerns or question, it’s more like a suggestions, but I don’t know, where can I propose it.
So, in admin/settings/class-simple-board-settings-upload-file-extensions.php from line 79
do_action('sjb_file_extension_options_start');
till
do_action('sjb_file_extension_options_end');
are extension checkboxes.
I wanna add ppt and pptx support, so I’ve simply copied one of the form-field, replace all extensions and hooked into ‘sjb_file_extension_options_start’. It works fine, but I think, all extensions should be in array and loop them throw foreach like this
<?php
/**
* Action -> Add new extension at the start of list.
*
* @since 2.8.3
*/
do_action('sjb_file_extension_options_start');
?>
<?php
$exts = ['pdf', 'doc', 'docx', 'odt', 'rtf', 'txt']; // Default
$exts = apply_filters('sjb_available_exts', $exts);
$exts = array_map('esc_html', $exts);
$exts = array_unique($exts);
foreach( $exts as $ext ) { ?>
<div class="sjb-form-group sjb-extensions">
<?php
if( FALSE !== get_option('job_board_all_extensions_check')){
if( 'no' === get_option('job_board_all_extensions_check') ){
if( FALSE !== get_option('job_board_upload_file_ext')){
if(in_array($ext, get_option('job_board_upload_file_ext'))){
$selected = 'checked';
}
else{
$selected = '';
}
}
else{
$selected = 'checked';
}
}
else{
$selected = 'checked';
}
}
else{
$selected = 'checked';
}
if( file_exists(plugin_dir_url(dirname(dirname(__FILE__))) . 'admin/images/' . $ext . '.png') ) {
$icon = 'admin/images/' . $ext . '.png';
} else {
$icon = 'admin/images/doc.png'; // Backup icon for unknown extension
}
?>
<input type="checkbox" id="upload_file_ext_<?php echo $ext; ?>" name="file_extensions[]" value="<?php echo $ext; ?>" <?php echo $selected; ?>>
<input type="hidden" name="upload_file_ext_<?php echo $ext; ?>" value="upload_file_ext_<?php echo $ext; ?>">
<label for="upload_file_ext_<?php echo $ext; ?>">
<img src="<?php echo plugin_dir_url(dirname(dirname(__FILE__))) . $icon ?>">
<span><?php echo esc_html( $ext ); ?></span>
</label>
</div>
<?php }
/**
* Action -> Add new extension at the end of list.
*
* @since 2.2.0
*/
do_action('sjb_file_extension_options_end');
In that case all I need to do in my functions.php is
function add_powerpoint_extensions($exts) {
$new_exts = ['pptx', 'ppt'];
return array_merge($exts, $new_exts);
}
add_filter( 'sjb_available_exts', 'add_powerpoint_extensions');
Which is much easier.
Also there is a little UX-problem – when ‘all extensions’-checkbox is checked (true === job_board_all_extensions_check), I still able to uncheck any extension and when I hit save, it still checked, because ‘all extensions’ is overwriting it. It’s a little bit confusing. So I have to uncheck ‘all extensions’ first, and then uncheck my unneeded extension.
I guess, it possible to add ‘change’-event on input in js, which will set #all-file-ext checked property to false or something similar to that.