简体   繁体   English

替换来自functions.php的插件函数

[英]Replace a plugin function from functions.php

I have I plugin that send emails using this function 我有使用此功能发送电子邮件的插件

    function em_event_added_email($EM_Event){
    if( !$EM_Event->get_status() && get_option('dbem_bookings_approval') && get_option('dbem_event_submitted_email_admin') != '' ){
        $admin_emails = explode(',', get_option('dbem_event_submitted_email_admin')); //admin emails are in an array, single or multiple
        $subject = $EM_Event->output(get_option('dbem_event_submitted_email_subject'));
        $message = $EM_Event->output(get_option('dbem_event_submitted_email_body'));
        //Send email to admins
        $EM_Event->email_send( $subject,$message, $admin_emails);
    }
}
add_action('em_event_added','em_event_added_email', 10, 1);

I want to be able to replace this function from theme functions.php so I can customize $message output, the aim is to add HTML data to the footer of all emails sent by this plugin, so if there is other way than replacing the function it would be better 我希望能够从主题functions.php替换此功能,以便我可以自定义$message输出,目的是将HTML数据添加到此插件发送的所有电子邮件的页脚中,因此,除了替换该功能外,还有其他方法会更好

The plugin has that function? 插件有那个功能吗? If the plugin doesn't have a filter (look for apply_filters in the plugin), then you can replace it by removing the original hook: 如果插件没有过滤器(请在插件中查找apply_filters),则可以通过删除原始钩子来替换它:

remove_action('em_event_added','em_event_added_email', 10, 1);

Then making your own in your theme's php (functions or an include) and replace the function name with your own and stick it back in the same hook with the same priority. 然后在主题的php(函数或包含项)中创建自己的函数,并用您自己的函数名称替换函数名称,并将其以相同的优先级粘贴在同一钩子中。

function yourprefix_new_em_event_added_email($EM_Event){
    if( !$EM_Event->get_status() && get_option('dbem_bookings_approval') && get_option('dbem_event_submitted_email_admin') != '' ){
        $admin_emails = explode(',', get_option('dbem_event_submitted_email_admin')); //admin emails are in an array, single or multiple
        $subject = $EM_Event->output(get_option('dbem_event_submitted_email_subject'));
        $message = $EM_Event->output(get_option('dbem_event_submitted_email_body'));
        //Send email to admins
        $EM_Event->email_send( $subject,$message, $admin_emails);
    }
}
add_action('em_event_added','yourprefix_new_em_event_added_email', 10, 1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM