Skip to content

Commit

Permalink
load actions needing translations in after-setup-theme instead of plu…
Browse files Browse the repository at this point in the history
…gins loaded
  • Loading branch information
iverok committed Nov 12, 2024
1 parent e9da6de commit fa654be
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 27 deletions.
26 changes: 15 additions & 11 deletions Vipps.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ public static function register_hooks() {
} else {
add_action('wp_footer', array($Vipps,'footer'));
}
add_action('init',array($Vipps,'init'));
add_action( 'plugins_loaded', array($Vipps,'plugins_loaded'));
add_action( 'after_setup_theme', array($Vipps,'after_setup_theme'));
add_action('init',array($Vipps,'init'));
add_action( 'woocommerce_loaded', array($Vipps,'woocommerce_loaded'));
add_filter( 'woocommerce_available_payment_gateways', array($Vipps, 'payment_gateway_filter'));
}
Expand Down Expand Up @@ -175,6 +176,7 @@ class_exists("Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTabl
}

public function init () {

// Register certain scripts in wp_loaded because they will be added to the backend as well - the gutenberg checkout block
// needs these to be defined in the backend. IOK 2024-04-16
add_action('wp_loaded', array($this, 'wp_register_scripts'));
Expand Down Expand Up @@ -2177,23 +2179,25 @@ public function get_payment_method_name() {
}

public function plugins_loaded() {
// To facilitate development, allow loading the plugin-supplied translations
$ok = Vipps::load_plugin_textdomain('woo-vipps', false, basename( dirname( __FILE__ ) ) . "/languages");

// Vipps Checkout replaces the default checkout page, and currently uses its own page for this which needs to exist
// Will also probably be used to maintain a real utility-page for Vipps actions later for themes where this
// is important.
add_filter('woocommerce_create_pages', array($this, 'woocommerce_create_pages'), 50, 1);

/* The gateway is added at 'plugins_loaded' and instantiated by Woo itself. IOK 2018-02-07 */
add_filter( 'woocommerce_payment_gateways', array($this,'woocommerce_payment_gateways' ));

/* Try to get a list of all installed gateways *before* we instantiate our own IOK 2024-05-27 */
add_filter( 'woocommerce_payment_gateways', function ($gws) {
if (!empty(Vipps::$installed_gateways)) return Vipps::$installed_gateways;
Vipps::$installed_gateways = $gws;
return $gws;
}, 99999);
}

public function after_setup_theme() {
// To facilitate development, allow loading the plugin-supplied translations. Must be called here at the earliest.
$ok = Vipps::load_plugin_textdomain('woo-vipps', false, basename( dirname( __FILE__ ) ) . "/languages");

// Vipps Checkout replaces the default checkout page, and currently uses its own page for this which needs to exist
// Will also probably be used to maintain a real utility-page for Vipps actions later for themes where this
// is important.
add_filter('woocommerce_create_pages', array($this, 'woocommerce_create_pages'), 50, 1);


// Callbacks use the Woo API IOK 2018-05-18
add_action( 'woocommerce_api_wc_gateway_vipps', array($this,'vipps_callback'));
Expand Down Expand Up @@ -3291,7 +3295,7 @@ public function check_status_of_pending_order($order, $maybe_restore_session=0)
return $order_status;
}

// This will probably be run in activate, but if the plugin is updated in other ways, will also be run on plugins_loaded. IOK 2020-04-01
// This will probably be run in activate, but if the plugin is updated in other ways, will also be run on after_setup_theme. IOK 2020-04-01
public static function maybe_add_cron_event() {
if (!wp_next_scheduled('vipps_cron_cleanup_hook')) {
wp_schedule_event(time(), 'hourly', 'vipps_cron_cleanup_hook');
Expand Down
3 changes: 0 additions & 3 deletions VippsCheckout.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public static function register_hooks() {
add_action('admin_init',array($VippsCheckout,'admin_init'));
}
add_action('init',array($VippsCheckout,'init'));
add_action( 'plugins_loaded', array($VippsCheckout,'plugins_loaded'));
add_action( 'woocommerce_loaded', array($VippsCheckout,'woocommerce_loaded'));
add_action( 'template_redirect', array($VippsCheckout,'template_redirect'));
add_action( 'admin_post_nopriv_vipps_gw', array($VippsCheckout, 'choose_other_gw'));
Expand Down Expand Up @@ -866,8 +865,6 @@ public function woocommerce_loaded () {

}

public function plugins_loaded() {
}

public function woocommerce_settings_pages ($settings) {
$vipps_checkout_activated = get_option('woo_vipps_checkout_activated', false);
Expand Down
2 changes: 1 addition & 1 deletion VippsKCSupport.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

class VippsKCSupport {

// To be run in "plugins_loaded" - extend Klarna Checkout with support for the Vipps external payment method.
// To be run in "after_setup_theme" - extend Klarna Checkout with support for the Vipps external payment method.
public static function init() {
add_filter( 'kco_wc_gateway_settings', array('VippsKCSupport','form_fields'));
add_filter( 'kco_wc_api_request_args', array('VippsKCSupport','create_order_vipps' ), 90);
Expand Down
3 changes: 0 additions & 3 deletions VippsQRCodeController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,9 @@ public static function register_hooks() {
add_action('admin_menu',array($controller,'admin_menu'));
}
add_action('init',array($controller,'init'));
add_action('plugins_loaded', array($controller,'plugins_loaded'));
add_action('woocommerce_loaded', array($controller,'woocommerce_loaded'));
}

public function plugins_loaded() {
}
public function woocommerce_loaded () {
}
public function admin_init() {
Expand Down
2 changes: 1 addition & 1 deletion WC_Gateway_Vipps.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ public function __construct() {
$this->apiurl = 'https://api.vipps.no';

$this->method_description = __('Offer Vipps or MobilePay as a payment method', 'woo-vipps');

$this->method_title = __('Vipps MobilePay','woo-vipps');
$this->title = __('Vipps MobilePay','woo-vipps');

$this->icon = plugins_url('img/vmp-logo.png',__FILE__);
$this->migrate_keyset_with_country_detection();
$this->init_form_fields();
Expand Down
11 changes: 8 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: wphostingdev, iverok, perwilhelmsen, nikolaidev, lassepladsen
Tags: woocommerce, vipps, mobilepay
Tags: woocommerce, vipps
Version: 3.0.3
Stable tag: 3.0.3
Version: 3.0.4
Stable tag: 3.0.4
Requires at least: 6.2
Tested up to: 6.7.0
Requires PHP: 7.0
Expand Down Expand Up @@ -94,7 +94,8 @@ Shareable links and QR codes can be generated from the Vipps tab on the product
This project is hosted on Github at: https://github.com/vippsas/vipps-woocommerce

== Upgrade Notice ==
Version 3.0.3 Fixes issue where zero-value fees would make purchases impossible
Version 3.0.4 Fixes issues with too small images uploaded to Vipps and loads strings with translations later to avoid trigging error-logging
Version 3.0.4 Fixes issue where zero-value fees would make purchases impossible
Version 3.0.2 Fixes support of Klarna Payments as an external payment method
Version 3.0.1 fixes an issue in the Gutenberg Checkout block where issues with Vipps/Mobilepay were turned into fatal errors.
In version 3.0.0 we are introducing an all-new settings screen reached from the Vipps Mobilpay menu. The old settings page will redirect to this. It should look and feel familiar, but we're going to use this page to hopefully improve the co nfiguraton experience as the features improve and the settings grow more complicated.
Expand Down Expand Up @@ -243,6 +244,10 @@ From version 1.1.13 you can also modify the javascript using the new WP hooks li

== Changelog ==

= 2024-11-12 version 3.0.4 =
Fixes an issue with too small images being uploaded to Vipps for orders
Does actions requiring translations in after_set_theme instead of plugins_loaded to avoid triggering "doing it wrong"-errors in WP 6.7.

= 2024-10-28 version 3.0.3 =
Fix issue with orders with zero-value fees
Fix issue with not being able to turn off Klarna in Checkout
Expand Down
5 changes: 3 additions & 2 deletions woo-vipps-compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

// Support Yith WooCommerce Name your price. We need to load the front-end filters when doing express checkout - otherwise price will be zero.
// Unfortunately, we can't do this before priority 10 for plugins loaded to support their 'premium' stuff. IOK 2021-09-29
add_action('plugins_loaded', function () {
add_action('after_setup_theme', function () {
if (function_exists('YITH_Name_Your_Price_Frontend')) {
if (is_admin() && defined('DOING_AJAX') && DOING_AJAX && isset($_REQUEST['action']) && $_REQUEST['action'] == 'do_express_checkout') {
YITH_Name_Your_Price_Frontend();
Expand Down Expand Up @@ -64,7 +64,8 @@

// IOK 2020-03-17: Klarna Checkout now supports external payment methods, such as Vipps. This is great, but we need first to check
// that any user hasn't already installed the free plugin for this created by Krokedil. If they have, this filter will be present:
add_action('plugins_loaded', function () {

add_action('after_setup_theme', function () {
if (class_exists('KCO') && defined('KCO_WC_VERSION') && version_compare(KCO_WC_VERSION, '2.0.0', '>=') && Vipps::instance()->gateway()->enabled == 'yes') {
if (has_filter('kco_wc_api_request_args', 'kcoepm_create_order_vipps')) {
// Vipps external payment support is already present - do nothing. IOK 2021-09-29
Expand Down
6 changes: 3 additions & 3 deletions woo-vipps.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
Author URI: https://www.wp-hosting.no/
Text-domain: woo-vipps
Domain Path: /languages
Version: 3.0.3
Stable tag: 3.0.3
Version: 3.0.4
Stable tag: 3.0.4
Requires at least: 6.2
Tested up to: 6.7.0
Requires PHP: 7.0
Expand Down Expand Up @@ -49,7 +49,7 @@


// Report version externally
define('WOO_VIPPS_VERSION', '3.0.3');
define('WOO_VIPPS_VERSION', '3.0.4');

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
Expand Down

0 comments on commit fa654be

Please sign in to comment.