Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Joe Dolson

    (@joedolson)

    Well, it depends on what you need to do. I’d recommend just leaving the default email function disabled in settings, then attach your own custom function to the ‘mc_save_event’ action.

    Thread Starter draco_ghost

    (@draco_ghost)

    I just need to add some emails dynamically to BCC, depending of the category of the event and the role of the users, without typing in the area text of the settings of the plugin, is just this

    $bcc .= $mail_users; // new line, string of mails

    if ( $bcc ) {
    $bcc = explode( PHP_EOL, $bcc );
    foreach ( $bcc as $b ) {
    $b = trim( $b );
    if ( is_email( $b ) ) {
    $headers[] = “Bcc: $b”;
    }
    }

    Plugin Author Joe Dolson

    (@joedolson)

    Here’s what I’d suggest, then. Change the line where $bcc is assigned from

    $bcc = get_option( 'mc_event_mail_bcc' );

    to

    $bcc = apply_filters( 'mc_event_mail_bcc', get_option( 'mc_event_mail_bcc' ), $details );

    I’ll add this change into my next release; the other email fields are filterable, it just makes sense that the BCC field should be filterable the same way the others are.

    Thread Starter draco_ghost

    (@draco_ghost)

    `can you add an extra argument $event ?
    Because in my case, i need to know the category of the event.

    apply_filters( ‘mc_event_mail_bcc’, get_option( ‘mc_event_mail_bcc’ ), $details, $event);

    I do this way
    in my functions.php

    function custom_mc_event_mail_bcc($details,$event){
    
        $category_name = (string)$event['category'];
        $category_name = strtolower($category_name);
    
        if($category_name == "intermedio / avanzado"){
          $category_name = "int_ava";
        }
    
        $args = array(
          'blog_id'      => $GLOBALS['blog_id'],
          'role'         => $category_name,
         ); 
    
        if(isset($args)){
          $blogusers = get_users( $args) ;
          $mail_users = "";
          foreach ( $blogusers as $user ) {
            $mail_users .= "\r\n".esc_html( $user->user_email )."\r\n";
          }
        }
        return $details." ".$mail_users;
    }
    
    add_filter('mc_event_mail_bcc', 'custom_mc_event_mail_bcc',10,3);
    Plugin Author Joe Dolson

    (@joedolson)

    The $details array includes that information; $details is an expanded architecture of the $event object.

    You’ll find it by name under $details['category'] and by ID under $details['cat_id'].

    Thread Starter draco_ghost

    (@draco_ghost)

    yes thats right,i dont need $event, thanks for your time and help.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘override function’ is closed to new replies.