Extending Contact Form 7 Wordpress plugin by using hooks

我怕爱的太早我们不能终老 提交于 2019-12-04 15:32:04

问题


I would like to create a plugin that uses the contact form 7 hook, wpcf7_admin_after_mail. I want to use the plugin to interface with a CRM system. What I have thus far is the following:

//plugin header here

function add_to_CRM( $cf7 )
{
    if (isset($cf7->posted_data["your-message"]))
    {
        full_contact($cf7);
    } else {
        quick_quote($cf7);
    }
    return $cf7;
}

add_action('wpcf7_admin_after_mail', 'add_to_CRM');

//other functions here

I can't seem to get this working. I can't even get the hook to work and do something like mail me. Anybody have any idea what I'm doing wrong here. Since I have limited Wordpress experience I might me missing the boat completely with what I'm trying to do here. I've Googled for answers to no end.

EDIT: I ended up adding this to the theme's functions.php file and it works perfectly. Thing is, I want to get it working as a plugin. Any help will be appreciated.


回答1:


Try delaying the add_action() call, something like;

add_action('init', create_function('',
    'add_action("wpcf7_admin_after_mail", "add_to_CRM");'));

This actually registers your CF7 hook once WordPress is ready (which is nearer the time functions.php gets loaded in).



来源:https://stackoverflow.com/questions/3203043/extending-contact-form-7-wordpress-plugin-by-using-hooks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!