Exemplo n.º 1
0
 public function enqueue_frontend_scripts()
 {
     wp_enqueue_script('localforage-script', plugins_url('lib/js/localforage.nopromises.min.js', __FILE__));
     $title_option = get_option('webpush_title');
     $icon = get_option('webpush_icon');
     if ($icon === 'blog_icon') {
         $icon = get_site_icon_url();
     } else {
         if ($icon === 'post_icon') {
             // We don't have a post here.
             $icon = '';
         }
     }
     wp_register_script('wp-web-push-script', plugins_url('lib/js/wp-web-push.js', __FILE__), array(Mozilla\WP_SW_Manager::SW_REGISTRAR_SCRIPT, 'localforage-script'));
     wp_localize_script('wp-web-push-script', 'WP_Web_Push', array('sw_id' => Mozilla\WP_SW_Manager::get_manager()->sw_js_id(), 'register_url' => admin_url('admin-ajax.php'), 'min_visits' => get_option('webpush_min_visits'), 'welcome_enabled' => in_array('on-subscription', get_option('webpush_triggers')), 'welcome_title' => $title_option === 'blog_title' ? get_bloginfo('name') : $title_option, 'welcome_body' => __('Successfully subscribed to notifications', 'web-push'), 'welcome_icon' => $icon, 'subscription_button' => get_option('webpush_subscription_button'), 'prompt_interval' => get_option('webpush_prompt_interval'), 'subscription_hint' => __('Welcome! Use this button to subscribe to notifications.', 'web-push'), 'mobile_subscription_hint' => __('Subscribe to notifications', 'web-push'), 'unsubscription_hint' => __('You can unsubscribe whenever you want using this button.', 'web-push'), 'mobile_unsubscription_hint' => __('You are now subscribed!', 'web-push'), 'unsubscribed_hint' => __('You are unsubscribed!', 'web-push'), 'notification_preview' => plugins_url('lib/notification.svg', __FILE__), 'subscription_prompt' => sprintf(__('<b>%s</b> can send you notifications for new posts.', 'web-push'), get_bloginfo('name')), 'unsubscription_prompt' => sprintf(__('You are subscribed to <b>%s</b>\'s notifications.', 'web-push'), get_bloginfo('name')), 'unsubscription_button_text' => __('Unsubscribe', 'web-push'), 'subscription_button_text' => __('Subscribe', 'web-push'), 'close_button_text' => __('Close', 'web-push'), 'gcm_enabled' => get_option('webpush_gcm_sender_id') && get_option('webpush_gcm_key')));
     wp_enqueue_script('wp-web-push-script');
     if (get_option('webpush_subscription_button')) {
         wp_enqueue_style('subscription-button-style', Mozilla\WP_Serve_File::get_relative_to_wp_root_url('subscription_button.css'));
     }
 }
 private function setup_sw()
 {
     Mozilla\WP_SW_Manager::get_manager()->sw()->add_content(array($this, 'render_sw'));
 }