From 5d17f7dba6fa32a789aae1919ea3dd5e6f2976fa Mon Sep 17 00:00:00 2001 From: Marcin Pietrzak Date: Fri, 6 Dec 2024 18:34:58 +0100 Subject: [PATCH] Translation loading was triggered too early. https://github.com/iworks/iworks-pwa/issues/10 --- includes/iworks/class-iworks-pwa.php | 95 +++++++++++++++++-- .../iworks/pwa/class-iworks-pwa-frontend.php | 12 ++- .../iworks/pwa/class-iworks-pwa-manifest.php | 14 ++- iworks-pwa.php | 18 ---- readme.txt | 1 + 5 files changed, 108 insertions(+), 32 deletions(-) diff --git a/includes/iworks/class-iworks-pwa.php b/includes/iworks/class-iworks-pwa.php index 450c4fa..cf17da2 100644 --- a/includes/iworks/class-iworks-pwa.php +++ b/includes/iworks/class-iworks-pwa.php @@ -1,5 +1,25 @@ url = rtrim( plugin_dir_url( $file ), '/' ); $this->root = rtrim( plugin_dir_path( $file ), '/' ); $this->debug = defined( 'WP_DEBUG' ) && WP_DEBUG; + /** + * plugin ID + * + * @since 1.1.6 + */ + $this->plugin_file = plugin_basename( $this->root ) . '/iworks-pwa.php'; /** * version filter * @@ -69,27 +107,43 @@ protected function __construct() { * End of line */ $this->eol = apply_filters( 'iworks/pwa/eol', $this->eol ); - /** - * set options - */ - $this->options = get_iworks_pwa_options(); - $this->_set_configuration(); /** * integrations wiith external plugins * * @since 1.2.0 */ add_action( 'plugins_loaded', array( $this, 'maybe_load_integrations' ) ); + add_action( 'init', array( $this, 'action_load_plugin_textdomain' ), 0 ); + add_action( 'init', array( $this, 'action_init_setup' ) ); + add_action( 'init', array( $this, 'action_init_register_iworks_rate' ), PHP_INT_MAX ); /** * clear cache * * @since 1.3.0 */ add_action( 'load-settings_page_iworks_pwa_index', array( $this, 'action_cache_clear' ) ); + add_action( 'wp_update_nav_menu', array( $this, 'action_cache_clear' ) ); + } + + /** + * setup + * + * @since 1.6.6 + */ + public function action_init_setup() { + /** + * set options + */ + $this->options = get_iworks_pwa_options(); + $this->_set_configuration(); + /** + * clear cache + * + * @since 1.3.0 + */ add_action( 'update_option_' . $this->options->get_option_name( 'icon_app' ), array( $this, 'action_cache_clear_icons_manifest' ) ); add_action( 'update_option_' . $this->options->get_option_name( 'icon_splash' ), array( $this, 'action_cache_clear_icons_manifest' ) ); add_action( 'update_option_' . $this->options->get_option_name( 'ms_square' ), array( $this, 'action_cache_clear_icons_ms' ) ); - add_action( 'wp_update_nav_menu', array( $this, 'action_cache_clear' ) ); } /** @@ -789,4 +843,33 @@ protected function get_configuration_categories() { ); } + /** + * register plugin to iWorks Rate Helper + * + * @since 1.6.6 + */ + public function action_init_register_iworks_rate() { + if ( ! class_exists( 'iworks_rate' ) ) { + include_once dirname( __FILE__ ) . '/rate/rate.php'; + } + do_action( + 'iworks-register-plugin', + plugin_basename( $this->plugin_file ), + __( 'iWorks PWA', 'iworks-pwa' ), + 'iworks-pwa' + ); + } + + /** + * i18n + * + * @since 1.6.6 + */ + public function action_load_plugin_textdomain() { + load_plugin_textdomain( + 'iworks-pwa', + false, + plugin_basename( $this->root ) . '/languages' + ); + } } diff --git a/includes/iworks/pwa/class-iworks-pwa-frontend.php b/includes/iworks/pwa/class-iworks-pwa-frontend.php index 3f4b39c..33ab386 100644 --- a/includes/iworks/pwa/class-iworks-pwa-frontend.php +++ b/includes/iworks/pwa/class-iworks-pwa-frontend.php @@ -11,13 +11,19 @@ class iWorks_PWA_Frontend extends iWorks_PWA { public function __construct() { parent::__construct(); - if ( ! is_object( $this->options ) ) { - $this->options = get_iworks_pwa_options(); - } /** * WordPress Hooks */ add_action( 'wp_head', array( $this, 'html_head' ), PHP_INT_MAX - 10 ); + add_action( 'init', array( $this, 'action_init_setup_local' ) ); + } + + /** + * Load scripts + * + * @since 1.0.1 + */ + public function action_init_setup_local() { switch ( $this->options->get_option( 'button_a2hs_position' ) ) { case 'wp_footer': $this->add( 'wp_footer' ); diff --git a/includes/iworks/pwa/class-iworks-pwa-manifest.php b/includes/iworks/pwa/class-iworks-pwa-manifest.php index f32f4eb..c905ee3 100644 --- a/includes/iworks/pwa/class-iworks-pwa-manifest.php +++ b/includes/iworks/pwa/class-iworks-pwa-manifest.php @@ -34,16 +34,20 @@ public function __construct() { */ add_action( 'after_setup_theme', array( $this, 'action_after_setup_theme_register_menu' ), PHP_INT_MAX ); add_action( 'init', array( $this, 'register_scripts' ) ); + add_action( 'init', array( $this, 'action_init_setup_local' ) ); add_action( 'login_enqueue_scripts', array( $this, 'enqueue' ), PHP_INT_MAX ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue' ), PHP_INT_MAX ); add_action( 'wp_nav_menu_item_custom_fields', array( $this, 'action_wp_nav_menu_item_custom_fields_add_short_name' ), 10, 5 ); add_action( 'wp_update_nav_menu', array( $this, 'action_wp_update_nav_menu_create_pwa_shortcuts' ), 10, 2 ); add_action( 'wp_update_nav_menu', array( $this, 'action_wp_update_nav_menu_save' ), 10, 2 ); - /** - * Clear generated icons - * - * @since 1.0.1 - */ + } + + /** + * Clear generated icons + * + * @since 1.0.1 + */ + public function action_init_setup_local() { $option_name = $this->options->get_option_name( 'icon_app' ); add_action( 'update_option_' . $option_name, array( $this, 'action_flush_icons' ), 10, 3 ); } diff --git a/iworks-pwa.php b/iworks-pwa.php index efa42de..6940876 100644 --- a/iworks-pwa.php +++ b/iworks-pwa.php @@ -51,11 +51,6 @@ include_once $includes . '/iworks/options/options.php'; } -/** - * i18n - */ -load_plugin_textdomain( 'iworks-pwa', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' ); - /** * load */ @@ -101,16 +96,3 @@ function get_iworks_pwa_options() { return $iworks_pwa_options; } -/** - * Ask for vote - * - * @since 1.0.0 - */ -include_once $includes . '/iworks/rate/rate.php'; -do_action( - 'iworks-register-plugin', - plugin_basename( __FILE__ ), - __( 'iWorks PWA', 'iworks-pwa' ), - 'iworks-pwa' -); - diff --git a/readme.txt b/readme.txt index d1bb3c5..b7c1275 100644 --- a/readme.txt +++ b/readme.txt @@ -106,6 +106,7 @@ A2HS is supported in all mobile browsers, except iOS web view. It's also support = 1.6.6 (2024-12-06) = * Few "translators" comments where been added.[#9](https://github.com/iworks/iworks-pwa/issues/9) * The [iWorks Rate](https://github.com/iworks/iworks-rate) module has been updated to 2.2.1. +* Translation loading time has been fixed. [#10](https://github.com/iworks/iworks-pwa/issues/10) = 1.6.5 (2024-11-12) = * Detailed explanation for missing `manifest.json` and `ieconfig.xml` requests where been added. [#2](https://github.com/iworks/iworks-pwa/issues/2)