Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

Include a file based on a group variable that send a email in wordpress

$
0
0

Replies: 0

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.


<?php
////////////////////////////////////////////////////////////////////
//  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

<?php
function send_emails_on_new_event_store_group_one($post_id)

{
    $post           =   get_post($post_id);
    $author         =   get_userdata($post->post_author);
    $ac_email       =   "some@email.com";
$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(); ?>

<html>
    <head>
        <title></title>
    </head>
    <body>
        <p>
            Hi 
        </p>
        <p>
            <?php echo $author->user_login ;?> has created a new entry maintenance system.
        </p>
        <p>
            <strong>Details:</strong><br />
            Ref number <?php echo $title ;?><br />
            Log in to track this call.
        </p>
        <p>
            Regards,<br />

        </p>
    </body>
</html>

<?php

$message = ob_get_contents();

ob_end_clean();
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.


Viewing all articles
Browse latest Browse all 59525

Trending Articles