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

报告相同问题?