Hi @sadiqodunsi
It’s not clear. how do you run your code? Are you attaching it to a UM hook?
Regards,
Hi @champsupertramp
No, I am not attaching it to a UM hook. My code has nothing to do with UM plugin. The problem is just that when UM plugin is activated, $wpdb->insert() method runs multiple times. When I deactivate UM plugin, it runs just once (as expected). I know it runs multiple times on page load because the data are inserted to db multiple times.
Below is a test code I am using that goes into a shortcode function in functions.php. When I use the code in a shortcode, the data is inserted twice and when I use it in init hook, the data is inserted about 5 times.
$email = new V_Saved_Email();
$email->create( [ 'email_id' => 'test_key' ] );
The $email->create() method eventually calls $wpdb->insert()
It seems this is a common problem after doing a Google search. Some people have noted that Yoast SEO plugin causes the issue for them but in my case it is UM plugin. See some questions about the issue below:
https://wordpress.stackexchange.com/questions/256896/wpdb-insert-is-running-multiple-times-on-page-load-but-only-called-once
https://stackoverflow.com/questions/25159778/wordpress-insert-query-runs-3-times#answer-42724307
Hi @sadiqodunsi
Could you please confirm what version of UM you’re using? Also, does this issue occurs when leaving UM as the only active plugin and changing your theme to a default WP theme such as 2020 or 2021?
Regards,
Hi @champsupertramp
Yes the issue occurs when UM is the only active plugin and using the default WP 2021 theme. When I deactivate UM plugin, everything works fine.
Below is the test code I used in 2021 default theme:
function show_test_output() {
ob_start();
$args = array(
'email_id' => 'testing',
'title' => 'testing',
'subject' => 'testing',
'content' => 'testing'
);
global $wpdb;
$table_name = "{$wpdb->prefix}test_saved_emails";
echo var_dump( $wpdb->insert( $table_name, $args ) );
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_shortcode( 'test_output', 'show_test_output');
I already created the {$wpdb->prefix}test_saved_emails db and I added the above code to functions.php in 2021 WP default theme.
All records are inserted twice with UM plugin active.
Hello,
Please see the video below to view the issue on my site:
https://drive.google.com/file/d/1dJ8gqq01D5X4FsOgYJBIf5YY82whAODv/view
Regards
Hi @sadiqodunsi
Could you please try the pre-release version 2.2.0 in the link?
https://github.com/ultimatemember/ultimatemember/tags
Ensure that you’ve created a full backup of your site before you update it manually.
Regards,
Hey there!
This thread has been inactive for a while so weβre going to go ahead and mark it Resolved.
Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and weβd be happy to help. π
Regards,
Hello,
Even after updating to the latest version, the issue still exists. Now I noticed that wp_mail() function also sends email twice if UM plugin is active. Everything works fine when I disable UM.
I am currently trying to log emails sent with wp_mail() function. I am using wp_mail filter to insert to database but the data gets inserted twice just as 2 emails get sent. I only call wp_mail() function once so only one email should be sent and just one record should be inserted to DB.
-
This reply was modified 4 years, 8 months ago by
sadiqodunsi.
Hi @sadiqodunsi
Do you have other custom codes added to your site related to UM?
Regards,
No. I have tested as you suggested earlier. I have tested with default themes and deactivated all plugins.
Hi @sadiqodunsi
Do you have any Cronjob running on the server that triggers the pages of your site?
Regards,