Closed despecial closed 6 years ago
If you didn't unregister the default handler, that will fire too.
Are the mails the same, or different?
And what version are you running?
I didn't unregister anything. Haven't read about that in the documentation. It's the same email that gets send - so my function is fired twice. edit: as I understand - unregistering the default handler is not necessary since the function I use to send the "thank you" mail is only added via the ID_post_validate action.
Version is 1.4.3
The default handler is registered here. You can remove it with remove_action('wplf_post_validate_submission', 'wplf_send_email_copy')
. That's a bit annoying for the average user, so there's also checkbox in the form edit page that lets you toggle the default email. But there was a bug on the checkbox: #98
That bug is fixed in the master branch, but it has not been released yet. 1.5 is in a beta, and I'm running it in production at the moment, so it works. Can you test if the issue persists on the new version?
https://github.com/libreform/wp-libre-form/releases/tag/1.5.0.2-beta
I don't have any ideas on why it fires twice. I can't search the repo througly for post_validate_submission at the moment, due to leaving my real computer at work, but I'm fairly certain that these are the only lines that call actions with that name.
If you're calling wplf_ajax_submit_handler
twice I guess it would happen, but that shouldn't happen unless you're actually submitting the form twice somehow.
It's a long shot, but do you have any plugins installed which could potentially change the way wp_ajax_nopriv_*
& wp_ajax_*
hooks work?
Normally only one of them is executed, wp_ajax_*
for logged in users and wp_ajax_nopriv_*
for anonymous users but it's WordPress and can be changed...
Hey, thanks for your quick reply and ideas.
So here is the code I use to show the form.
[libre-form id="164" xhtml="data-abide novalidate" xclass="hf_form"]
I use the validation framework from "Foundation" which checks the input and blocks the form if necessary.
The email checkbox is unchecked in all the forms and I already added the patch manually for your bug in #98 - pretty sure it's not the problem because the content of the mail is the one from the post_submission filter.
I will try to test the beta version but first I have to check what code changes I added to the current version (xhtml parameter because of the attribute 'bug').
The attribute bug is also fixed, and it could also be worked around with novalidate=""
& data-abide=""
.
Update: checked with your beta version and added your suggestion to the shortcode the work around is functional but the mails get sent twice.
To debug I added the form ID to the mails that go out. It's the same for both mails.
In my functions.php I have these two lines (to use the same function for several forms)
add_action( 'wplf_39_post_validate_submission', 'mailcopy_table' );
add_action( 'wplf_164_post_validate_submission', 'mailcopy_table' );
In the submissions list there is only one entry. So it looks like the post validation gets fired twice.
Checked calls to *_post_validate_submission.
$ ag -Q "post_validate_submission"
inc/wplf-ajax.php
107: do_action( 'wplf_post_validate_submission', $return );
108: do_action( "wplf_{$form->post_name}_post_validate_submission", $return );
109: do_action( "wplf_{$form->ID}_post_validate_submission", $return );
inc/wplf-form-actions.php
3:add_action( 'wplf_post_validate_submission', 'wplf_send_email_copy', 20 );
README.md
126:### Action: wplf_post_validate_submission
134:- `wplf_{form_id}_post_validate_submission`
135:- `wplf_{form_slug}_post_validate_submission`
142:add_action( 'wplf_post_validate_submission', 'my_email_thankyou' );
$form
is a result of get_post($_POST['_form_id'])
. If you haven't changed post_name to be the ID I'm running really low on ideas.
It's (probably) possible to filter get_post to do that, but I don't see why anyone or anything would do so.
As an immediate fix to the duplicate mail problem, you could save something to the submission post meta to indicate that the mail has been sent already, and return early for the second call.
Doesn't fix the bug but should fix your problem.
Tried to debug it and added microtime to the output so that I can see if it's a problem within the function or that the script sends the post_submission filter twice.
Even removed the default handler. No change.
Then I used this function to check the execution of your filter: https://codex.wordpress.org/Function_Reference/did_action
And indeed - the second mail shows the count of 2. So something is triggering the execution of this filter again.
PS: I can use this to function to stop sending the mail a second time but this bug should be investigated..
I debugged the actions that are executed when submitting the form. Here is an extract of it
Action Name : loop_start
Action Name : get_user_metadata
Action Name : content_pagination
Action Name : the_post
Action Name : the_title
Action Name : no_texturize_tags
Action Name : no_texturize_shortcodes
Action Name : attribute_escape
Action Name : post_password_required
Action Name : the_content
Action Name : no_texturize_tags
Action Name : no_texturize_shortcodes
Action Name : pre_do_shortcode_tag
Action Name : shortcode_atts_libre-form
Action Name : query
Action Name : get_post_status
Action Name : wplf_164_form
Action Name : wplf_164_form
Action Name : wplf_form
Action Name : pre_option_use_smilies
Action Name : alloptions
Action Name : option_use_smilies
Action Name : attribute_escape
Action Name : attribute_escape
Action Name : attribute_escape
Action Name : attribute_escape
Action Name : attribute_escape
Action Name : attribute_escape
Action Name : attribute_escape
Action Name : pre_option_show_on_front
Action Name : alloptions
Action Name : option_show_on_front
Action Name : pre_option_page_on_front
Action Name : alloptions
Action Name : option_page_on_front
Action Name : get_page_uri
Action Name : pre_option_home
Action Name : alloptions
Action Name : option_home
Action Name : set_url_scheme
Action Name : home_url
Action Name : user_trailingslashit
Action Name : _get_page_link
Action Name : page_link
Action Name : the_permalink
Action Name : clean_url
Action Name : attribute_escape
Action Name : attribute_escape
Action Name : do_shortcode_tag
Action Name : pre_option_use_smilies
Action Name : alloptions
Action Name : option_use_smilies
Action Name : pre_option_wp_rocket_settings
Action Name : alloptions
Action Name : option_wp_rocket_settings
Action Name : pre_get_rocket_option_lazyload
Action Name : get_rocket_option_lazyload
Action Name : loop_end
not sure why wplf_form is executed twice. may this be the source of the problem? besides that I suggest to add the doaction('wplf'._POST[_form_id].'...) check in your script, so that if ever another plugin hooks in, it wont be executed more than once..
It shouldn't be. I've never had this kind of problem, and I tested the mails pretty thoroughly in the pr that fixed #98. It was only one email at all times.
I've no idea why this is happening.
Couldn't find out why the plugin processes it twice. The mail copy I send after validation gets send two times.
add_action( 'wplf_341_post_validate_submission', 'mailcopy_table' );