コード例 #1
0
/**
 * 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');
}
コード例 #2
0
/**
 * Render Purchase Log Meta Box
 *
 * @access      private
 * @since       1.0 
 * @return      void
*/
function edd_render_purchase_log_meta_box()
{
    global $post;
    $sales = edd_get_download_sales_log($post->ID);
    $per_page = 10;
    if (isset($_GET['edd_sales_log_page'])) {
        $page = intval($_GET['edd_sales_log_page']);
        $offset = $per_page * ($page - 1);
        $sales_log = edd_get_download_sales_log($post->ID, true, $per_page, $offset);
    } else {
        $page = 1;
        $sales_log = edd_get_download_sales_log($post->ID, false);
    }
    echo '<table class="form-table">';
    echo '<tr>';
    echo '<th style="width:20%"><strong>' . __('Sales Log', 'edd') . '</strong></th>';
    echo '<td colspan="4" class="edd_download_stats">';
    _e('Each sale for this download is listed below.', 'edd');
    echo '</td>';
    echo '</tr>';
    if ($sales_log['sales']) {
        foreach ($sales_log['sales'] as $sale) {
            if ($sale['user_info']['id'] != 0) {
                $user_data = get_userdata($sale['user_info']['id']);
                $name = $user_data->display_name;
            } else {
                $name = $sale['user_info']['first_name'] . ' ' . $sale['user_info']['last_name'];
            }
            echo '<tr>';
            echo '<td class="edd_download_sales_log">';
            echo '<strong>' . __('Date:', 'edd') . '</strong> ' . $sale['date'];
            echo '</td>';
            echo '<td class="edd_download_sales_log">';
            echo '<strong>' . __('Buyer:', 'edd') . '</strong> ' . $name;
            echo '</td>';
            echo '<td colspan="3" class="edd_download_sales_log">';
            echo '<strong>' . __('Purchase ID:', 'edd') . '</strong> <a href="' . admin_url('edit.php?post_type=download&page=edd-payment-history&purchase_id=' . $sale['payment_id'] . '&edd-action=edit-payment') . '">' . $sale['payment_id'] . '</a>';
            echo '</td>';
            echo '</tr>';
        }
        // endforeach
        do_action('edd_purchase_log_meta_box');
    } else {
        echo '<tr>';
        echo '<td colspan=2" class="edd_download_sales_log">';
        echo __('No sales yet', 'edd');
        echo '</td>';
        echo '</tr>';
    }
    echo '</table>';
    $total_log_entries = $sales_log['number'];
    $total_pages = ceil($total_log_entries / $per_page);
    if ($total_pages > 1) {
        echo '<div class="tablenav">';
        echo '<div class="tablenav-pages alignright">';
        $base = 'post.php?post=' . $post->ID . '&action=edit%_%';
        echo paginate_links(array('base' => $base, 'format' => '&edd_sales_log_page=%#%', 'prev_text' => '&laquo; ' . __('Previous', 'edd'), 'next_text' => __('Next', 'edd') . ' &raquo;', 'total' => $total_pages, 'current' => $page, 'end_size' => 1, 'mid_size' => 5, 'add_fragment' => '#edd_purchase_log'));
        echo '</div>';
        echo '</div><!--end .tablenav-->';
    }
}