Changeset 3455110
- Timestamp:
- 02/06/2026 04:00:45 AM (8 weeks ago)
- Location:
- wpjam-basic/trunk
- Files:
-
- 4 edited
-
includes/class-wpjam-admin.php (modified) (1 diff)
-
includes/class-wpjam-field.php (modified) (4 diffs)
-
public/wpjam-functions.php (modified) (2 diffs)
-
wpjam-basic.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wpjam-basic/trunk/includes/class-wpjam-admin.php
r3454759 r3455110 154 154 'admin' => true, 155 155 'nonce_action' => fn($data)=> 'upload-'.$data['name'], 156 'callback' => fn($data)=> wpjam_upload($data['name'], [' mimes'=>$data['mimes']])156 'callback' => fn($data)=> wpjam_upload($data['name'], ['accept'=>$data['accept']]) 157 157 ]); 158 158 -
wpjam-basic/trunk/includes/class-wpjam-field.php
r3454739 r3455110 591 591 if($this->render){ 592 592 return wpjam_wrap($this->call('render_by_prop', $args)); 593 }elseif($this->is('fieldset')){ 593 } 594 595 $key = $this->key; 596 597 if($this->is('fieldset')){ 594 598 $mu = $this->_mu; 595 599 $group = $this->group && !$this->is('fields'); … … 601 605 $this->summary && $field->before([$this->summary, 'strong'], 'summary')->wrap('details'); 602 606 603 return $field->wrap($tag, $attr)->add_class($group ? 'field-group' : '')->data($mu ? [] : ['key'=>$ this->key]);607 return $field->wrap($tag, $attr)->add_class($group ? 'field-group' : '')->data($mu ? [] : ['key'=>$key]); 604 608 }elseif($this->is('mu')){ 605 609 $value = $this->value ?: []; … … 694 698 ]); 695 699 }elseif($this->is('uploader')){ 696 $mimes = wpjam_accept_to_mime_types($this->accept ?: 'image/*'); 697 $exts = implode(',', wpjam_map($mimes, fn($v)=> str_replace('|', ',', $v), 'k')); 698 $params = ['_ajax_nonce'=>wp_create_nonce('upload-'.$this->key), 'action'=>'wpjam-upload', 'name'=>$this->key, 'mimes'=>$mimes]; 699 700 $mimes === [] && $this->attr('disabled', 'disabled'); 701 702 return $this->input(['type'=>'hidden'])->wrap('div', ['plupload', $this->disabled])->data(['key'=>$this->key, 'plupload'=>[ 703 'browse_button' => 'plupload_button__'.$this->key, 700 $accept = $this->accept ?: 'image/*'; 701 $exts = implode(',', wpjam_map(wpjam_accept_to_mime_types($accept), fn($v)=> str_replace('|', ',', $v), 'k')); 702 703 return $this->input(['type'=>'hidden'])->wrap('div', ['plupload', $exts ? '' : 'disabled'])->data(['key'=>$key, 'plupload'=>[ 704 'browse_button' => 'plupload_button__'.$key, 704 705 'button_text' => $this->button_text ?: __('Select Files', 'wpjam'), 705 'container' => 'plupload_container__'.$ this->key,706 'file_data_name' => $ this->key,707 'multipart_params' => $params,706 'container' => 'plupload_container__'.$key, 707 'file_data_name' => $key, 708 'multipart_params' => ['_ajax_nonce'=>wp_create_nonce('upload-'.$key), 'action'=>'wpjam-upload', 'name'=>$key, 'accept'=>$accept], 708 709 'filters' => ['max_file_size'=>(wp_max_upload_size() ?: 0).'b']+($exts ? ['mime_types'=>[['extensions'=>$exts]]] : []), 709 710 ]+(($this->pull('drap_drop') && !wp_is_mobile()) ? [ 710 'drop_element' => 'plupload_drag_drop__'.$ this->key,711 'drop_element' => 'plupload_drag_drop__'.$key, 711 712 'drop_info' => [__('Drop files to upload', 'wpjam'), _x('or', 'Uploader: Drop files here - or - Select Files', 'wpjam')] 712 713 ] : [])]); … … 717 718 $value = $this->options && !$wrap ? (array_find($this->options(), fn($v, $k)=> $value ? $k == $value : !$k) ?? $value) : $value; 718 719 719 return wpjam_wrap($value, $tag, $tag ? ['class'=>'field-key field-key-'.$ this->key, 'data'=>['val'=>$this->value, 'name'=>$this->name]] : []);720 return wpjam_wrap($value, $tag, $tag ? ['class'=>'field-key field-key-'.$key, 'data'=>['val'=>$this->value, 'name'=>$this->name]] : []); 720 721 }elseif($this->is('hr')){ 721 722 return wpjam_tag('hr'); -
wpjam-basic/trunk/public/wpjam-functions.php
r3454739 r3455110 814 814 $upload = wp_upload_bits($name, null, $bits); 815 815 }else{ 816 wpjam_validate_mime_types($args['mimes'] ?? []) && ($args += ['test_form'=>false]); 817 816 if(!empty($args['accept'])){ 817 $args['mimes'] = wpjam_accept_to_mime_types($args['accept']); 818 $args['mimes'] || wpjam_throw('upload_error', '无效的文件类型'); 819 } 820 821 $args += ['test_form'=>false]; 818 822 $upload = is_array($name) ? wp_handle_sideload($name, $args) : wp_handle_upload($_FILES[$name], $args); 819 823 } … … 986 990 } 987 991 988 function wpjam_validate_mime_types($mimes){989 $allowed = get_allowed_mime_types();990 991 foreach($mimes as $k => $v){992 $ext = array_search($v, $allowed);993 994 if(!$ext || array_diff(explode('|', $k), explode('|', $ext))){995 wpjam_throw('upload_error', '无效的文件类型');996 }997 }998 999 return true;1000 }1001 1002 992 function wpjam_accept_to_mime_types($accept){ 1003 993 $allowed = get_allowed_mime_types(); -
wpjam-basic/trunk/wpjam-basic.php
r3454739 r3455110 4 4 Plugin URI: https://blog.wpjam.com/project/wpjam-basic/ 5 5 Description: WPJAM 常用的函数和接口,屏蔽所有 WordPress 不常用的功能。 6 Version: 6.9.2 6 Version: 6.9.2.1 7 7 Requires at least: 6.7 8 8 Tested up to: 6.9
Note: See TracChangeset
for help on using the changeset viewer.