• Resolved AWOL

    (@awol)


    I’m sure that I am missing something somewhere, but having looked through the support threads and the documentation, I can’t find a way for a form submitted by User A, that is on a post by User B, can send an email to User B. There doesn’t seem to be a built in option to either populate a field with the post author email, or in the Email settings of the form, so is there some sort of filter that can achieve this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @awol,

    So are the users gonna change based on the post? Are the same forms going to be added on multiple posts which have different users and email should be sent dynamically based on post author? Is the form used only when logged in?

    If there isn’t any change to the users then you only have to create a new Email Notification in the form which has the Email Field assigned as its Recipient as shown in the following screenshot.

    Screenshot at 17:12:49.png

    The email-1 in the above screenshot would refer to the existing Email field present in the form. So that when a user submits the form the newly created notification would get sent to his email.

    You could also use the “Hidden” field instead of the “Email” field if you want the email to get picked automatically for the logged-in user.

    Could you please advise the workflow you are looking to achieve so that we could assist further if needed?

    Best Regards,

    Nithin

    Thread Starter AWOL

    (@awol)

    Hi Nithin @wpmudevsupport11,
    It is one form that will appear on a custom post type that has been posted by any other logged in user, for the current user to fill in and for the post author to be notified. How do I get the email address of the post author into the form? I know how to get the current user’s email but there is no option that I can see for the post author in any of the fields or in the email settings. So yes, the same form is going to be added on multiple posts which have different users and email should be sent dynamically based on post author, and yes, the form can only be submitted by a logged in user.

    Thread Starter AWOL

    (@awol)

    Hi Nithin @wpmudevsupport11,
    Just to let you know, I am currently devising a workaround where I use the WordPress add_query_arg() in a filter to append the required information, but I haven’t tested it yet. Once I have I will post again here, but of course if this can either be added as a built in function to the plugin, or there is some other kind of filter I would be pleased to hear it.

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @awol,

    Thanks for explaining further. I’m afraid there isn’t an out-of-the-box setting for such a workflow supported on the plugin side.

    I’m bringing this to our developer’s attention in order to check and suggest a workaround regarding this.

    Will keep you posted once we get further feedback asap.

    Best Regards,

    Nithin

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @awol,

    You can try this snippet to grab the post author email:

    <?php
    
    add_filter( 'forminator_field_hidden_field_value', 'wpmudev_populate_author_email_field', 10, 4 );
    function wpmudev_populate_author_email_field( $value, $saved_value, $field, $hidden_field ){
    	if ( 'custom_value' == $saved_value && '{author_mail}' == $value ) {        		
    		$value = sanitize_text_field( get_the_author_meta('user_email') );
    	}
    	return $value;
    }
    

    The above snippet can be added as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Once the code is added, you’ll need to create a Hidden field with the following custom value:
    https://imgur.com/9LCvWLk

    You can then add the above Hidden Field as the Recipient for your Email notification and the email should get to the Post Author.

    Screenshot at 14:05:38.png

    Can confirm it works fine when tested in my test site. Please do check and let us know if you have any further queries.

    Best Regards,

    Nithin

    Thread Starter AWOL

    (@awol)

    Hi Nithin @wpmudevsupport11,

    Thank you for the code snippet. I actually managed to write a function to achieve what I wanted (and more) which might be useful to others, as it can go in a child theme functions file, allows adding many other bits of data (almost whatever you want), and can be used with other plugins or circumstances so I have included it below.

    //Function to alter url to include post author and email as query parameters (plus anything else you want)
    add_filter( 'post_type_link', 'append_query_string', 10, 2 );
    function append_query_string( $url, $post ) {
    //Here you can add if statements to filter out any posts you don't want to add the query parameter to - mine filters classified listings CPT but you could filter categories or other post-meta
        if (($post->post_type != 'rtcl_listing') && ($post->ad_type == 'member')){
            return;
        }
        $user_id = $post-> post_author;
        $user = get_user_by('id', $user_id);
        $email = $user->user_email;
        $name = $user->user_login;
        $arr_params = array( 'author_email' => $email, 'author_name' => $name );
        }
        return add_query_arg($arr_params, $url);
    }
    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @awol

    That’s a nice thing, thank you for sharing!

    Should we consider case closed then or do you still need some kind of assistance!

    Best regards,
    Adam

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Email to post author?’ is closed to new replies.