• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Easy Digital Downloads a2z

Easy Digital Downloads a2z

Easy Digital Downloads a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / EDD_Tools_Reset_Stats::get_data() – Get the Export Data

You appear to be a bot. Output may be restricted

Description

Get the Export Data

Usage

$array = EDD_Tools_Reset_Stats::get_data();

Parameters

Returns

array $data The data for the CSV file

Source

File name: easy-digital-downloads/includes/admin/tools/class-edd-tools-reset-stats.php
Lines:

1 to 85 of 85
  public function get_data() {
    global $wpdb;

    $items = $this->get_stored_data( 'edd_temp_reset_ids' );

    if ( ! is_array( $items ) ) {
      return false;
    }

    $offset     = ( $this->step - 1 ) * $this->per_step;
    $step_items = array_slice( $items, $offset, $this->per_step );

    if ( $step_items ) {

      $step_ids = array(
        'customers' => array(),
        'downloads' => array(),
        'other'     => array(),
      );

      foreach ( $step_items as $item ) {

        switch( $item['type'] ) {
          case 'customer':
            $step_ids['customers'][] = $item['id'];
            break;
          case 'download':
            $step_ids['downloads'][] = $item['id'];
            break;
          default:
            $item_type = apply_filters( 'edd_reset_item_type', 'other', $item );
            $step_ids[ $item_type ][] = $item['id'];
            break;
        }

      }

      $sql = array();

      foreach ( $step_ids as $type => $ids ) {

        if ( empty( $ids ) ) {
          continue;
        }

        $ids = implode( ',', $ids );

        switch( $type ) {
          case 'customers':
            $table_name = $wpdb->prefix . 'edd_customers';
            $sql[] = "DELETE FROM $table_name WHERE id IN ($ids)";
            break;
          case 'downloads':
            $sql[] = "UPDATE $wpdb->postmeta SET meta_value = 0 WHERE meta_key = '_edd_download_sales' AND post_id IN ($ids)";
            $sql[] = "UPDATE $wpdb->postmeta SET meta_value = 0.00 WHERE meta_key = '_edd_download_earnings' AND post_id IN ($ids)";
            break;
          case 'other':
            $sql[] = "DELETE FROM $wpdb->posts WHERE id IN ($ids)";
            $sql[] = "DELETE FROM $wpdb->postmeta WHERE post_id IN ($ids)";
            $sql[] = "DELETE FROM $wpdb->comments WHERE comment_post_ID IN ($ids)";
            $sql[] = "DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (SELECT comment_ID FROM $wpdb->comments)";
            break;
        }

        if ( ! in_array( $type, array( 'customers', 'downloads', 'other' ) ) ) {
          // Allows other types of custom post types to filter on their own post_type
          // and add items to the query list, for the IDs found in their post type.
          $sql = apply_filters( 'edd_reset_add_queries_' . $type, $sql, $ids );
        }

      }

      if ( ! empty( $sql ) ) {
        foreach ( $sql as $query ) {
          $wpdb->query( $query );
        }
      }

      return true;

    }

    return false;

  }
 

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 26th November 2019

Primary Sidebar

Information

Function name: EDD_Tools_Reset_Stats::get_data
Class ref: EDD_Tools_Reset_Stats
Plugin ref: Easy Digital Downloads
Version: 2.9.23
Sourcefile: includes/admin/tools/class-edd-tools-reset-stats.php
File ref: includes/admin/tools/class-edd-tools-reset-stats.php
Deprecated?: No
API Letters: E,G,R,S,T

Footer

Easy Digital Downloads a2z
Easy Digital Downloads a2z
Easy Digital Downloads a2z
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  edd.wp-a2z.org
© Copyright Easy Digital Downloads a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites