1

我对新 WordPress 3.5 中的媒体上传器没有什么问题。我创建了自己的插件来上传图片。我正在使用这段代码 JS:

<script type="text/javascript">
    var file_frame;

    jQuery('.button-secondary').live('click', function( event ){

        event.preventDefault();

        if ( file_frame ) {
            file_frame.open();
            return;
        }

        file_frame = wp.media.frames.file_frame = wp.media(
            {
                title: 'Select File',
                button: {
                    text: jQuery( this ).data( 'uploader_button_text' )
                },
                multiple: false
            }
        );

        file_frame.on('select', function() {
            attachment = file_frame.state().get('selection').first().toJSON();
            jQuery('#IMGsrc').val(attachment.url);
        });

        file_frame.open();
    });
</script>

代码工作正常,但不幸的是表单似乎不完整。当我选择任何图片时,右侧不会显示“附件显示设置”。我不知道为什么。我尝试向媒体添加选项:

displaySettings: true,
displayUserSettings: true

但它也不起作用。

4

2 回答 2

0

页面是否<script type="text/html" id="tmpl-attachment-details">...在源代码中有模板?如果没有,您需要调用 wp_print_media_templates(),从 wp-includes/media-template.php 编写样式

于 2013-01-09T06:07:40.673 回答
0

这是我使用的代码。资料来源: http: //mikejolley.com/2012/12/using-the-new-wordpress-3-5-media-uploader-in-plugins/ 它似乎工作得很好,但左边的侧边栏不见了。(故意的,但无论如何我都不想要它)。

<?php wp_enqueue_media(); ?>

<script>

function showAddPhotos() {

// Uploading files
var file_frame;

// event.preventDefault();

// If the media frame already exists, reopen it.
if ( file_frame ) {
  file_frame.open();
  return;
}

// Create the media frame.
file_frame = wp.media.frames.file_frame = wp.media({
  title: jQuery( this ).data( 'uploader_title' ),
  button: {
    text: jQuery( this ).data( 'uploader_button_text' ),
  },
  multiple: false  // Set to true to allow multiple files to be selected
});

// When an image is selected, run a callback.
file_frame.on( 'select', function() {
  // We set multiple to false so only get one image from the uploader
  attachment = file_frame.state().get('selection').first().toJSON();

  // Do something with attachment.id and/or attachment.url here
});

// Finally, open the modal
file_frame.open();

}
</script>
于 2013-01-25T03:59:59.360 回答