Automatic Email Snippet after manual approve

Question

i’m currently working on a WordPress website and i need some guidance on about my code. What i would like to achieve is have an email sent automatically after i have approved a user login and clicked “update user”.

To go a little in-depth about this – User’s are able to sign up to our website and the information is sent to the website, we have a custom plugin that display certain information the user entered, the information is displayed through using Advanced Custom Fields. In the customised plugin section we have “login allowed” checkbox, i want it so when i check this and click update user, the email is sent.

Also needing the email to be automatically retrieved from the wordpress’s default “Basic information” section. Any guidance / clarification & feedback is majorly appreciated – here’s my code so far.

      add_action(‘acf/save_post’, ‘my_save_post’);

        function my_save_post( $post_id ) {

        // check if you are editing a user
        global $pagenow;
        if ($pagenow == ‘user-edit.php’) {

        //get the value of the field
        $value = get_field(‘login_allowed’,$post_id);

        // check if the checkbox is filled
        if ( ! $value ='unchecked' ) {
                return false;
            }

        $value == 'checked'
            {

        // Company information
        $email = “removed”;
        $name = “removed”;

        //get user's email
        $user = get_user_by('email', $username);
        if ($user) {
        $details['email'] = $user->user_email;


        // email data
    $to = $useremail;
    $subject = 'The subject';
    $body = 'The email body content';
    $headers = ‘From:‘ . $name . ‘ <‘ . $email . ‘>’ . “rn”;

        // send email
        wp_mail($to, $subject, $body, $headers );

        }
        }
        }
        }
0
, , YxngLBZ 9 months 0 Answers 86 views 0

Leave an answer