【问题标题】:Display Media Uploader in Own Plugin on Wordpress 3.5在 Wordpress 3.5 上的自己的插件中显示媒体上传器
【发布时间】:2013-01-06 22:44:59
【问题描述】:

我对新 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

但它也不起作用。

【问题讨论】:

  • 你有没有想过这个问题?我正在尝试做同样的事情,所有的研究都显示了同样的事情,但没有人解释任何关于显示附件设置选项的内容......提前致谢。
  • 也许你可以在这里找到解决方案stackoverflow.com/questions/21540951/…

标签: forms wordpress media uploader


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    这是我使用的代码。来源: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>
    

    【讨论】:

      猜你喜欢
      • 2015-06-21
      • 1970-01-01
      • 2014-08-11
      • 1970-01-01
      • 2013-07-02
      • 1970-01-01
      • 2012-11-30
      • 2013-03-04
      • 2012-07-25
      相关资源
      最近更新 更多