php – 具有大小选择的WordPress Media Uploader

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 具有大小选择的WordPress Media Uploader脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在我自己的wordpress插件添加图像输入.
为此,我使用标准的wordpress媒体上传器,如下所示:
VAR custom_uploader;

$('.upload_image_button').click(function(e) {
    input = $(this);
    e.preventDefault();

    custom_uploader = wp.media.frames.file_frame = wp.media({
        tITle: 'Choose Collage Image',library: {
            tyPE: 'image'
        },button: {
            text: 'Choose Collage Image'
        },multiple: false,displaySettings: true,displayUserSettings: false
    });

    custom_uploader.on('select',function() {
        attachment = custom_uploader.state().get('selection').First().toJSON();
        input.PRev('input').val(attachment.url);
    });

    custom_uploader.open();

});

这很完美.
添加了两个与我的插件完全相同的图像大小:

if ( function_exists( 'add_image_size' ) ) {
    add_image_size( 'collage-large',460,660,true );
    add_image_size( 'collage-small',325,true );
}

我的问题:
媒体上传表单中未显示图像大小的选择器或更好的缩略图选择器.我怎么做?

我在互联网找到了一些地方.可能有用.
attachment = custom_uploader.state().get('selection').first().toJSON();

通过附件,您可以使用:

> alt
>作者
>标题
> compat(< - 它是对象) >项目
>元

>约会
> dateFormatted
>描述
> editLink
>文件
>身高
>图标
> id
>链接
> menuOrder
>哑剧
>修改
>名字
> nonces(< - thi是对象) >删除
>更新
>原型

>方向
>尺寸(< - 这是对象) > full(< - 这是对象) >身高
>方向
>网址
>
>原型

> medium(< - 这是对象) >身高
>方向
>网址
>宽度
>原型

>缩略图(< - 这是对象) >身高
>方向
>网址
>宽度
>原型

> proto(< - 这是对象) >状态
>子类型
>标题
>类型
> uploadedTo
>网址
>宽度

为了解决您的问题,我建议使用上面的案例20:

input.prev('input').val(attchment.sizes.collage-large.url);

希望这项工作!

脚本宝典总结

以上是脚本宝典为你收集整理的php – 具有大小选择的WordPress Media Uploader全部内容,希望文章能够帮你解决php – 具有大小选择的WordPress Media Uploader所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。