/** * Maybe log a recommendation sale * Iterates through items in the payment and if one is a recommendation logs it * * @since 1.2.6 * @param int $payment_id The Payment ID being completed * @return void */ function edd_rp_log_recommendation_sale($payment_id) { $payment_items = edd_get_payment_meta_cart_details($payment_id, true); foreach ($payment_items as $item) { if (!empty($item['item_number']['recommendation_source'])) { $edd_log = new EDD_Logging(); $log_data = array('post_parent' => $item['item_number']['recommendation_source'], 'post_date' => edd_get_payment_completed_date($payment_id), 'log_type' => 'recommendation_sale'); $log_meta = array('payment_id' => $payment_id, 'download_id' => $item['id'], 'price' => $item['price'], 'quantity' => $item['quantity'], 'item_price' => $item['item_price']); $log_entry = $edd_log->insert_log($log_data, $log_meta); } } }
/** * Checks if a file is at its download limit * * This limit refers to the maximum number of times files connected to a product * can be downloaded. * * @since 1.3.1 * @uses EDD_Logging::get_log_count() * @param int $download_id Download ID * @param int $payment_id Payment ID * @param int $file_id File ID * @param int $price_id Price ID * @return bool True if at limit, false otherwise */ function edd_is_file_at_download_limit($download_id = 0, $payment_id = 0, $file_id = 0, $price_id = false) { // Checks to see if at limit $logs = new EDD_Logging(); $meta_query = array('relation' => 'AND', array('key' => '_edd_log_file_id', 'value' => (int) $file_id), array('key' => '_edd_log_payment_id', 'value' => (int) $payment_id), array('key' => '_edd_log_price_id', 'value' => (int) $price_id)); $ret = false; $download_count = $logs->get_log_count($download_id, 'file_download', $meta_query); $download_limit = edd_get_file_download_limit($download_id); $unlimited_purchase = edd_payment_has_unlimited_downloads($payment_id); if (!empty($download_limit) && empty($unlimited_purchase)) { if ($download_count >= $download_limit) { $ret = true; // Check to make sure the limit isn't overwritten // A limit is overwritten when purchase receipt is resent $limit_override = edd_get_file_download_limit_override($download_id, $payment_id); if (!empty($limit_override) && $download_count < $limit_override) { $ret = false; } } } return (bool) apply_filters('edd_is_file_at_download_limit', $ret, $download_id, $payment_id, $file_id); }
/** * Converts old sale and file download logs to new logging system * * @since 1.3.1 * @uses WP_Query * @uses EDD_Logging * @return void */ function edd_v131_upgrades() { if (get_option('edd_logs_upgraded')) { return; } if (version_compare(get_option('edd_version'), '1.3', '>=')) { return; } ignore_user_abort(true); if (!edd_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) { set_time_limit(0); } $args = array('post_type' => 'download', 'posts_per_page' => -1, 'post_status' => 'publish'); $query = new WP_Query($args); $downloads = $query->get_posts(); if ($downloads) { $edd_log = new EDD_Logging(); foreach ($downloads as $download) { // Convert sale logs $sale_logs = edd_get_download_sales_log($download->ID, false); if ($sale_logs) { foreach ($sale_logs['sales'] as $sale) { $log_data = array('post_parent' => $download->ID, 'post_date' => $sale['date'], 'log_type' => 'sale'); $log_meta = array('payment_id' => $sale['payment_id']); $log = $edd_log->insert_log($log_data, $log_meta); } } // Convert file download logs $file_logs = edd_get_file_download_log($download->ID, false); if ($file_logs) { foreach ($file_logs['downloads'] as $log) { $log_data = array('post_parent' => $download->ID, 'post_date' => $log['date'], 'log_type' => 'file_download'); $log_meta = array('user_info' => $log['user_info'], 'file_id' => $log['file_id'], 'ip' => $log['ip']); $log = $edd_log->insert_log($log_data, $log_meta); } } } } add_option('edd_logs_upgraded', '1'); }
/** * Displayes the source dropdown menu * * @since 1.2.6 * @return void */ public function source_filter() { $edd_logs = new EDD_Logging(); $log_query = array('log_type' => 'recommendation_sale', 'posts_per_page' => -1, 'fields' => array('post_parent')); $logs = $edd_logs->get_connected_logs($log_query); if ($logs) { foreach ($logs as $log) { $sources[$log->post_parent] = get_the_title($log->post_parent); } $dropdown_args = array('options' => $sources, 'name' => 'source', 'id' => 'source', 'selected' => !empty($_GET['source']) ? absint($_GET['source']) : false, 'show_option_all' => _x('All Sources', 'all dropdown items', 'edd-rp-txt'), 'show_option_none' => false); echo EDD()->html->select($dropdown_args); } }
/** * Get an array of all the log IDs using the EDD Logging Class * * @return array if logs, null otherwise * @param $download_id Download's ID */ function get_log_ids($download_id = '') { // Instantiate a new instance of the class $edd_logging = new EDD_Logging(); // get logs for this download with type of 'sale' $logs = $edd_logging->get_logs($download_id, 'sale'); // if logs exist if ($logs) { // create array to store our log IDs into $log_ids = array(); // add each log ID to the array foreach ($logs as $log) { $log_ids[] = $log->ID; } // return our array return $log_ids; } return null; }
/** * Assign selected courses to members of a paticular level. * @param Level ID in which members will get courses enrollment adjusted. */ protected function retroactive_assignment($level_ID) { //Get all transactions from EDD $logging = new EDD_Logging(); $transactions = $logging->get_logs($level_ID); $payment_ids = array(); $customer_ids = array(); //Convert log entries into payment IDs if ($transactions) { foreach ($transactions as $key => $transaction) { $payment_ids[] = get_post_meta($transaction->ID, '_edd_log_payment_id', true); } } //Get IDs that are member of membership level if (count($payment_ids) > 0) { foreach ($payment_ids as $key => $payment_id) { $customer_ids[$key] = get_post_meta($payment_id, '_edd_payment_user_id', true); } } //clean up duplicate IDs $customer_ids = array_unique($customer_ids); $page = new PageBuilder(false); //Enroll members of level if (count($customer_ids) > 0) { foreach ($customer_ids as $customer_id) { $memberLevels = edd_get_users_purchased_products($customer_id); $userLevels = array(); foreach ($memberLevels as $key => $memberLevel) { $userLevels[$key] = $memberLevel->ID; } // Over to the parent class to handle the sync of data. parent::handle_courseSync($customer_id, $userLevels); $page->showMessage(__('All members were successfully retroactively enrolled into the selected courses.', 'wp_courseware')); } return; } else { $page->showMessage(__('No existing members found for the specified level.', 'wp_courseware')); } }
/** * Export all downloads to CSV * * @access private * @since 1.2 * @return void */ function edd_export_all_downloads_history() { if (current_user_can('administrator')) { ignore_user_abort(true); if (!edd_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) { set_time_limit(0); } $report_args = array('post_type' => 'download', 'post_status' => 'publish', 'posts_per_page' => -1, 'order' => 'post_date'); $downloads = get_posts($report_args); if (!empty($downloads)) { header("Content-type: text/csv"); $today = date_i18n("Y-m-d"); header("Content-Disposition: attachment; filename=user_downloads_history-{$today}.csv"); header("Pragma: no-cache"); header("Expires: 0"); echo '"' . __('Date', 'edd') . '",'; echo '"' . __('Downloaded by', 'edd') . '",'; echo '"' . __('IP Address', 'edd') . '",'; echo '"' . __('Product', 'edd') . '",'; echo '"' . __('File', 'edd') . '"'; echo "\r\n"; foreach ($downloads as $report) { $page = isset($_GET['paged']) ? intval($_GET['paged']) : 1; $download_log = new EDD_Logging(); $file_downloads = $download_log->get_connected_logs(array('post_parent' => $report->ID, 'posts_per_page' => -1, 'log_type' => 'file_download', 'monthnum' => date('n'), 'year' => date('Y'))); $files = edd_get_download_files($report->ID); if (is_array($file_downloads)) { foreach ($file_downloads as $log) { $user_info = get_post_meta($log->ID, '_edd_log_user_info', true); $file_id = (int) get_post_meta($log->ID, '_edd_log_file_id', true); $ip = get_post_meta($log->ID, '_edd_log_ip', true); $user_id = isset($user_info['id']) ? $user_info['id'] : 0; $user_data = get_userdata($user_id); if ($user_data) { $name = $user_data->display_name; } else { $name = $user_info['email']; } $file_id = (int) $file_id !== false ? $file_id : 0; $file_name = isset($files[$file_id]['name']) ? $files[$file_id]['name'] : null; echo '"' . $log->post_date . '",'; echo '"' . $name . '",'; echo '"' . $ip . '",'; echo '"' . html_entity_decode(get_the_title($report->ID)) . '",'; echo '"' . $file_name . '"'; echo "\r\n"; } // endforeach } } exit; } } else { wp_die(__('Export not allowed for non-administrators.', 'edd')); } }