Plugin Directory

Changeset 3455110


Ignore:
Timestamp:
02/06/2026 04:00:45 AM (8 weeks ago)
Author:
denishua
Message:

version 6.9.2

Location:
wpjam-basic/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • wpjam-basic/trunk/includes/class-wpjam-admin.php

    r3454759 r3455110  
    154154                'admin'         => true,
    155155                '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']])
    157157            ]);
    158158
  • wpjam-basic/trunk/includes/class-wpjam-field.php

    r3454739 r3455110  
    591591        if($this->render){
    592592            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')){
    594598            $mu     = $this->_mu;
    595599            $group  = $this->group && !$this->is('fields');
     
    601605            $this->summary && $field->before([$this->summary, 'strong'], 'summary')->wrap('details');
    602606
    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]);
    604608        }elseif($this->is('mu')){
    605609            $value  = $this->value ?: [];
     
    694698            ]);
    695699        }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,
    704705                '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],
    708709                'filters'           => ['max_file_size'=>(wp_max_upload_size() ?: 0).'b']+($exts ? ['mime_types'=>[['extensions'=>$exts]]] : []),
    709710            ]+(($this->pull('drap_drop') && !wp_is_mobile()) ? [
    710                 'drop_element'  => 'plupload_drag_drop__'.$this->key,
     711                'drop_element'  => 'plupload_drag_drop__'.$key,
    711712                'drop_info'     => [__('Drop files to upload', 'wpjam'), _x('or', 'Uploader: Drop files here - or - Select Files', 'wpjam')]
    712713            ] : [])]);
     
    717718            $value  = $this->options && !$wrap ? (array_find($this->options(), fn($v, $k)=> $value ? $k == $value : !$k) ?? $value) : $value;
    718719
    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]] : []);
    720721        }elseif($this->is('hr')){
    721722            return wpjam_tag('hr');
  • wpjam-basic/trunk/public/wpjam-functions.php

    r3454739 r3455110  
    814814        $upload = wp_upload_bits($name, null, $bits);
    815815    }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];
    818822        $upload = is_array($name) ? wp_handle_sideload($name, $args) : wp_handle_upload($_FILES[$name], $args);
    819823    }
     
    986990}
    987991
    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 
    1002992function wpjam_accept_to_mime_types($accept){
    1003993    $allowed    = get_allowed_mime_types();
  • wpjam-basic/trunk/wpjam-basic.php

    r3454739 r3455110  
    44Plugin URI: https://blog.wpjam.com/project/wpjam-basic/
    55Description: WPJAM 常用的函数和接口,屏蔽所有 WordPress 不常用的功能。
    6 Version: 6.9.2
     6Version: 6.9.2.1
    77Requires at least: 6.7
    88Tested up to: 6.9
Note: See TracChangeset for help on using the changeset viewer.