1

新しい WordPress 3.5 の Media Uploader にはほとんど問題がありません。写真をアップロードする独自のプラグインを作成しました。私はこのコード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

これは私が使用するコードです。ソース: 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 に答える
0

ページ<script type="text/html" id="tmpl-attachment-details">...のソースにテンプレートがありますか? そうでない場合は、wp_print_media_templates() を呼び出して、wp-includes/media-template.php からスタイルを書き込む必要があります。

于 2013-01-09T06:07:40.673 に答える