jasemcnotty
Forum Replies Created
-
Forum: Plugins
In reply to: [Ultimate WP Mail] Scheduling and “Send Later” issueHi Jay
This wasn’t actually resolved, sorry if I clicked something to mark it “resolved”… BUT it is now! woohoo
Just posting this if it might help someone else.
I think there’s an error in the code of the following file:
/includes/Notifications.class.php
line: 730
The send_scheduled_emails() function references the “email” array as a value in the foreach loop looking for a key that is nested in a deeper array (params) so the conditions for “list” and “all” sends will never be met.. it will always default to the “else”.
eg: the condition for list send was:
elseif ( array_key_exists( ‘send_type’, $email ) && $email[‘send_type’] == ‘list’ )
it should be:
elseif ( array_key_exists( ‘send_type’, $email[‘params’] ) && $email[‘params’][‘send_type’] == ‘list’ )
I’ll post my rewritten function below. I’ve also added a bit to account for the timezone problem I was having. I’ve sure there’s better ways to write it, but works for me. (also make sure to set your timezone in WP->Settings->General)
Thanks again for pointing me in the right direction.
public function send_scheduled_emails() { $scheduled_emails = (array) get_option( 'EWD_UWPM_Scheduled_Emails' ); foreach ( $scheduled_emails as $key => $email ) { if ( ! is_array( $email ) ) { unset( $scheduled_emails[ $key ] ); continue; } $myTimezone = wp_timezone_string(); $currentTime = new DateTime(); $currentTime->setTimezone(new DateTimeZone($myTimezone)); $currentTimeString = $currentTime->format('Y-m-d H:i'); $customchecktime = str_replace('T', ' ', $email['send_time']); // this should give a format of YYYY-MM-DD HH:MM if ( $customchecktime > $currentTimeString ) { continue; } $message_format = get_post_type( $email['params']['email_id'] ) == EWD_UWPM_SMS_POST_TYPE ? 'sms' : 'email'; if ( array_key_exists( 'send_type', $email['params'] ) && $email['params']['send_type'] == 'all' ) { if ( $sms ) { $this->sms_all_users( $email['params'] ); } else { $this->email_all_users( $email['params'] ); } } elseif ( array_key_exists( 'send_type', $email['params'] ) && $email['params']['send_type'] == 'list' ) { if ( $sms ) { $this->sms_user_list( $email['params'] ); } else { $this->email_user_list( $email['params'] ); } } else { if ( $sms ) { $this->sms_user( $email['params'] ); } else {$this->email_user( $email['params'] ); } } unset( $scheduled_emails[ $key ] ); } update_option( 'EWD_UWPM_Scheduled_Emails', $scheduled_emails ); }
Forum: Plugins
In reply to: [Ultimate WP Mail] Scheduling and “Send Later” issueHi Jay
Sorry for the late reply, I’ve gotten round to doing some more testing with this in the last few days.
I’ve made a completely new WP install (v6.2.2) on a different host (php v7.4) and different domain with the default theme and no plugins other than UWPM (the latest version v1.2.2, unmodified)
I enabled debugging.
I’m not using SMTP.
I created 3 users with different email addresses, and added them to a new list.
The results are these:
I can send to any single user immediately
I can send to a user list immediately
I CAN schedule (send later) to any single user
I can NOT schedule (send later) to a user listI also noticed that the date/time for scheduling is UTC, which means I need to subtract an hour manually to get the timezone I’m in (GMT+1)… but that’s a minor thing, I just bear it in mind when testing.
The debug file showed a few things, but nothing that shouts critical error I don’t think:
[18-Jul-2023 14:40:45 UTC] PHP Notice: Undefined variable: sms in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/includes/Notifications.class.php on line 754 [18-Jul-2023 14:40:45 UTC] PHP Notice: Undefined index: target in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/includes/Notifications.class.php on line 1047 [18-Jul-2023 14:46:47 UTC] PHP Notice: Undefined variable: sms in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/includes/Notifications.class.php on line 754 [18-Jul-2023 14:46:47 UTC] PHP Notice: Undefined index: target in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/includes/Notifications.class.php on line 1047 [18-Jul-2023 14:51:35 UTC] PHP Notice: Trying to get property 'term_id' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176 [18-Jul-2023 14:51:35 UTC] PHP Notice: Trying to get property 'name' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176 [18-Jul-2023 14:51:35 UTC] PHP Notice: Trying to get property 'term_id' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176 [18-Jul-2023 14:51:35 UTC] PHP Notice: Trying to get property 'name' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176 [18-Jul-2023 14:56:35 UTC] PHP Notice: Undefined variable: sms in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/includes/Notifications.class.php on line 754 [18-Jul-2023 15:25:50 UTC] PHP Notice: Undefined variable: sms in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/includes/Notifications.class.php on line 754 [18-Jul-2023 17:56:42 UTC] PHP Notice: Trying to get property 'term_id' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176 [18-Jul-2023 17:56:42 UTC] PHP Notice: Trying to get property 'name' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176 [18-Jul-2023 17:56:42 UTC] PHP Notice: Trying to get property 'term_id' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176 [18-Jul-2023 17:56:42 UTC] PHP Notice: Trying to get property 'name' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176 [18-Jul-2023 18:11:02 UTC] PHP Notice: Trying to get property 'term_id' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176 [18-Jul-2023 18:11:02 UTC] PHP Notice: Trying to get property 'name' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176 [18-Jul-2023 18:11:02 UTC] PHP Notice: Trying to get property 'term_id' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176 [18-Jul-2023 18:11:02 UTC] PHP Notice: Trying to get property 'name' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176 [18-Jul-2023 18:19:14 UTC] PHP Notice: Trying to get property 'term_id' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176 [18-Jul-2023 18:19:14 UTC] PHP Notice: Trying to get property 'name' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176 [18-Jul-2023 18:19:14 UTC] PHP Notice: Trying to get property 'term_id' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176 [18-Jul-2023 18:19:14 UTC] PHP Notice: Trying to get property 'name' of non-object in /home/xxxxxxxxx/public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 176
The earlier sms reference is from the public function send_scheduled_emails(). I removed the condition for sms as I’m only testing the email side.
When I did that, the scheduled time for a send passes, the EWD_UWPM_Scheduled_Emails field in the wp_options table is emptied, but no emails are sent and nothing at all is added to the debug file. It’s strange.
I had a look at the EWD_UWPM_Scheduled_Emails value and compared it with the ewd-uwpm-email-lists value (in the options table), specifically the list id.
The EWD_UWPM_Scheduled_Emails value contains this:
s:7:”list_id”;i:2;s:9:”send_time”;s:16:”2023-07-18T19:25″;s:9:”send_type”;s:4:”list”
..and the ewd-uwpm-email-lists value contains this:
s:2:”id”;s:1:”2″;s:4:”name”;s:8:”New List”
Could it be that the script is getting mucked up with the variable types of the id reference being different?.. I’m assuming that’s what the s and i mean, for string and integer, or maybe the key names “id” and “list_id” being different?
As I mentioned above, I can schedule sending to a single user fine, it’s just lists that are the problem for me at the moment.
Sorry for the wall of text.. I’ll have another crack at figuring this out tomorrow and report back.
Forum: Plugins
In reply to: [Ultimate WP Mail] Scheduling and “Send Later” issueHi Jay
No worries, we’re all busy.. appreciate you replying.
The scheduled times have passed. Checked the db, and the EWD_UWPM_Scheduled_Emails value is “empty” now… a:0:{}
.. but no emails were sent, received or shown in the logs.
There are loads of other emails being sent using the WP core and other plugins (including UWPM when sending immediately), so I don’t think that’s the issue.
Could you suggest which files to check that handle both assigning the queue value and, more importantly, how the queue is triggered and what happens then?
Thanks again for your help.
Forum: Plugins
In reply to: [Ultimate WP Mail] Scheduling and “Send Later” issueThanks for the reply Jay.
Yes I’m familiar with the technique of activity-triggered queues to sort of simulate cron jobs. The site has a decent amount of activity on it. The front gets regular visits throughout the day, and there are 3 other admins besides myself tinkering on the backend.
I checked the EWD_UWPM_Scheduled_Emails option value in the options table. This is what is in there at the moment (I’ve removed the actual email content).
a:2:{i:4;a:2:{s:9:"send_time";s:16:"2023-06-14T17:58";s:6:"params";a:8:{s:8:"email_id";i:1099;s:11:"email_title";s:24:"Feedback and Suggestions";s:13:"email_content";s:3271:" <!-- redacted email_content (html) here --> ";s:7:"list_id";i:7;s:9:"send_time";s:16:"2023-06-14T17:58";s:9:"send_type";s:4:"list";s:9:"interests";a:3:{s:15:"post_categories";a:0:{}s:15:"uwpm_categories";a:0:{}s:13:"wc_categories";a:0:{}}s:11:"woocommerce";a:5:{s:19:"previous_purchasers";s:5:"false";s:18:"product_purchasers";s:5:"false";s:20:"previous_wc_products";s:0:"";s:19:"category_purchasers";s:5:"false";s:22:"previous_wc_categories";s:0:"";}}}i:5;a:2:{s:9:"send_time";s:16:"2023-06-13T16:58";s:6:"params";a:8:{s:8:"email_id";i:1099;s:11:"email_title";s:24:"Feedback and Suggestions";s:13:"email_content";s:3271:" <!-- redacted email_content (html) here --> ";s:7:"list_id";i:7;s:9:"send_time";s:16:"2023-06-13T10:18";s:9:"send_type";s:4:"list";s:9:"interests";a:3:{s:15:"post_categories";a:0:{}s:15:"uwpm_categories";a:0:{}s:13:"wc_categories";a:0:{}}s:11:"woocommerce";a:5:{s:19:"previous_purchasers";s:5:"false";s:18:"product_purchasers";s:5:"false";s:20:"previous_wc_products";s:0:"";s:19:"category_purchasers";s:5:"false";s:22:"previous_wc_categories";s:0:"";}}}}
This is a screenshot of other, maybe-related fields in the option table
Thanks
Forum: Plugins
In reply to: [Ultimate WP Mail] Critical error on Lists pagesizeof() is an alias for count()
in php version 8+ count/sizeof will throw an error (rather than a warning as in ver 7 or below ) if it’s passed the wrong parameter type.. ie, if the parameter is null or not an array or countable object and that’s probably what’s causing the problem
https://www.php.net/manual/en/function.count.php#refsect1-function.count-changelog
anywhere that uses count or sizeof should check to see if the thing being counted is an array before you try to count it.. eg:
// anywhere you see count() you can substitute for sizeof() // example existing code echo count($myarray); // php version 7+ change to if(is_countable($myarray)) { echo count(myarray); } // any php version but you know you're expecting an array specifically if(is_array($myarray)) { echo count($myarray); } // you can use shorthand if/else but only if there's an else, eg echo (is_countable($myarray) ? count($myarray) : '');
Forum: Plugins
In reply to: [Ultimate WP Mail] Critical error on Lists pageI’m not a dev on the plugin so try this at your own risk.
It might be a php version issue if the server version has been “upgraded” recently.
If you’re comfortable editing php files, you could try the following:
In the file: /public_html/wp-content/plugins/ultimate-wp-mail/ewd-uwpm-templates/admin-send-mail.php on line 57, change…
<?php echo esc_html( $list->name ); ?> ( <?php echo sizeOf( $list->user_list ) . ' ' . __(' Users', 'ultimate-wp-mail'); ?> )
to…
<?php echo esc_html( $list->name ); ?> ( <?php echo (is_array($list->user_list) ? sizeOf( $list->user_list ) : '0') . ' ' . __(' Users', 'ultimate-wp-mail'); ?> )
if it is php version related, there may be other array sizeof/count issues elsewhere but you won’t know until you get past this error
good luck
Forum: Plugins
In reply to: [Ultimate WP Mail] Reference “List Name” in emal templateThanks for the reply Jay, definitely pointed me in the right direction. I’ll outline the solution I used if it helps anyone else. Quick disclaimer, this is definitely not the only way to achieve this and almost certainly not the best/safest way as it involves changing some of the “core” php files in the plugin.
adding a custom element to the TinyMCE email variables:
add this to main functions.php file, or using a code snippet plugin
function insert_list_name_into_mass_email() { return '[email_list_name]'; } add_action('uwpm_register_custom_element', 'register_my_custom_element'); function register_my_custom_element() { uwpm_register_custom_element( 'email_list_name', array( 'label' => 'Email List Name', '', 'callback_function' => 'insert_list_name_into_mass_email' ) ); }
This will create a custom shortcode available in the “email variables” dropdown called [email_list_name]. The substitution that happens in insert_list_name_into_mass_email() doesn’t really matter, so I just have it return the same value as the original shortcode (ie, [email_list_name] becomes [email_list_name]. You’ll see why it doesn’t matter next.
This is where I’m sure there are better ways to do it but it works for me. Modify the file: /plugins/ultimate-wp-mail/includes/Ajax.class
around line 126, just before the $params = array( bit of the email_user_list function, add the following:
// check for presence of custom shortcode if(strpos($_POST['email_content'], '[email_list_name]') !== false && is_numeric($_POST['list_id'])) { // get all list data from wp_options table $getlists = array_filter( (array) get_option( 'ewd-uwpm-email-lists' ) ); // get array key based on list id $mykey = array_search($_POST['list_id'], array_column($getlists, 'id')); if(is_numeric($mykey)) { $getlist_name = sanitize_text_field($getlists[$mykey]->name); if(!empty($getlist_name)) { // replace shortcode with list name $_POST['email_content'] = str_replace('[email_list_name]', $getlist_name, $_POST['email_content']); } } }
Keep a copy of this file (Ajax.class) on your local computer or in a redundant folder on the web host as it will probably be overwritten when updating the plugin.