donglianer5064 2017-02-19 18:05
浏览 152
已采纳

替换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

  • 写回答

1条回答 默认 最新

  • douchunsui2395 2017-02-19 20:10
    关注

    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:

    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.

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算