1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
<?php
defined( 'ABSPATH' ) || exit();
class WC_Stripe_Update {
private static $updates
= array(
'3.0.7' => 'update-3.0.7.php',
'3.1.0' => 'update-3.1.0.php',
'3.1.1' => 'update-3.1.1.php',
'3.1.6' => 'update-3.1.6.php',
'3.1.7' => 'update-3.1.7.php',
'3.2.8' => 'update-3.2.8.php',
'3.3.13' => 'update-3.3.13.php',
'3.3.14' => 'update-3.3.14.php'
);
public static function init() {
add_action( 'init', array( __CLASS__, 'update' ) );
}
public static function update() {
$current_version = get_option( 'stripe_wc_version', '3.0.6' );
if ( version_compare( $current_version, stripe_wc()->version(), '<' ) ) {
foreach ( self::$updates as $version => $path ) {
if ( version_compare( $current_version, $version, '<' ) ) {
$file = stripe_wc()->plugin_path() . 'includes/updates/' . $path;
if ( file_exists( $file ) ) {
include $file;
}
$current_version = $version;
update_option( 'stripe_wc_version', $current_version );
add_action(
'admin_notices',
function () use ( $current_version ) {
$message = sprintf( __( 'Thank you for updating Stripe for WooCommerce to version %1$s.', 'woo-stripe-payment' ), $current_version );
if ( ( $text = self::get_messages( $current_version ) ) ) {
$message .= ' ' . $text;
}
printf( '<div class="notice notice-success is-dismissible"><p>%1$s</p></div>', $message );
}
);
}
}
update_option( 'stripe_wc_version', stripe_wc()->version() );
}
}
public static function get_messages( $version ) {
$messages = array();
return isset( $messages[ $version ] ) ? $messages[ $version ] : false;
}
}
WC_Stripe_Update::init();