wordpress 图片上传冲突

网上常见的wordpress图片上传

jQuery('#upload_image_button').click(function() {
    //formfield并未用上,可能代码遗漏了一段,怀疑和类的限定有关
    formfield = jQuery('#upload_image').attr('name');
    // show Wordpress' uploader modal box
    tb_show('', '<?php echo admin_url(); ?>media-upload.php?type=image&amp;TB_iframe=true'); 

    window.send_to_editor = function(html) {
    // this will execute automatically when a image uploaded and then clicked to 'insert to post' button
      imgurl = jQuery('img',html).attr('src');
      jQuery('.certi-img').attr('src',imgurl);
      jQuery('#certi_img').val(imgurl);
  
//close wordpress' uploader modal box   tb_remove(); } //阻止冒泡和默认动作,如a的跳转 return false; });

其中window.send_to_editor为 ,在被激活后,所有调用的send都会上传到#certi_img,所以,如果一个页面还含有其他自带图片上传的话,基本都会传到#certi_img,而本来要传入的editor中并没有任何图片。

所以,如果要上传到对应的editor,需要重写覆盖之前的代码

jQuery('#wp-euser_plan-media-buttons').click(function() {
     tb_show('', '<?php echo admin_url(); ?>media-upload.php?type=image&amp;TB_iframe=true'); 
     window.send_to_editor = function(html) {
             imgurl = jQuery('img',html).attr('src');
             tinymce.get("euser_plan").execCommand('mceInsertContent', false, '<img src="'+imgurl+'">');
             tb_remove();
             }
     return false;
    });
其中tinymce.get("euser_plan").execCommand('mceInsertContent', false, '<img src="'+imgurl+'">');保证了图片上传到光标插入的地方。
个人感觉可以从/wp-admin/js/media-upload.js中利用自身的插入函数insert,无奈现在还没有测出来。

posted on 2019-04-22 17:39  六月游乐  阅读(131)  评论(0编辑  收藏  举报

导航