• Hi,

    This is kind of a complicated question so please bear with me. I am writing a plugin for personal use that overrides the default functionality of wp_new_user_notification so I can automatically send different user roles a different message when they sign up, a simple theory.

    So far it works fine, the roles are determined by my other (published) plugin get_user_role() and the correct message is selected. The problem arises when I’m trying to use some post information to populate certain details within these emails.

    The user registration is handled by Gravity Forms and there is a custom post type set up as well which is facilitated by Custom Post Types for Gravity Forms so it stores a lot of other information besides the basic user information. Now I want some of this information to be available to send out in the welcome email but here’s the issue. Sometimes it works and sometimes it doesn’t! I can run the form 10 times and it’ll work 4 or 5 times and fail the rest. I can find no consistency or pattern to it and can only assume it is due to the way in which the posts are stored resulting in them not always being available to the code as.

    Here’s my code: http://pastie.org/5448784

    Does anyone have any ideas how I can validate this so it waits a few fractions of a second longer until it finds the correct information or whatever else the problem is please? It’s driving me nuts!

    If someone can help and needs to see the live site I will pm them as I don’t want the test site details mentioned here.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    Inserting data in tables is computationally heavy, so your suspicion is probably correct. Have you tried simply putting a utimer() line in before your function does anything, in particular before accessing any tables?

    Thread Starter theslink2000

    (@theslink2000)

    Forgive me for being thick but what is the utimer() function? I can’t seem to find reference to it in Google. Failing that, what exactly is it you’re suggesting bud?

    Moderator bcworkz

    (@bcworkz)

    Err.. I meant “usleep”. My brain has a short somewhere 🙁 Talk about thick! Sorry to send you on a fruitless search. Put something like usleep(500000); as the first line of your function.

    Thread Starter theslink2000

    (@theslink2000)

    No worries bud, I’ll give it a try and see how it goes but it makes sense.

    Cheers.

    Thread Starter theslink2000

    (@theslink2000)

    Sadly it doesn’t seem to have any effect, no matter how long I extend the time too. Maybe I should just override the welcome email and stop the function working and use the form submission function instead as the user should be created before the form submission is completed, which may be why this isn’t working thinking about it.

    Any thoughts?

    Moderator bcworkz

    (@bcworkz)

    I don’t think it’ll matter. The user notification shouldn’t be run until after the form’s submitted in any case. When you say it doesn’t work, what are you seeing that tells you it doesn’t work? Is it the email simply does not get delivered?

    I’ve noticed a similar odd behavior when someone new posts a comment. I should receive an email notification via a very similar mechanism. I don’t always get a message. Yet when I pretend to be a new commenter, I always receive a message.

    Thread Starter theslink2000

    (@theslink2000)

    Sorry for the delayed response bud.

    By not working I mean the email arrives but missing the correct metadata, the place where it should be is simply blank, no matter what the time delay. I’ve upped it to over 10 seconds and it still behaves the same way sadly.

    I’ve gone down the other route of using the forms after submission hook and it’s worked perfectly for one user type but the other isn’t working with identical code so I’m currently debugging it now.

    However, I’d still appreciate any thoughts you may have.

    Cheers.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘wp_new_user_notification and Custom Post Data Issue’ is closed to new replies.