Skip to content

Commit

Permalink
Translation loading was triggered too early.
Browse files Browse the repository at this point in the history
  • Loading branch information
iworks committed Dec 6, 2024
1 parent b10c5ce commit 5d17f7d
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 32 deletions.
95 changes: 89 additions & 6 deletions includes/iworks/class-iworks-pwa.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
<?php

/*
Copyright 2021-PLUGIN_TILL_YEAR Marcin Pietrzak (marcin@iworks.pl)
this program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

defined( 'ABSPATH' ) || exit; // Exit if accessed directly


abstract class iWorks_PWA {

Expand Down Expand Up @@ -54,11 +74,29 @@ abstract class iWorks_PWA {
*/
protected $option_name_check_meta_viewport = 'iworks_pwa_meta_viewport';

/**
* plugin file
*
* @since 1.6.6
*/
private $plugin_file;

protected function __construct() {
/**
* basic settings
*
* @since 1.0.0
*/
$file = dirname( dirname( __FILE__ ) );
$this->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
*
Expand All @@ -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' ) );
}

/**
Expand Down Expand Up @@ -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'
);
}
}
12 changes: 9 additions & 3 deletions includes/iworks/pwa/class-iworks-pwa-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
14 changes: 9 additions & 5 deletions includes/iworks/pwa/class-iworks-pwa-manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
18 changes: 0 additions & 18 deletions iworks-pwa.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@
include_once $includes . '/iworks/options/options.php';
}

/**
* i18n
*/
load_plugin_textdomain( 'iworks-pwa', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );

/**
* load
*/
Expand Down Expand Up @@ -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'
);

1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5d17f7d

Please # to comment.