0

I'm using a simple plugin "user following system" And all what i need to do is sending an email after the users get a new followers.

I think this is the important part of the plugin code:

function pwuf_follow_user( $user_id, $user_to_follow ) {

    $following = pwuf_get_following( $user_id );

    if ( $following && is_array( $following ) ) {
        $following[] = $user_to_follow;
    } else {
        $following = array();
        $following[] = $user_to_follow;
    }

    // retrieve the IDs of all users who are following $user_to_follow
    $followers = pwuf_get_followers( $user_to_follow );

    if ( $followers && is_array( $followers ) ) {
        $followers[] = $user_id;
    } else {
        $followers = array();
        $followers[] = $user_id;
    }

    do_action( 'pwuf_pre_follow_user', $user_id, $user_to_follow );

    // update the IDs that this user is following
    $followed = update_user_meta( $user_id, '_pwuf_following', $following );

    // update the IDs that follow $user_id
    $followers = update_user_meta( $user_to_follow, '_pwuf_followers', $followers );

    // increase the followers count
    $followed_count = pwuf_increase_followed_by_count( $user_to_follow ) ;

    if ( $followed ) {

        do_action( 'pwuf_post_follow_user', $user_id, $user_to_follow );

        return true;
    }
    return false;
}

and here to check if a user is following another:

function pwuf_is_following( $user_id, $followed_user ) {

    $following = pwuf_get_following( $user_id );

    $ret = false; // is not following by default

    if ( is_array( $following ) && in_array( $followed_user, $following ) ) {
        $ret = true; // is following
    }

    return $ret;
}

I tried to add this code after updating the user meta but nothing happen!

   $subscribers = explode(",", $user_to_follow );
    $emails      = array ();

    foreach ( $subscribers as $subscriber ) {
        $user_info = get_userdata($subscriber);
        $emails[] = $user_info ->user_email;
    }
    $body = sprintf( $user_to_follow->display_name, 'followed your work! See <%s>' );

    wp_mail( $emails, 'New followers!', $body );
  • Have you confirmed your server is able to send email, and that it hasn't been spammed or blacklisted? – Tom J Nowell Jul 9 '18 at 20:30
  • Where exactly have you added your code? Directly in that plugin? – Krzysiek Dróżdż Jul 10 '18 at 6:32
  • Thanks @Tom for comment, Yes my server sending emails. – Adham Mohamed Jul 10 '18 at 10:14
  • Yes @Yrzysiek i added them Directly! i hope you can helping me creating some function to send email after users get new followers. – Adham Mohamed Jul 10 '18 at 10:17
  • i need your help guys! – Adham Mohamed Jul 10 '18 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.