加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 13:30:21 所属栏目:PHP教程 来源:网络整理
导读:我想在我自己的WordPress插件中添加图像输入. 为此,我使用标准的WordPress媒体上传器,如下所示: var custom_uploader;$('.upload_image_button').click(function(e) { input = $(this); e.preventDefault(); custom_uploader = wp.media.frames.file_frame
我想在我自己的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);

希望这项工作!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读