Skip to content

Commit

Permalink
Added checking for a tag meta with the "viewport" value. Add it if it…
Browse files Browse the repository at this point in the history
… is missing.
  • Loading branch information
iworks committed Sep 10, 2022
1 parent 42ba6f4 commit 0a54e27
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions includes/iworks/class-iworks-pwa.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ), '/' );
Expand Down
59 changes: 59 additions & 0 deletions includes/iworks/pwa/class-iworks-pwa-administrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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( '/<meta[^>]+/', $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 );
}

}

19 changes: 18 additions & 1 deletion includes/iworks/pwa/class-iworks-pwa-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
}
Expand Down Expand Up @@ -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(
'<meta name="viewport" content="width=device-width, initial-scale=1" />%s',
$this->eol
);
}
/**
* manifest.json
*/
printf(
'<link rel="manifest" href="%s" />%s',
wp_make_link_relative( home_url( 'manifest.json' ) ),
Expand All @@ -84,6 +98,9 @@ public function html_head() {
wp_make_link_relative( home_url( 'manifest.json' ) ),
$this->eol
);
/**
* theme color
*/
printf(
'<meta name="theme-color" content="%s" />%s',
$this->configuration['theme_color'],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
4 changes: 4 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0a54e27

Please sign in to comment.