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
<?php
defined( 'ABSPATH' ) || exit();
class WC_Braintree_Update {
private static $updates = array(
'3.0.0' => 'update-3.0.0.php',
'3.0.4' => 'update-3.0.4.php',
'3.0.9' => 'update-3.0.9.php',
'3.2.5' => 'update-3.2.5.php',
'3.2.7' => 'update-3.2.7.php',
'3.2.8' => 'update-3.2.8.php',
'3.2.29' => 'update-3.2.29.php'
);
public static function init() {
add_action( 'init', array( __CLASS__, 'update' ) );
}
public static function get_messages( $version ) {
$messages = array(
'3.0.0' => __( 'Version 3.0.0 is a major updated. Please check your settings and explore all of the new options.' ) .
sprintf( '<ul><li>%s</li><li>%s</li><li>%s</li><li>%s</li></ul>', 'Google Pay added on product pages, cart pages, top of checkout page', 'PayPal added to product pages', 'Local payment methods like iDEAL added.', 'Performance improvements' ),
'3.0.4' => __( 'Version 3.0.4 updated the text domain used for translations. Make sure your translations are not affected. New text domain is woo-payment-gateway' ),
);
return isset( $messages[ $version ] ) ? $messages[ $version ] : false;
}
public static function update() {
$current_version = get_option( 'braintree_wc_version', '2.6.65' );
if ( version_compare( $current_version, braintree()->version, '<' ) ) {
foreach ( self::$updates as $version => $path ) {
if ( version_compare( $current_version, $version, '<' ) ) {
$file = braintree()->plugin_path() . 'includes/updates/' . $path;
if ( file_exists( $file ) ) {
include $file;
}
$current_version = $version;
update_option( 'braintree_wc_version', $current_version );
add_action(
'admin_notices',
function () use ( $current_version ) {
$message = sprintf( __( 'Thank you for updating Braintree for WooCommerce to version %1$s.', 'woo-payment-gateway' ), $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( 'braintree_wc_version', braintree()->version );
}
}
}
WC_Braintree_Update::init();