WordPress.org

Plugin Directory


Ignore:
Timestamp:
12/07/17 13:50:19 (6 weeks ago)
Author:
playes
Message:

3.1

  • 继续优化兼容逻辑
  • 修改时删除缩略图
File:
1 edited

Legend:

Unmodified
Added
Removed
  • oss-upload/trunk/oss-upload.php

    r1782441 r1782681  
    22/* 
    33 * Plugin Name: OSS Upload 
    4  * Version: 3.0 
     4 * Version: 3.1 
    55 * Description: Upload with Aliyun OSS, with modified OSS Wrapper and fully native image edit function support. 
    66 * Plugin URI: https://www.xiaomac.com/2016121895.html 
     
    4949    register_setting('oss_upload_admin_options_group', 'ouop'); 
    5050    add_action('wp_ajax_image-editor', 'oss_upload_dir_loader', 1); 
    51     add_action('wp_ajax_query-attachments', 'oss_upload_dir_loader', 1); 
    5251} 
    5352 
     
    101100 
    102101add_action('delete_attachment', 'oss_upload_delete_thumbnail'); 
     102add_action('edit_attachment', 'oss_upload_delete_thumbnail'); 
    103103function oss_upload_delete_thumbnail($id) { 
    104104    if(!ouop('oss') || ouop('oss_thumbnail', 1)) return; 
     
    113113} 
    114114 
    115 add_filter('wp_generate_attachment_metadata', 'oss_upload_generate_metadata'); 
    116 function oss_upload_generate_metadata($data){ 
     115add_filter('wp_generate_attachment_metadata', 'oss_upload_generate_metadata', 10, 2); 
     116function oss_upload_generate_metadata($data, $id){ 
    117117    if(ouop('oss') && ouop('oss_thumbnail') && !empty($data['sizes'])){ 
    118118        $uploads = oss_upload_dir(wp_get_upload_dir()); 
     
    123123        $data = oss_upload_set_metadata($data); 
    124124    } 
     125    if(ouop('oss')) update_post_meta($id, 'oss_upload', '1'); 
    125126    return $data; 
    126127} 
     
    149150add_filter('wp_get_attachment_url', 'oss_upload_attachment_url', 9999, 2); 
    150151function oss_upload_attachment_url($url, $id){ 
    151     if(ouop('oss')){ 
    152         if(ouop('oss_url') && ouop('oss_path')){ 
    153             $upload = wp_get_upload_dir(); 
    154             $upload_new = oss_upload_dir($upload); 
    155             $oss = oss_upload_get_attachment_oss($id, $upload); 
    156             if(empty($oss)){ 
    157                 $url = str_replace($upload_new['baseurl'], $upload['baseurl'], $url); 
    158             }else{ 
    159                 $url = str_replace($upload['baseurl'], $upload_new['baseurl'], $url); 
    160             } 
    161         } 
    162         if(wp_attachment_is_image($id) && ouop('oss_default_style')) $url .= ouop('oss_default_style'); 
    163     } 
     152    if(ouop('oss') && ouop('oss_url') && ouop('oss_path')){ 
     153        $upload = wp_get_upload_dir(); 
     154        $upload_new = oss_upload_dir($upload); 
     155        $oss = oss_upload_get_attachment_oss($id, $upload); 
     156        if(empty($oss)){ 
     157            $url = str_replace($upload_new['baseurl'], $upload['baseurl'], $url); 
     158        }else{ 
     159            $url = str_replace($upload['baseurl'], $upload_new['baseurl'], $url); 
     160        } 
     161    } 
     162    if(wp_attachment_is_image($id) && ouop('oss_default_style')) $url .= ouop('oss_default_style'); 
    164163    return $url; 
    165164} 
     
    183182    $oss = get_post_meta($id, 'oss_upload', true); 
    184183    if($oss != '') return $oss; 
     184    if(has_filter('upload_dir', 'oss_upload_dir')) return '1'; 
    185185    $url = get_the_guid($id); 
    186186    if(!$upload) $upload = wp_get_upload_dir(); 
Note: See TracChangeset for help on using the changeset viewer.