Easy Digital Downloads
  • Package
  • Function
  • Tree

Packages

  • EDD
    • Admin
      • Actions
      • Add-ons
      • Dashboard
      • Discounts
      • Downloads
      • Export
      • Notices
      • Pages
      • Payments
      • Reports
      • Settings
      • System
      • Upgrades
      • Upload
      • Welcome
    • Cart
    • Checkout
    • Classes
      • API
      • Fees
      • HTML
      • Roles
      • Session
    • Emails
    • Functions
      • AJAX
      • Compatibility
      • Errors
      • Formatting
      • Install
      • Login
      • Taxes
      • Templates
    • Gateways
    • Logging
    • Payments
    • Shortcodes
    • Widgets

Functions

  • edd_show_upgrade_notices
  • edd_trigger_upgrades
  • edd_upgrades_screen
  • edd_v131_upgrades
  • edd_v134_upgrades
  • edd_v14_upgrades
  • edd_v15_upgrades
  1 <?php
  2 /**
  3  * Upgrade Functions
  4  *
  5  * @package     EDD
  6  * @subpackage  Admin/Upgrades
  7  * @copyright   Copyright (c) 2013, Pippin Williamson
  8  * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
  9  * @since       1.3.1
 10  */
 11 
 12 // Exit if accessed directly
 13 if ( ! defined( 'ABSPATH' ) ) exit;
 14 
 15 /**
 16  * Display Upgrade Notices
 17  *
 18  * @since 1.3.1
 19  * @return void
 20 */
 21 function edd_show_upgrade_notices() {
 22     if ( isset( $_GET['page'] ) && $_GET['page'] == 'edd-upgrades' )
 23         return; // Don't show notices on the upgrades page
 24 
 25     $edd_version = get_option( 'edd_version' );
 26 
 27     if ( ! $edd_version ) {
 28         // 1.3 is the first version to use this option so we must add it
 29         $edd_version = '1.3';
 30     }
 31 
 32     if ( ! get_option( 'edd_payment_totals_upgraded' ) && ! get_option( 'edd_version' ) ) {
 33         if ( wp_count_posts( 'edd_payment' )->publish < 1 )
 34             return; // No payment exist yet
 35 
 36         // The payment history needs updated for version 1.2
 37         $url = add_query_arg( 'edd-action', 'upgrade_payments' );
 38         $upgrade_notice = sprintf( __( 'The Payment History needs to be updated. %s', 'edd' ), '<a href="' . wp_nonce_url( $url, 'edd_upgrade_payments_nonce' ) . '">' . __( 'Click to Upgrade', 'edd' ) . '</a>' );
 39         add_settings_error( 'edd-notices', 'edd-payments-upgrade', $upgrade_notice, 'error' );
 40     }
 41 
 42     if ( version_compare( $edd_version, '1.3.2', '<' ) && ! get_option( 'edd_logs_upgraded' ) ) {
 43         printf(
 44             '<div class="updated"><p>' . esc_html__( 'The Purchase and File Download History in Easy Digital Downloads needs to be upgraded, click %shere%s to start the upgrade.', 'edd' ) . '</p></div>',
 45             '<a href="' . esc_url( admin_url( 'options.php?page=edd-upgrades' ) ) . '">',
 46             '</a>'
 47         );
 48     }
 49 
 50     if ( version_compare( $edd_version, '1.3.4', '<' ) || version_compare( $edd_version, '1.4', '<' ) ) {
 51         printf(
 52             '<div class="updated"><p>' . esc_html__( 'Easy Digital Downloads needs to upgrade the plugin pages, click %shere%s to start the upgrade.', 'edd' ) . '</p></div>',
 53             '<a href="' . esc_url( admin_url( 'options.php?page=edd-upgrades' ) ) . '">',
 54             '</a>'
 55         );
 56     }
 57 
 58     if ( version_compare( $edd_version, '1.5', '<' ) ) {
 59         printf(
 60             '<div class="updated"><p>' . esc_html__( 'Easy Digital Downloads needs to upgrade the database, click %shere%s to start the upgrade.', 'edd' ) . '</p></div>',
 61             '<a href="' . esc_url( admin_url( 'options.php?page=edd-upgrades' ) ) . '">',
 62             '</a>'
 63         );
 64     }
 65 }
 66 add_action( 'admin_notices', 'edd_show_upgrade_notices' );
 67 
 68 /**
 69  * Triggers all upgrade functions
 70  *
 71  * This function is usually triggered via AJAX
 72  *
 73  * @since 1.3.1
 74  * @return void
 75 */
 76 function edd_trigger_upgrades() {
 77     $edd_version = get_option( 'edd_version' );
 78 
 79     if ( ! $edd_version ) {
 80         // 1.3 is the first version to use this option so we must add it
 81         $edd_version = '1.3';
 82         add_option( 'edd_version', $edd_version );
 83     }
 84 
 85     if ( version_compare( EDD_VERSION, $edd_version, '>' ) ) {
 86         edd_v131_upgrades();
 87     }
 88 
 89     if ( version_compare( $edd_version, '1.3.4', '<' ) ) {
 90         edd_v134_upgrades();
 91     }
 92 
 93     if ( version_compare( $edd_version, '1.4', '<' ) ) {
 94         edd_v14_upgrades();
 95     }
 96 
 97     if ( version_compare( $edd_version, '1.5', '<' ) ) {
 98         edd_v15_upgrades();
 99     }
100 
101     update_option( 'edd_version', EDD_VERSION );
102 
103     if ( DOING_AJAX )
104         die( 'complete' ); // Let AJAX know that the upgrade is complete
105 }
106 add_action( 'wp_ajax_edd_trigger_upgrades', 'edd_trigger_upgrades' );
107 
108 /**
109  * Converts old sale and file download logs to new logging system
110  *
111  * @since 1.3.1
112  * @uses WP_Query
113  * @uses EDD_Logging
114  * @return void
115  */
116 function edd_v131_upgrades() {
117     if ( get_option( 'edd_logs_upgraded' ) )
118         return;
119 
120     if ( version_compare( get_option( 'edd_version' ), '1.3', '>=' ) )
121         return;
122 
123     ignore_user_abort( true );
124 
125     if ( ! edd_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) )
126         set_time_limit( 0 );
127 
128     $args = array(
129         'post_type'         => 'download',
130         'posts_per_page'    => -1,
131         'post_status'       => 'publish'
132     );
133 
134     $query = new WP_Query( $args );
135     $count = $query->post_count;
136     $downloads = $query->get_posts();
137 
138     if ( $downloads ) {
139         $edd_log = new EDD_Logging();
140         $i = 0;
141         foreach ( $downloads as $download ) {
142             // Convert sale logs
143             $sale_logs = edd_get_download_sales_log( $download->ID, false );
144 
145             if ( $sale_logs ) {
146                 foreach ( $sale_logs['sales'] as $sale ) {
147                     $log_data = array(
148                         'post_parent'   => $download->ID,
149                         'post_date'     => $sale['date'],
150                         'log_type'      => 'sale'
151                     );
152 
153                     $log_meta = array(
154                         'payment_id'=> $sale['payment_id']
155                     );
156 
157                     $log = $edd_log->insert_log( $log_data, $log_meta );
158                 }
159             }
160 
161             // Convert file download logs
162             $file_logs = edd_get_file_download_log( $download->ID, false );
163 
164             if ( $file_logs ) {
165                 foreach ( $file_logs['downloads'] as $log ) {
166                     $log_data = array(
167                         'post_parent'   => $download->ID,
168                         'post_date'     => $log['date'],
169                         'log_type'      => 'file_download'
170 
171                     );
172 
173                     $log_meta = array(
174                         'user_info' => $log['user_info'],
175                         'file_id'   => $log['file_id'],
176                         'ip'        => $log['ip']
177                     );
178 
179                     $log = $edd_log->insert_log( $log_data, $log_meta );
180                 }
181             }
182         }
183     }
184     add_option( 'edd_logs_upgraded', '1' );
185 }
186 
187 /**
188  * Upgrade routine for v1.3.4
189  *
190  * @since 1.3.4
191  * @return void
192  */
193 function edd_v134_upgrades() {
194     $general_options = get_option( 'edd_settings_general' );
195 
196     if ( isset( $general_options['failure_page'] ) )
197         return; // Settings already updated
198 
199     // Failed Purchase Page
200     $failed = wp_insert_post(
201         array(
202             'post_title'     => __( 'Transaction Failed', 'edd' ),
203             'post_content'   => __( 'Your transaction failed, please try again or contact site support.', 'edd' ),
204             'post_status'    => 'publish',
205             'post_author'    => 1,
206             'post_type'      => 'page',
207             'post_parent'    => $general_options['purchase_page'],
208             'comment_status' => 'closed'
209         )
210     );
211 
212     $general_options['failure_page'] = $failed;
213 
214     update_option( 'edd_settings_general', $general_options );
215 }
216 
217 /**
218  * Upgrade routine for v1.4
219  *
220  * @since 1.4
221  * @global $edd_options Array of all the EDD Options
222  * @return void
223  */
224 function edd_v14_upgrades() {
225     global $edd_options;
226 
227     /** Add [edd_receipt] to success page **/
228     $success_page = get_post( $edd_options['success_page'] );
229 
230     // Check for the [edd_receipt] short code and add it if not present
231     if( strpos( $success_page->post_content, '[edd_receipt' ) === false ) {
232         $page_content = $success_page->post_content .= "\n[edd_receipt]";
233         wp_update_post( array( 'ID' => $edd_options['success_page'], 'post_content' => $page_content ) );
234     }
235 
236     /** Convert Discounts to new Custom Post Type **/
237     $discounts = get_option( 'edd_discounts' );
238 
239     if ( $discounts ) {
240         foreach ( $discounts as $key => $discount ) {
241             $status = isset( $discount['status'] ) ? $discount['status'] : 'inactive';
242 
243             $discount_id = wp_insert_post( array(
244                 'post_type'   => 'edd_discount',
245                 'post_title'  => isset( $discount['name'] ) ? $discount['name'] : '',
246                 'post_status' => 'active'
247             ) );
248 
249             $meta = array(
250                 'code'        => isset( $discount['code'] ) ? $discount['code'] : '',
251                 'uses'        => isset( $discount['uses'] ) ? $discount['uses'] : '',
252                 'max_uses'    => isset( $discount['max'] ) ? $discount['max'] : '',
253                 'amount'      => isset( $discount['amount'] ) ? $discount['amount'] : '',
254                 'start'       => isset( $discount['start'] ) ? $discount['start'] : '',
255                 'expiration'  => isset( $discount['expiration'] ) ? $discount['expiration'] : '',
256                 'type'        => isset( $discount['type'] ) ? $discount['type'] : '',
257                 'min_price'   => isset( $discount['min_price'] ) ? $discount['min_price'] : ''
258             );
259 
260             foreach ( $meta as $key => $value ) {
261                 update_post_meta( $discount_id, '_edd_discount_' . $key, $value );
262             }
263         }
264 
265         // Remove old discounts from database
266         delete_option( 'edd_discounts' );
267     }
268 }
269 
270 
271 /**
272  * Upgrade routine for v1.5
273  *
274  * @since 1.5
275  * @return void
276  */
277 function edd_v15_upgrades() {
278     // Update options for missing tax settings
279     $tax_options = get_option( 'edd_settings_taxes' );
280 
281     // Set include tax on checkout to off
282     $tax_options['checkout_include_tax'] = 'no';
283 
284     // Check if prices are displayed with taxes
285     if( isset( $tax_options['taxes_on_prices'] ) ) {
286         $tax_options['prices_include_tax'] = 'yes';
287     } else {
288         $tax_options['prices_include_tax'] = 'no';
289     }
290 
291     update_option( 'edd_settings_taxes', $tax_options );
292 
293     // Flush the rewrite rules for the new /edd-api/ end point
294     flush_rewrite_rules();
295 }
Easy Digital Downloads API documentation generated by ApiGen 2.8.0