diff --git a/assets/js/pwa-register.js b/assets/js/pwa-register.js index 7baf4f1..3908f84 100644 --- a/assets/js/pwa-register.js +++ b/assets/js/pwa-register.js @@ -9,6 +9,10 @@ var swUrl = cfg.swUrl || '/sw.js'; var scope = cfg.scope || '/'; + if ( cfg.requireLogin && ! cfg.isLoggedIn ) { + return; + } + // ------------------------------------------------------------------ // Service Worker registrieren // ------------------------------------------------------------------ diff --git a/assets/js/service-worker.js b/assets/js/service-worker.js index 2801390..eb3110f 100644 --- a/assets/js/service-worker.js +++ b/assets/js/service-worker.js @@ -8,7 +8,7 @@ 'use strict'; -const CACHE_NAME = 'kgv-pwa-v1'; +const CACHE_NAME = 'kgv-pwa-v1-0-1'; const OFFLINE_PAGE = '/'; const PRECACHE_URLS = [ diff --git a/kgv-pwa.php b/kgv-pwa.php index 9388006..3546041 100644 --- a/kgv-pwa.php +++ b/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' ), diff --git a/readme.txt b/readme.txt index 30d8b8f..9de0107 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: ronnygrobel Tags: pwa, progressive web app, manifest, service worker, offline Requires at least: 6.0 Tested up to: 6.7 -Stable tag: 1.0.0 +Stable tag: 1.0.1 Requires PHP: 7.4 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -43,5 +43,10 @@ Werden keine Icons angegeben, wird automatisch das WordPress-Site-Icon verwendet == Changelog == += 1.0.1 = +* PWA-Installation auf eingeloggte Benutzer begrenzt +* Manifest und Service Worker geben fuer Gaeste HTTP 403 zurueck +* Frontend-Assets und Install-Button nur fuer eingeloggte Benutzer aktiv + = 1.0.0 = * Erstveröffentlichung