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 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划