PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Assigning a submission to an author that already exists.

  1. astronauts
    Member

    L.S.,

    I have a problem with assigning users to a post captured via a Gravity form. The glitch is I want this to work for users that have already submitted a post and are registered at the first submit. I DO NOT want them to login.

    Some background:
    I'm building an internal corporate platform meant for capturing posts. To capture the posts, I'm using Gravity + UserReg add-on. I want to keep the threshold for submitting a post as low as possible, so I'm simply using a form that allows user to add a post without the hassle of registering. This is done automatically via the form without them ever knowing or receiving a password. Even more, I don't want my users to ever see -let alone login to- the WP backend.

    The glitch is users can add multiple posts. There's basically two entry conditions:
    (1) A user has never submitted an post before. Based on a condition ("have you submitted a post before? > no") the user form is set to register the user.
    (2) The user submitted a post before. Based on the same condition, the user registration is skipped.

    The problem here is that in the second condition the post/post isn't assigned to the user. This is absolutely essential for the platform to work. When I remove the condition, users simply get an error message when they submit a second post because they've already been registered at the first submit (which they won't understand).

    Is it possible to assign a post to an existing user with Gravity (based on matching e-mails)? I haven't found the option. I've tried to write a plugin that uses WP's set_as_author() (take the user email, assign the post to this user), but I'm simply not skilled enough to make this work.

    Therefore:
    (1) Am I missing something and IS it possible to assign a post to a user that already exists with Gravity in a form (based on matching emailadress provided) OR is there another way to accomplish this with Gravity?
    (2) Is this a planned development?

    Hope you can help!

    Posted 12 years ago on Saturday July 14, 2012 | Permalink
  2. To be clear, you are registering the user based on their submitted email on their initial submission and assigning the created post to that user via the User Registration add-on. Now you'd like to take this a step further and on subsequent submissions, the created post should be assigned to the existing user based on the re-submitted email address.

    Is this correct?

    Posted 12 years ago on Monday July 16, 2012 | Permalink
  3. astronauts
    Member

    Thanks for your response!

    Yes, that is correct.

    - Users fill out a front-end form that is captured as a post
    - Users that have filled-out the form before aren't registered anymore as they already exist in the DB
    - For those users, I want to grab the filled-out email@
    - Set the author of that submitted post to match that email@ or any other way to overwrite the standard author and set to the user that submitted the post.

    Does that clarify things? Hope so.

    Posted 12 years ago on Tuesday July 17, 2012 | Permalink
  4. Hi Astronauts,

    You can use the gform_after_submission hook to fire some functionality after the entry has been completely submitted and post created. You can then use the get_user_by() to pass the submitted email. If it returns a valid user, you can then assign that user ID to as the post author via the wp_update_post() function.

    Some psuedo code to get you started:

    [php]
    // update "1" to your form ID
    add_action('gform_after_submission_1', 'maybe_attribute_author');
    function maybe_attribute_author($entry) {
    
        $author = get_user_by("email", $entry['3']); // update the "3" to the ID of your form's email field
        if(!$author)
            return;
    
        $post = array();
        $post['ID'] = $entry['post_id'];
        $post['post_author'] = $author->ID;
        wp_update_post($post);
    
    }
    Posted 12 years ago on Thursday July 19, 2012 | Permalink
  5. astronauts
    Member

    Apparently I missed the email that notified me of your reply - but that's great, thanks! I'll try to make it work. Many thanks!

    Best,
    -Pim

    Posted 12 years ago on Thursday July 26, 2012 | Permalink
  6. David Peralty

    Let us know if any other issues come up.

    Posted 12 years ago on Thursday July 26, 2012 | Permalink