Php 联系表7-多文件上传值作为电子邮件中的链接

Php 联系表7-多文件上传值作为电子邮件中的链接,php,wordpress,contact-form-7,Php,Wordpress,Contact Form 7,我正在我的表单中使用“联系人表单7拖放文件上载-多文件上载”(Contact Form 7拖放文件上载)插件。上传可能相当大,所以我不希望它附加到邮件,而是有链接到邮件中上传的文件 我从邮件附件字段中删除了标签,并将其添加到邮件正文中,希望它能输出上传的文件链接: <p><strong>IMAGES</strong><br/><br/>[dropfiles-291]</a></p> 图像[dropfiles-

我正在我的表单中使用“联系人表单7拖放文件上载-多文件上载”(Contact Form 7拖放文件上载)插件。上传可能相当大,所以我不希望它附加到邮件,而是有链接到邮件中上传的文件

我从邮件附件字段中删除了标签,并将其添加到邮件正文中,希望它能输出上传的文件链接:

 <p><strong>IMAGES</strong><br/><br/>[dropfiles-291]</a></p>
图像

[dropfiles-291]

但它只输出由“|”分隔的文件名。例如:“imagename1.jpg | imagename2.jpg | imagename3.jpg | imagename4.jpg”

经过一些搜索,我在拖放插件代码中找到了以下代码:

add_filter('wpcf7_mail_tag_replaced_dropfiles', array($this, 'wpcf7_mail_tag_replaced'), 100, 3);

function wpcf7_mail_tag_replaced($text, $submitted, $html ){
    $upload_dir   = wp_upload_dir();
    $datas = explode("|",$text);
    $url = $upload_dir["baseurl"]."/cf7-uploads-save/";
    $text_custom = array();

    foreach ($datas as $value) {
        $text_custom[] = $url.$value;
    }
    if($html){
        return implode(" <br>", $text_custom);
    }else{
        return implode(" | ", $text_custom);
    }           

}
add_filter('wpcf7_-mail_-tag_-replaced_-dropfiles',array('this,'wpcf7_-mail_-tag_-replaced'),100,3);
函数wpcf7\邮件\标签\已替换($text、$submitted、$html){
$upload_dir=wp_upload_dir();
$datas=分解(“|”,$text);
$url=$upload_dir[“baseurl”]。“/cf7 uploads save/”;
$text_custom=array();
foreach($data作为$value){
$text_custom[]=$url.$value;
}
如果($html){
返回内爆(“
”,$text\u custom); }否则{ 返回内爆(“|”,$text_custom); } }
我不是一个php开发人员,但在我看来,代码应该用电子邮件中的链接来包装上传的文件。无论如何,它不起作用。经过广泛的在线研究,我将代码更改为:

add_filter('wpcf7_mail_tag_replaced', array($this, 'wpcf7_mail_tag_replaced_dropfiles'), 100, 3);

function wpcf7_mail_tag_replaced_dropfiles( $text, $submitted, $html ){        

    $upload_dir = wp_upload_dir();
    $datas = explode("|",$text);
    $url = $upload_dir["baseurl"]."/cf7-uploads-save/";
    $text_custom = array();

    foreach ($datas as $value) {
        $text_custom[] = $url.$value;
    }
    if($html){
        return implode(" <br>", $text_custom);}
        else{return implode(" | ", $text_custom);}               

}
add_filter('wpcf7_mail_tag_replaced',array('this,'wpcf7_mail_tag_replaced_dropfiles'),100,3);
函数wpcf7_mail_tag_replaced_dropfiles($text,$submitted,$html){
$upload_dir=wp_upload_dir();
$datas=分解(“|”,$text);
$url=$upload_dir[“baseurl”]。“/cf7 uploads save/”;
$text_custom=array();
foreach($data作为$value){
$text_custom[]=$url.$value;
}
如果($html){
返回内爆(“
”,$text_custom);} else{return introde(|“,$text_custom);} }
电子邮件现在具有所需的链接效果,但在表单中所有提交的字段上,而不仅仅是[dropfiles]字段上。[dropfiles]字段看起来很棒,每个上传文件的链接都在一个新行中,等等。但是,很明显,我不希望普通文本、文本区域、复选框、收音机等字段也成为链接


我已经给插件开发者发了一张支持票,但是还没有收到任何回复。我可以采取什么方法来实现这个目标?

我已经找到了一个临时解决方案——直到我从插件开发人员那里得到了一个永久解决方案。我将代码更改如下:

add_filter('wpcf7_mail_tag_replaced', array($this, 'wpcf7_mail_tag_replaced_dropfiles'), 100, 3);

function wpcf7_mail_tag_replaced_dropfiles( $text, $submitted, $html ){        
if(preg_match('/\.(jpg|png|jpeg|gif)$/', $submitted))  {
    $upload_dir = wp_upload_dir();
    $datas = explode("|",$text);
    $url = $upload_dir["baseurl"]."/cf7-uploads-save/";
    $text_custom = array();

    foreach ($datas as $value) {
        $text_custom[] = $url.$value;
    }
    if($html){
        return implode(" <br>", $text_custom);}
        else{return implode(" | ", $text_custom);}               
    } 

    return $text; 
}
add_filter('wpcf7_mail_tag_replaced',array('this,'wpcf7_mail_tag_replaced_dropfiles'),100,3);
函数wpcf7_mail_tag_replaced_dropfiles($text,$submitted,$html){
if(预匹配('/\(jpg | png | jpeg | gif)$/',$已提交)){
$upload_dir=wp_upload_dir();
$datas=分解(“|”,$text);
$url=$upload_dir[“baseurl”]。“/cf7 uploads save/”;
$text_custom=array();
foreach($data作为$value){
$text_custom[]=$url.$value;
}
如果($html){
返回内爆(“
”,$text_custom);} else{return introde(|“,$text_custom);} } 返回$text; }
我花了几个小时来窃听这个问题,但我想我已经找到了问题所在

我注意到,当我使用dropfiles标记作为必填字段时,这种情况就发生了。[dropfiles*…]

联系人表单7有一个函数“replace_tags_callback”,它应用过滤器“wpcf7_mail_tag_replaced_u{$type}”

问题是{$type}是从$form_tag->type获取的,在我们的例子中,它可以是“dropfiles”或“dropfiles*”。如果CF7使用$form_tag->basetype获得它,那么这两个标记将是相同的

为了解决这个问题,我在contact-form-7-drop-files/frontend/index.php的第7行添加了一个“dropfiles*”过滤器

add_filter('wpcf7_mail_tag_replaced_dropfiles*', array($this, 'wpcf7_mail_tag_replaced'), 100, 3);
所以课程的开始是这样的:

function __construct(){
    add_action("wp_enqueue_scripts",array($this,"add_lib"));
    add_filter('wpcf7_form_response_output', array($this,'add_settings'),999999,4);
    add_filter('wpcf7_mail_tag_replaced_dropfiles', array($this, 'wpcf7_mail_tag_replaced'), 100, 3);
    add_filter('wpcf7_mail_tag_replaced_dropfiles*', array($this, 'wpcf7_mail_tag_replaced'), 100, 3);
}
function wpcf7_mail_tag_replaced($text, $submitted, $html ){
    $upload_dir   = wp_upload_dir();
    $datas = explode("|",$text);
    $url = $upload_dir["baseurl"]."/cf7-uploads-save/";
    $text_custom = array();

    foreach ($datas as $value) {
        $text_custom[] = $url.$value;
    }
    if($html){
        return implode(" <br>", $text_custom);
    }else{
        return implode(" | ", $text_custom);
    }



}
函数uuu构造(){
add_action(“wp_排队_脚本”,数组($this,“add_lib”));
add_filter('wpcf7_form_response_output',array('this,'add_settings'),999999,4);
添加过滤器(wpcf7邮件标签替换掉的dropfiles),数组($this,'wpcf7邮件标签替换掉的'),100,3;
添加过滤器(wpcf7邮件标签替换掉的dropfiles*),数组($this,'wpcf7邮件标签替换掉的'),100,3);
}
函数wpcf7\邮件\标签\已替换($text、$submitted、$html){
$upload_dir=wp_upload_dir();
$datas=分解(“|”,$text);
$url=$upload_dir[“baseurl”]。“/cf7 uploads save/”;
$text_custom=array();
foreach($data作为$value){
$text_custom[]=$url.$value;
}
如果($html){
返回内爆(“
”,$text\u custom); }否则{ 返回内爆(“|”,$text_custom); } }
我向插件作者报告了这个bug,希望他/她能在下一个版本中更新它