doukong9982 2015-04-26 18:06
浏览 56

如何动态挂钩和编辑wordpress上传的图像

I'm new in wordpress plugin development and I'm trying to hook my function to one of wordpress's upload / attachements functions. My target is to: - hook to wordpress function (I've tried: wp_handle_upload, wp_handle_upload_prefilter) - use image/media resource in my function (apply filter on image) - return modified resource to further processing by wordpress core.

Is there a way to achieve that?

The code I'm using is similar to:

add_filter('wp_handle_upload', 'handle_upload');

function handle_upload($resource){

   $tools->tool_blurImage($resource);

return $resource;
}

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dth96108 2015-04-26 21:24
    关注

    The $resource passed to the function is an array of 3 elements:

    • file is the absolute path to the image file;
    • url is the url to the image;
    • type is the mime type of the file (i.e. image/jpeg).

    So if your $tools->tool_blurImage function accept the file path as parameter you should check if the file is an image and then pass the file path:

    function handle_upload($resource) {
    
        if( 'image' == substr( $resource['type'], 0, 5 ) )
            $tools->tool_blurImage($resource['file']);
    
        return $resource;
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么