Add plugin update hook & run PayLater migration if plugin is updated

This commit is contained in:
Narek Zakarian 2022-11-18 20:18:41 +04:00
parent 769699763d
commit 13b72db35a
2 changed files with 12 additions and 4 deletions

View file

@ -200,7 +200,7 @@ class CompatModule implements ModuleInterface {
}
add_action(
'woocommerce_paypal_payments_gateway_migrate',
'woocommerce_paypal_payments_gateway_migrate_on_update',
function () use ( $c, $is_pay_later_settings_migrated_option_name ) {
$settings = $c->get( 'wcgateway.settings' );
assert( $settings instanceof Settings );

View file

@ -90,13 +90,21 @@ define( 'PPCP_FLAG_SUBSCRIPTION', true );
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugin_data = get_plugin_data( __DIR__ . '/woocommerce-paypal-payments.php' );
$plugin_version = $plugin_data['Version'] ?? null;
if ( get_option( 'woocommerce-ppcp-version' ) !== $plugin_version ) {
$plugin_data = get_plugin_data( __DIR__ . '/woocommerce-paypal-payments.php' );
$plugin_version = $plugin_data['Version'] ?? null;
$installed_plugin_version = get_option( 'woocommerce-ppcp-version' );
if ( $installed_plugin_version !== $plugin_version ) {
/**
* The hook fired when the plugin is installed or updated.
*/
do_action( 'woocommerce_paypal_payments_gateway_migrate' );
if ( $installed_plugin_version ) {
/**
* The hook fired when the plugin is updated.
*/
do_action( 'woocommerce_paypal_payments_gateway_migrate_on_update' );
}
update_option( 'woocommerce-ppcp-version', $plugin_version );
}
}