/** * Responsible for queueing any scripts and even localizing any data needed for those scripts to run. This function * should only be called through the WordPress action hook `wp_enqueue_scripts` */ public static function wp_enqueue_scripts() { // Get data required for theme-side API requests $authentication = PushUp_Notifications_Authentication::get_authentication_data(); if (false === $authentication) { return; } // Get notification prompt configuration (0 = custom) $prompt_settings = PushUp_Notifications_Core::get_prompt_setting(); $prompts = $prompt_settings['prompt'] == 'custom' ? 0 : (int) $prompt_settings['prompt_views']; // Allow base path to be filtered $base = apply_filters('pushup-notification-base-script-path', plugins_url('', dirname(__FILE__))); // Enqueue the main PushUp JS used to prompt visitors $append = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script('pushup', $base . '/js/pushup' . $append . '.js', array('jquery'), PushUp_Notifications_Core::get_script_version(), true); // Localize the Notification prompt strings wp_localize_script('pushup', 'PushUpNotificationSettings', array('domain' => $authentication['domain'], 'userID' => $authentication['user_id'], 'websitePushID' => $authentication['website_push_id'], 'webServiceURL' => self::$_api_url, 'prompt' => (int) $prompts)); }
/** * Renders the push notification settings form for our WP settings page */ public static function render_settings_page() { ?> <div class="wrap pushup-notifications-settings"> <h2><?php echo get_admin_page_title(); ?> </h2> <form action="options.php" method="post" autocomplete="off"> <?php settings_errors('pushup-settings'); ?> <?php settings_fields('pushup'); ?> <?php do_settings_sections(self::$menu_page); ?> <?php // If data needed to offer notifications isn't set, let's // actually give the button a more clear name: activate! if (!PushUp_Notifications_Authentication::get_authentication_data()) { $submit_text = __('Activate PushUp', 'pushup'); } else { $submit_text = __('Save Changes'); // No text domain here } submit_button($submit_text); ?> </form> </div> <?php }