【问题标题】:Wordpress media button "insert into post" not returning file urlWordpress 媒体按钮“插入帖子”不返回文件 url
【发布时间】:2012-02-16 17:42:52
【问题描述】:

我创建了一个自定义字段,通过单击“插入帖子”按钮,使用 wordpress 标准媒体库弹出存储媒体文件 url/位置的字段。下面是我提取媒体文件路径的代码。图片网址工作正常。但它只返回媒体标题。我不知道从哪里可以得到文件路径。

jQuery(document).ready(function() {
    jQuery('#wsp_media_button').click(function() {
     formfield = jQuery('#wsp_media').attr('name');
     tb_show('', 'media-upload.php?TB_iframe=true&tab=library');
     return false;
    });

    window.send_to_editor = function(html) {
        var imgurlar = html.match(/<img[^>]+src=\"([^\"]+)\"/);
        var imgurl = imgurlar[1];

        //html is returning only title of the media
        alert(html);

        //image
        if( imgurl.length ){
            jQuery('#wsp_media').val(imgurl);
        }
        //other types of files
        else{
            var fileurl = jQuery(html);

        }
    }
});

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    如果用户在插入媒体(视频、pdf 等)时选择了包含链接 URL,那么传回编辑器的只是文件名,这就是您所看到的.

    如果您想始终确保发送回文件 URL,无论用户选择什么设置,或者以不同的格式存储文件 URL,您可以连接到两个单独的过滤器。

    程序设置:

        add_filter('media_send_to_editor', 'media_to_editor', 1, 3);
        add_filter('image_send_to_editor', 'image_to_editor', 1, 8);
    

    对于图像,过滤器函数如下所示:

    image_to_editor($html, $id, $caption, $title, $align, $url, $size, $alt){
    
    }
    

    对于媒体附件:

    function media_to_editor($html, $send_id, $attachment ){        
    
    } 
    

    因此,您可以在这些过滤器中更改调整发送回编辑器的数据,以确保它始终具有文件 URL。对于媒体附件,请检查 html 是否包含文件引用,如果没有,请将其添加回来,然后将其发送回编辑器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-27
      • 2014-02-17
      相关资源
      最近更新 更多