/** * Run WC-related conditions on the $item and see if it passes * * @param bool|WP_Error $passed * @param FUE_Sending_Queue_Item $item * @return bool|WP_Error */ public function check_item_conditions($passed, $item) { // only storewide for now if (fue_get_email_type($item->email_id) != 'storewide') { return $passed; } if (is_wp_error($passed)) { return $passed; } $conditions = $this->fue_wc->wc_conditions->get_conditions(); $email = new FUE_Email($item->email_id); $email_conditions = !empty($email->conditions) ? $email->conditions : array(); foreach ($email_conditions as $email_condition) { if (array_key_exists($email_condition['condition'], $conditions)) { // this is a WC condition $passed = $this->fue_wc->wc_conditions->test_condition($email_condition, $item); if (is_wp_error($passed)) { // immediately return errors return $passed; } } } return true; }
/** * Import all previous usage data that were not sent yet */ public static function import_usage_data() { global $wpdb; if (self::is_sending_usage_data_disabled()) { return; } $imported = get_option('fue_imported_previous_usage', false); if ($imported) { return; } $emails = $wpdb->get_results("\n SELECT eo.email_id, eo.date_sent\n FROM {$wpdb->prefix}followup_email_orders eo\n WHERE eo.is_sent = 1"); $sent_data = array(); foreach ($emails as $email) { $type = fue_get_email_type($email->email_id); $date = date('Y-m-d', strtotime($email->date_sent)); if (isset($sent_data[$date][$type])) { $sent_data[$date][$type]++; } else { $sent_data[$date][$type] = 1; } } if (empty($sent_data)) { return; } $site_id = self::get_site_id(); $date = date('Y-m-d'); $token = self::get_auth_token(); $resp = self::api_call('register_usage', array('site_id' => $site_id, 'dated' => 1, 'data' => $sent_data), $token); if (isset($resp->code) && $resp->code == 401) { // try to get a new token $token = self::get_auth_token(true); $resp = self::api_call('register_usage', array('site_id' => $site_id, 'dated' => 1, 'data' => $sent_data), $token); } update_option('fue_usage_last_report', current_time('timestamp')); update_option('fue_imported_previous_usage', true); }