diff --git a/.gitmodules b/.gitmodules index b87baff..e6aad27 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "includes/iworks/rate"] path = includes/iworks/rate - url = git@bitbucket.org:iworks-pl/iworks-rate.git + url = git@github.com:iworks/iworks-rate.git [submodule "includes/iworks/options"] path = includes/iworks/options url = git@github.com:iworks/wordpress-options-class.git diff --git a/includes/iworks/class-iworks-pwa.php b/includes/iworks/class-iworks-pwa.php index 84fc272..39e9577 100644 --- a/includes/iworks/class-iworks-pwa.php +++ b/includes/iworks/class-iworks-pwa.php @@ -47,6 +47,13 @@ abstract class iWorks_PWA { */ protected $settings_cache_option_name = 'ipwac_'; + /** + * option to check meta viewport + * + * @since 1.5.1 + */ + protected $option_name_check_meta_viewport = 'iworks_pwa_meta_viewport'; + protected function __construct() { $file = dirname( dirname( __FILE__ ) ); $this->url = rtrim( plugin_dir_url( $file ), '/' ); diff --git a/includes/iworks/pwa/class-iworks-pwa-administrator.php b/includes/iworks/pwa/class-iworks-pwa-administrator.php index 58a2512..2903460 100644 --- a/includes/iworks/pwa/class-iworks-pwa-administrator.php +++ b/includes/iworks/pwa/class-iworks-pwa-administrator.php @@ -73,6 +73,13 @@ public function __construct() { add_action( 'update_option_site_icon', array( $this, 'clear_cache' ) ); add_action( 'update_option_siteurl', array( $this, 'clear_cache' ) ); add_action( 'update_option_stylesheet', array( $this, 'clear_cache' ) ); + /** + * check meta viewport actions + * + * @since 1.5.1 + */ + add_action( 'shutdown', array( $this, 'meta_viewport_check' ) ); + add_action( 'after_switch_theme', array( $this, 'meta_viewport_delete' ) ); } public function filter_add_debug_urls_to_config( $options ) { @@ -271,5 +278,57 @@ public function close_pointer() { $dismissed_pointers[] = $this->pointer_name; update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', implode( ',', $dismissed_pointers ) ); } + + /** + * check meta viewport - on shutdown + * + * @since 1.5.1 + */ + public function meta_viewport_check() { + if ( ! is_admin() ) { + return; + } + $value = get_option( $this->option_name_check_meta_viewport ); + if ( ! empty( $value ) ) { + return; + } + if ( isset( $_GET[ $this->option_name_check_meta_viewport ] ) ) { + return; + } + $url = add_query_arg( + array( + $this->option_name_check_meta_viewport => 'checking', + 'timestamp' => time(), + ), + home_url() + ); + $response = wp_remote_get( $url, array( 'sslverify' => false ) ); + if ( is_wp_error( $response ) ) { + return; + } + $html = wp_remote_retrieve_body( $response ); + if ( preg_match_all( '/]+/', $html, $matches ) ) { + foreach ( $matches[0] as $one ) { + if ( + preg_match( '/name=["\']viewport["\']/', $one ) + && preg_match( '/initial-scale/', $one ) + ) { + update_option( $this->option_name_check_meta_viewport, 'valid' ); + return; + } + } + } + update_option( $this->option_name_check_meta_viewport, 'missing' ); + } + + /** + * delete meta viewport - on after_switch_theme + * + * @since 1.5.1 + */ + public function meta_viewport_delete() { + delete_option( $this->option_name_check_meta_viewport ); + } + } diff --git a/includes/iworks/pwa/class-iworks-pwa-frontend.php b/includes/iworks/pwa/class-iworks-pwa-frontend.php index 8c5826a..c85d08a 100644 --- a/includes/iworks/pwa/class-iworks-pwa-frontend.php +++ b/includes/iworks/pwa/class-iworks-pwa-frontend.php @@ -29,7 +29,7 @@ public function __construct() { } private function add( $action ) { - add_action( $action, array( $this, 'add_to_home_screen' ) ); + add_action( $action, array( $this, 'add_to_home_screen' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'register_styles' ), 0 ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); } @@ -74,6 +74,20 @@ private function before() { */ public function html_head() { $this->before(); + /** + * add meta viewport - on wp_head + * + * @since 1.5.1 + */ + if ( 'missing' === get_option( $this->option_name_check_meta_viewport ) ) { + printf( + '%s', + $this->eol + ); + } + /** + * manifest.json + */ printf( '%s', wp_make_link_relative( home_url( 'manifest.json' ) ), @@ -84,6 +98,9 @@ public function html_head() { wp_make_link_relative( home_url( 'manifest.json' ) ), $this->eol ); + /** + * theme color + */ printf( '%s', $this->configuration['theme_color'], diff --git a/package.json b/package.json index 73fd9b6..435aa9c 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "title": "PWA — easy way to Progressive Web App", "tagline": "Your easy way to Progressive Web Application.", "description": "Progressive Web Apps (PWA) is a technology that combines the best of mobile web and the best of mobile apps to create a superior mobile web experience. They are installed on the phone like a normal app (web app) and can be accessed from the home screen.", - "version": "1.5.0", + "version": "1.5.1", "homepage": "http://iworks.pl/en/plugins/iworks-pwa/", "author": [ { diff --git a/readme.txt b/readme.txt index d10c6ad..96fe53a 100644 --- a/readme.txt +++ b/readme.txt @@ -94,6 +94,10 @@ A2HS is supported in all mobile browsers, except iOS webview. It's also supporte == Changelog == += 1.5.1 (2022-09-10) = +* Added checking for a tag meta with the "viewport" value. Add it if it is missing. Props for [Bert](https://wordpress.org/support/users/bertluch/) +* Changed [iWorks Rate Module](https://github.com/iworks/iworks-rate) repository to GitHub. + = 1.5.0 (2022-08-03) = * Added `Add to Home screen` button to show browser prompt to install "app". Check [Browser compatibility](https://developer.mozilla.org/en-US/docs/Web/API/BeforeInstallPromptEvent#browser_compatibility). * Added google campaign track to "start_url" in `manifest.json` file.