Support » Plugin: Groups » Include a file based on a group variable that send a email in wordpress

  • Resolved mfwebmaster


    I have a file that is included in my function.php file that listens for any CPT that is posted. once the CPT has been posted it should send a email based on the variable for the groups plugin via a IF statement.

    Below is the listening file that I have a problem with where it does not include the email based on the variable $group_id_strip.

    //  Add the listing Hooks for Email 
    add_action('new_to_publish', 'select_email_template_on_new_event');
    function select_email_template_on_new_event($post_id)
        $post                   =   get_post($post_id);
        $post_id                =   $post->ID;
        $post_type              =   'CPT'; //post, page, attachment or 
    whatever other CPT you may have
        $author                 =   get_userdata($post->post_author);
        $author_id              =   $author->ID;
        $group_id               =   do_shortcode( '[groups_user_groups 
    user_id=”‘ . $author_id . ‘”]' );
    $group_id_strip         =   strip_tags($group_id);
    if ( $group_id_strip    =   'Store Group 1') {
        get_template_part( 'email/email-sg', '1' ); 
    if ( $group_id_strip = "Store Group 2") {
        get_template_part( 'email/email-sg', '2' );  

    The problem is that I cannot get the IF statements to work can somebody please assist me in solving this problem to include the file base on the $group_id_strip variable

    below is the email file that will get called once the IF statement works

    function send_emails_on_new_event_store_group_one($post_id)
        $post           =   get_post($post_id);
        $author         =   get_userdata($post->post_author);
        $ac_email       =   "";
    $admin_email    =   get_option('admin_email');
    $emails         =   "$ac_email, $author->user_email"; //If you want to send 
    to site administrator, use $emails = get_option('admin_email');
    $title          =   wp_strip_all_tags(get_the_title($post->ID));
    $url            =   get_permalink($post->ID);
    $post_id        =   $post->ID;
    $post_type      =   'maintenances'; //post, page, attachment or whatever 
    other CPT you may have
        //  Email lay out
       ob_start(); ?>
                <?php echo $author->user_login ;?> has created a new entry maintenance system.
                <strong>Details:</strong><br />
                Ref number <?php echo $title ;?><br />
                Log in to track this call.
                Regards,<br />
    $message = ob_get_contents();
    if(get_post_type($post_id) === $post_type)
    wp_mail($emails, "New Item listed maintenance system. Ref number echo $title", $message);

    This file works fine. the thing that change here is the $ac_email based on the group the $author belongs to.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • gtsiokos



    I think that the conditionals are wrong in your code. The lines should be
    if ( $group_id_strip == 'Store Group 1' )
    if ( $group_id_strip == "Store Group 2")

    because I think you need to compare the value and not assign a value to $groups_id_strip.

    Kind regards,

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.