예제 #1
0
/**
 * Register and enqueues public-facing JavaScript files.
 *
 * @since    1.0.0
 */
function wpbo_enqueue_scripts()
{
    if (is_admin()) {
        return;
    }
    if (!wpbo_page_has_popup()) {
        return;
    }
    $settings = get_post_meta(wpbo_page_has_popup(), '_wpbo_settings', true);
    /**
     * Check if we can display the credit.
     */
    $settings['credit'] = apply_filters('wpbo_show_credit', true);
    /**
     * Use booleans
     */
    $settings['close_overlay'] = isset($settings['close_overlay']) ? true : false;
    $settings['close_esc'] = isset($settings['close_esc']) ? true : false;
    $settings['wiggle'] = isset($settings['wiggle']) ? true : false;
    $settings['cookie_lifetime'] = isset($settings['cookie_lifetime']) ? intval($settings['cookie_lifetime']) : 30;
    /**
     * Add popup ID
     */
    $settings['popup_id'] = wpbo_page_has_popup();
    /**
     * Define Ajax URL
     */
    $settings['ajaxurl'] = admin_url('admin-ajax.php');
    wp_enqueue_script('wpbo-script', WPBO_URL . 'public/assets/js/betterOptin.min.js', array('jquery'), WPBO_VERSION);
    wp_localize_script('wpbo-script', 'wpbo', json_encode($settings));
}
예제 #2
0
/**
 * Manually triggers a popup.
 *
 * @since  1.0.1
 *
 * @param  array $atts Shortcode attributes
 *
 * @return string      HTML link
 */
function wpbo_trigger_popup($atts = array())
{
    $defaults = array('popup_id' => wpbo_page_has_popup(), 'type' => 'button', 'label' => __('Show Popup', 'betteroptin'), 'bypass_cookie' => true, 'btn_class' => '');
    $atts = shortcode_atts($defaults, $atts);
    $popup_id = (int) $atts['popup_id'];
    /* No popup ID? Bye bye... */
    if (false === $atts['popup_id']) {
        return false;
    }
    /* Do NOT bypass the cookie */
    if (isset($_COOKIE["wpbo_{$popup_id}"]) && false === (bool) $atts['bypass_cookie']) {
        return false;
    }
    if ('button' == $atts['type']) {
        $sc = "<button class='wpbo-trigger {$atts['btn_class']}'>{$atts['label']}</button>";
    } else {
        $sc = "<a href='#' class='wpbo-trigger {$atts['btn_class']}'>{$atts['label']}</a>";
    }
    return $sc;
}
예제 #3
0
/**
 * Check if the current page has a popup and if the current visitor hasn't dismissed it already
 *
 * @since 2.0
 * @return void
 */
function wpbo_maybe_load_popup()
{
    // If the provider is not ready we don't display the popup at all
    if (!wpbo_is_provider_ready()) {
        return;
    }
    $popup_id = wpbo_page_has_popup();
    $post_id = wpbo_get_post_id();
    if (false === $popup_id) {
        return;
    }
    if (wpbo_is_popup_dismissed($popup_id)) {
        if (false === $post_id) {
            return;
        }
        $post = get_post($post_id);
        if (is_null($post)) {
            return;
        }
        /**
         * Because the popups can be triggered by a button (generated by a shortcode), we want to load the popup markup
         * EVEN IF it has been dismissed when the trigger button is present in the post content.
         */
        if (!has_shortcode($post->post_content, 'wpbo_popup')) {
            return;
        }
    }
    $popup = new WPBO_Popup($popup_id);
    $popup->popup();
}