如何以编程方式更改联系表7中的默认消息? [英] How to programmatically change the default messages in Contact Form 7?
问题描述
我正在尝试在WordPress的contact-form-7插件中编辑垃圾邮件的错误消息。到目前为止,它仅显示一条简单的消息,尝试发送您的消息时出错,我想对此进行更改。但是我无法弄清楚在哪里可以找到发送此消息的代码中的位置。我已经找到了默认消息,但是一旦更改了该消息,它将不会执行任何操作。
在哪里可以找到它?
I am trying to edit the error message for spam in the contact-form-7 plugin in WordPress. As of now it only shows a simple message with 'there was an error trying to send your message', I would like to change this. But I can not figure out where to find the place in the code where this message is sent from. I have found the default message, but once this is changed, this does not do anything. Where can I find this?
推荐答案
有两种方法可以更改CF7中的默认消息,一种是使用admin cf7表单编辑器,该编辑器具有消息标签,而第二种方法是在设置完所有消息后,钩住插件触发的 wpcf7_messages过滤器,
There are 2 ways to change the default messages in CF7, one is using the admin cf7 form editor which has a tab 'Messages', while the 2nd way is to hook the 'wpcf7_messages' filter fired by the plugin once all the messages have been set,
//give a prioity >10 to ensure you filter hooks after those of the plugin.
add_filter('wpcf7_messages', 'change_spam_filter', 20,1);
function change_spam_filter($msgs){
$msgs['spam']['default'] = "this is a custom spam message";
return $msgs;
}
此过滤器仅在管理员后端而不是前端触发-结束。如果您需要在提交表单时过滤消息,则可以执行钩子操作
this filter only fires on the admin back-end and not on the front-end. If you need to filter the message when the form is submitted you can hook,
add_filter('wpcf7_display_message','',10,2);
function filter_spam_msg($message, $status){
if('spam' != $status) return $message;
$message = "this is a custom spam message";
return $message;
}
这篇关于如何以编程方式更改联系表7中的默认消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!