示例#1
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();
}
示例#2
0
 /**
  * Trigger form submission.
  *
  * @since  1.0.0
  * @return void
  */
 public function submit()
 {
     if (!wpbo_is_provider_ready()) {
         return;
     }
     $data = $this->get_clean_fields();
     $result = call_user_func(array(wpbo_get_provider_class(), 'submit'), $data);
     // Log the conversion
     $conversion = $this->new_conversion();
     $first_name = isset($data['first_name']) ? $data['first_name'] : $data['name'];
     $last_name = isset($data['last_name']) ? $data['last_name'] : '';
     // Dismiss the popup
     wpbo_dismiss_popup($this->popup_id);
     // Backup the subscriber in case something went wrong
     if (true !== $result) {
         $failsafe = array('conversion_id' => $conversion, 'first_name' => $first_name, 'last_name' => $last_name, 'email' => $data['email'], 'status' => 'failed');
         wpbo_failsafe_add_subscriber($failsafe);
     }
     // Redirect
     wp_redirect($this->get_return_url());
     exit;
 }