Пример #1
0
 function chimpy_lite_form($allowed_forms = array())
 {
     $opt = get_option('chimpy_lite_options', $results);
     // Check if integration is enabled
     if (!$opt || !is_array($opt) || empty($opt) || !isset($opt['chimpy_lite_api_key']) || !$opt['chimpy_lite_api_key']) {
         return;
     }
     // Check if at least one form is defined
     if (!isset($opt['forms']) || empty($opt['forms'])) {
         return;
     }
     $form = ChimpyLite::select_form_by_conditions($opt['forms'], $allowed_forms);
     require_once CHIMPY_LITE_PLUGIN_PATH . '/includes/chimpy-lite-prepare-form.inc.php';
     $html = chimpy_lite_prepare_form($form, $opt, 'shortcode', null, true);
     echo $html;
 }
Пример #2
0
 /**
  * Frontend display of widget
  * 
  * @access public
  * @param array $args
  * @param array $instance
  * @return void
  */
 public function widget($args, $instance)
 {
     // Check if integration is enabled
     if (!$this->opt['chimpy_lite_api_key'] || !isset($this->opt['forms']) || empty($this->opt['forms'])) {
         return;
     }
     // Get allowed forms
     $allowed_forms = isset($instance['allowed_forms']) && is_array($instance['allowed_forms']) && !empty($instance['allowed_forms']) ? $instance['allowed_forms'] : array();
     // Select form that match the conditions best
     $form = ChimpyLite::select_form_by_conditions($this->opt['forms'], $allowed_forms);
     if (!$form) {
         return;
     }
     require_once CHIMPY_LITE_PLUGIN_PATH . '/includes/chimpy-lite-prepare-form.inc.php';
     $form_html = chimpy_lite_prepare_form($form, $this->opt, 'widget', $args);
     echo $form_html;
 }
Пример #3
0
 /**
  * Form shortcode handler
  * 
  * @access public
  * @param mixed $attributes
  * @return void
  */
 public function subscription_shortcode($attributes)
 {
     // Make sure this is not a feed
     if (is_home() || is_archive() || is_search() || is_feed()) {
         return '';
     }
     // Check if integration is enabled and at least one form configured
     if (!$this->opt['chimpy_lite_api_key'] || !isset($this->opt['forms']) || empty($this->opt['forms'])) {
         return '';
     }
     // Extract attributes
     extract(shortcode_atts(array('forms' => ''), $attributes));
     if ($forms != '') {
         $forms = preg_split('/,/', $forms);
         $normalized_allowed_forms = array();
         foreach ($forms as $allowed_form) {
             if (is_numeric($allowed_form)) {
                 $normalized_allowed_forms[] = (int) $allowed_form;
             }
         }
         $allowed_forms = $normalized_allowed_forms;
     } else {
         $allowed_forms = array();
     }
     // Select form that match the conditions best
     $form = self::select_form_by_conditions($this->opt['forms'], $allowed_forms);
     if (!$form) {
         return '';
     }
     require_once CHIMPY_LITE_PLUGIN_PATH . '/includes/chimpy-lite-prepare-form.inc.php';
     $form_html = chimpy_lite_prepare_form($form, $this->opt, 'shortcode');
     return $form_html;
 }