2017-09-06 3 views
0

私はフロントエンドからファイルをアップロードするためのカスタムwp.mediaモーダルウィンドウを作成したいワードプレスプラグインがあります。現在のユーザーがアップロードしたファイルのみを表示したい。この入力をどこからフィルタリングするかはわかりません。ここに私の現在のjavascript wp.media関数があります。私はライブラリを特定のファイルタイプに制限することができますが、current_userでフィルタリングする方法がわかりません。現在のユーザーがアップロードしたファイルのみを表示するwp.media modalを制限する

function open_media_window() { 
var upload = ""; 
if (this.window === undefined) { 

    if($(this).hasClass('bizimg-select')){ 
    upload = "bizimg"; 
    } 
    if($(this).hasClass('vcard-file')){ 
    upload = "vcard"; 
    } 

    if(upload=='bizimg'||upload==""){ 
    this.window = wp.media({ 
      title: 'Upload my Bizcard Bizimg', 
      library: {type: 'image/*', 
      uploadedTo : wp.media.view.settings.post.id}, 
      multiple: false, 
      button: {text: 'Insert'} 
     }); 
    } 
    if((upload=='vcard')){ 
    this.window = wp.media({ 
      title: 'Upload my Bizcard vCard', 
      library: {type: 'text/x-vcard'}, 
      multiple: false, 
      button: {text: 'Insert'} 
     }); 
    } 

    var self = this; // Needed to retrieve our variable in the anonymous function below 
    this.window.on('select', function() { 
      var files = self.window.state().get('selection').toArray(); 
      var first = files[0].toJSON(); 
      wp.media.editor.insert('[myshortcode id="' + first.id + '"]'); 
      //populate selected-bizimg-file with file name 
      if(upload=='bizimg'){ 
      //populate bizimg_post with post id 
      $('#bizimg_post').val(first["id"]); 
      if($('#selected-bizimg-file')){ 
       $('#selected-bizimg-file').text(first['filename']); 
      } 
      if('img.bizimg'){ 
       $('img.bizimg').attr("srcset", first['url']).attr("src", first['url']); 
       $('.bizimg-div').removeClass("border-blue"); 
      } 
      } 
      //do the same for vcard 
      if(upload=='vcard'){ 
      $('#vcard_post').val(first["id"]); 
      if($('#selected-vcard-file')){ 
       $('#selected-vcard-file').text(first['filename']); 
       $('#vcard-raw-textarea').load(first['url']); 
       $('#vcard-upload').css('color','#df9e06'); 
       $('.remove-file').removeClass('daisy-hidden'); 
      } 
      } 

     }); 

} 
    this.window.open(); 
    return false; 
    } 

答えて

0

これはしばらく掘り出した後はかなり簡単でした。私は前の質問でこれを答えた回答をcaldasとしたいと思います。 wordpress show only media user has uploaded in wp_editor 。これが単なる重複した質問であると思われる場合は、フラグを立ててください。私はカスタムwpメディアモーダルを扱っていたので、それは無関係だと思った。

関連する問題