Release 1.0.1: restrict PWA install to logged-in users
This commit is contained in:
28
kgv-pwa.php
28
kgv-pwa.php
@@ -3,7 +3,7 @@
|
||||
* Plugin Name: KGV PWA
|
||||
* Plugin URI: https://apex-project.de/
|
||||
* Description: Progressive Web App Unterstützung fuer KGV-Webseiten – Web App Manifest, Service Worker und Install-Banner.
|
||||
* Version: 1.0.0
|
||||
* Version: 1.0.1
|
||||
* Author: Ronny Grobel
|
||||
* Author URI: https://apex-project.de/
|
||||
* Text Domain: kgv-pwa
|
||||
@@ -18,7 +18,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
||||
final class KGV_PWA_Plugin {
|
||||
|
||||
const VERSION = '1.0.0';
|
||||
const VERSION = '1.0.1';
|
||||
const OPTION_KEY = 'kgv_pwa_settings';
|
||||
const REWRITE_VERSION_OPTION = 'kgv_pwa_rewrite_version';
|
||||
|
||||
@@ -99,6 +99,11 @@ final class KGV_PWA_Plugin {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_user_logged_in() ) {
|
||||
status_header( 403 );
|
||||
exit;
|
||||
}
|
||||
|
||||
$settings = $this->get_settings();
|
||||
|
||||
$manifest = array(
|
||||
@@ -172,6 +177,11 @@ final class KGV_PWA_Plugin {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! is_user_logged_in() ) {
|
||||
status_header( 403 );
|
||||
exit;
|
||||
}
|
||||
|
||||
$sw_file = plugin_dir_path( __FILE__ ) . 'assets/js/service-worker.js';
|
||||
|
||||
if ( ! file_exists( $sw_file ) ) {
|
||||
@@ -193,6 +203,10 @@ final class KGV_PWA_Plugin {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public function output_head_tags() {
|
||||
if ( ! is_user_logged_in() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$settings = $this->get_settings();
|
||||
$app_name = esc_attr( $settings['app_name'] );
|
||||
$theme_hex = esc_attr( $settings['theme_color'] );
|
||||
@@ -221,6 +235,10 @@ final class KGV_PWA_Plugin {
|
||||
}
|
||||
|
||||
public function enqueue_assets() {
|
||||
if ( ! is_user_logged_in() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sw_url = $this->get_service_worker_url();
|
||||
$scope = trailingslashit( home_url( '/' ) );
|
||||
|
||||
@@ -245,6 +263,8 @@ final class KGV_PWA_Plugin {
|
||||
array(
|
||||
'swUrl' => esc_url_raw( $sw_url ),
|
||||
'scope' => esc_url_raw( $scope ),
|
||||
'requireLogin' => true,
|
||||
'isLoggedIn' => is_user_logged_in(),
|
||||
'iosInstallNotice' => __( 'Auf iPhone/iPad: Im Browser auf Teilen tippen und dann "Zum Home-Bildschirm" waehlen.', 'kgv-pwa' ),
|
||||
)
|
||||
);
|
||||
@@ -259,6 +279,10 @@ final class KGV_PWA_Plugin {
|
||||
* class – Zusätzliche CSS-Klassen
|
||||
*/
|
||||
public function render_install_button( $atts ) {
|
||||
if ( ! is_user_logged_in() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$atts = shortcode_atts(
|
||||
array(
|
||||
'label' => __( 'App installieren', 'kgv-pwa' ),
|
||||
|
||||
Reference in New Issue
Block a user