diff --git a/css/onsignal-amp-style.css b/css/onsignal-amp-style.css new file mode 100644 index 0000000..ebf24a2 --- /dev/null +++ b/css/onsignal-amp-style.css @@ -0,0 +1,83 @@ +/* + * The file contains CSS for Subscribe and Unsubscribe button on AMP endpoints which will be enqued only at AMP endpoints. + * +/* + Created on : Jul 14, 2021, 11:57:12 PM + Author : milind +*/ + +amp-web-push-widget button.subscribe.subscribe, amp-web-push-widget button.unsubscribe { + margin: 0; + padding: 0; + border: 0; + cursor: pointer; + outline: none; + position: fixed; + bottom: 20px; + right: 20px; + z-index: 999; + background-color: transparent; + height: 48px; + width: 48px; +} + +amp-web-push-widget button.unsubscribe{ + opacity: 0.5; +} + +amp-web-push-widget button.unsubscribe:hover { + opacity: 1; +} + +amp-web-push-widget button.subscribe svg.onesignal-bell-svg, amp-web-push-widget button.unsubscribe svg.onesignal-bell-svg { + width: 100%; + height: 100%; + overflow: visible; +} + +amp-web-push-widget button.subscribe svg.onesignal-bell-svg .background, amp-web-push-widget button.unsubscribe svg.onesignal-bell-svg .background { + fill: #e54b4d; +} + +amp-web-push-widget button.subscribe svg.onesignal-bell-svg .foreground, amp-web-push-widget button.unsubscribe svg.onesignal-bell-svg .foreground { + fill: #ffffff; +} + +amp-web-push-widget button.subscribe svg.onesignal-bell-svg .stroke, amp-web-push-widget button.unsubscribe svg.onesignal-bell-svg .stroke { + fill: none; + stroke: #ffffff; + stroke-width: 3px; + stroke-miterlimit: 10; +} + +/* Tooltip text */ +amp-web-push-widget button.subscribe .tooltiptext, amp-web-push-widget button.unsubscribe .tooltiptext { + visibility: hidden; + min-width: 350px; + background-color: black; + color: #fff; + text-align: center; + padding: 5px 0; + border-radius: 6px; + top: 5px; + right: 120%; + position: absolute; + z-index: 1; + font-size: 1em; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; +} + +amp-web-push-widget button.subscribe .tooltiptext::after, amp-web-push-widget button.unsubscribe .tooltiptext::after { + content: ""; + position: absolute; + top: 50%; + left: 100%; + margin-top: -5px; + border-width: 5px; + border-style: solid; + border-color: transparent transparent transparent black; +} + +amp-web-push-widget button.subscribe:hover .tooltiptext, amp-web-push-widget button.unsubscribe:hover .tooltiptext { + visibility: visible; +} diff --git a/onesignal-public.php b/onesignal-public.php index 96a7ea4..ac91cac 100644 --- a/onesignal-public.php +++ b/onesignal-public.php @@ -21,6 +21,7 @@ public function __construct() public static function init() { add_action('wp_head', array(__CLASS__, 'onesignal_header'), 10); + add_action( 'wp_enqueue_scripts', array( __CLASS__, 'onesigal_amp_style' ) ); } // For easier debugging of sites by identifying them as WordPress @@ -51,6 +52,20 @@ private static function getOneSignalPluginPath() public static function onesignal_header() { + + if ( function_exists( 'amp_is_request' ) && amp_is_request() ) { + + if ( function_exists( 'amp_is_legacy' ) && amp_is_legacy() ) { + add_action( 'amp_post_template_body_open', array( __CLASS__, 'insert_amp_web_push' ) ); + add_action( 'amp_post_template_footer', array( __CLASS__, 'insert_amp_one_signal_widget' ) ); + } else { + add_action( 'wp_body_open', array( __CLASS__, 'insert_amp_web_push' ) ); + add_action( 'wp_footer', array( __CLASS__, 'insert_amp_one_signal_widget' ) ); + } + + return; + } + $onesignal_wp_settings = OneSignal::get_onesignal_settings(); if (array_key_exists('subdomain', $onesignal_wp_settings) && $onesignal_wp_settings['subdomain'] === '') { @@ -346,5 +361,102 @@ function documentInitOneSignal() { ', + esc_url( $helper_iframe_url ), + esc_url( $permission_dialog_url ), + esc_url( $service_worker_url ) + ); + } + + /** + * Add AMP webpush widget. + */ + public static function insert_amp_one_signal_widget() { + $onesignal_app_id = self::get_onesignal_app_id(); + + if ( empty( $onesignal_app_id ) ) { + return; + } + ?> + + + + + + + + + +