Exemplo n.º 1
0
 /**
  * Constructor
  *
  * @param array $data
  */
 public function __construct(array $data)
 {
     $this->data = $this->normalize_data($data);
     // store number of submitted form
     $this->form_element_id = (string) $this->data['_MC4WP_FORM_ELEMENT_ID'];
     $this->form = MC4WP_Form::get($this);
 }
Exemplo n.º 2
0
 /**
  * Constructor
  *
  * @param array $data
  */
 public function __construct(array $data)
 {
     // find fields prefixed with _mc4wp_
     $this->config = $this->parse_config($data);
     // normalize user data
     $this->data = $this->normalize_data($data);
     // get form
     $this->form = MC4WP_Form::get($this->config['form_id'], $this);
 }
Exemplo n.º 3
0
/**
 * @since 2.3.8
 * @param int $form_id
 * @return string
 */
function mc4wp_form_get_response_html($form_id = 0)
{
    $form = MC4WP_Form::get($form_id);
    // return empty string if form doesn't exist or isn't submitted
    if (!$form instanceof MC4WP_Form || !$form->is_submitted()) {
        return '';
    }
    return $form->request->get_response_html();
}
 /**
  * Constructor
  *
  * @param array $data
  */
 public function __construct(array $data)
 {
     // find fields prefixed with _mc4wp_
     $this->internal_data = $this->get_internal_data($data);
     // normalize user data
     $this->user_data = $this->normalize_data($data);
     // store number of submitted form
     $this->form_element_id = (string) $this->internal_data['form_element_id'];
     // get form
     $this->form = MC4WP_Form::get($this);
 }
Exemplo n.º 5
0
 /**
  * Constructor
  *
  * @param array $data
  */
 public function __construct(array $data)
 {
     // find fields prefixed with _mc4wp_
     $this->internal_data = $this->get_internal_data($data);
     // normalize user data
     $this->user_data = $this->normalize_data($data);
     // store number of submitted form
     $this->form_element_id = (string) $this->internal_data['form_element_id'];
     // get form this request belongs to and bind request to that form
     $this->form = MC4WP_Form::get((int) $this->internal_data['form_id'], $this);
     // get referer
     if (!empty($_SERVER['HTTP_REFERER'])) {
         $this->http_referer = strip_tags($_SERVER['HTTP_REFERER']);
     }
 }
 /**
  * Returns the MailChimp for WP form mark-up
  *
  * @param array $attributes
  * @param string $content
  *
  * @return string
  */
 public function output_form($attributes = array(), $content = '')
 {
     global $is_IE;
     // increase count of outputted forms
     $this->outputted_forms_count++;
     $attributes = shortcode_atts(array('id' => 0, 'element_id' => 'mc4wp-form-' . $this->outputted_forms_count), $attributes, 'mc4wp_form');
     // create or retrieve form instance
     $form = MC4WP_Form::get();
     // make sure to print date fallback later on if form contains a date field
     if ($form->contains_field_type('date')) {
         $this->print_date_fallback = true;
     }
     // was form submited?
     if ($form->is_submitted($attributes['element_id'])) {
         // enqueue scripts (in footer) if form was submitted
         $animate_scroll = apply_filters('mc4wp_form_animate_scroll', true);
         wp_enqueue_script('mc4wp-form-request');
         wp_localize_script('mc4wp-form-request', 'mc4wpFormRequestData', array('success' => $form->request->success ? 1 : 0, 'formElementId' => $form->request->form_element_id, 'data' => $form->request->user_data, 'animate_scroll' => $animate_scroll));
     }
     // Print small JS snippet later on in the footer.
     add_action('wp_footer', array($this, 'print_js'), 99);
     // make sure scripts are enqueued later
     if (isset($is_IE) && $is_IE) {
         wp_enqueue_script('mc4wp-placeholders');
     }
     // output form
     return $form->output($attributes['element_id'], $attributes, false);
 }
Exemplo n.º 7
0
 /**
  * Outputs a form with the given ID
  *
  * @param array $attributes
  * @param string $content
  * @return string
  */
 public function output_form($attributes = array(), $content = '')
 {
     global $is_IE;
     // increase count of outputted forms
     $this->outputted_forms_count++;
     $attributes = shortcode_atts(array('id' => 0, 'element_id' => 'mc4wp-form-' . $this->outputted_forms_count), $attributes, 'mc4wp_form');
     // try to get default form ID if it wasn't specified in the shortcode atts
     if (!$attributes['id']) {
         // try to get default form id
         $attributes['id'] = absint(get_option('mc4wp_default_form_id', 0));
         if (empty($attributes['id'])) {
             // return error message or empty form
             if (current_user_can('manage_options')) {
                 return '<p>' . sprintf(__('<strong>Error:</strong> Please specify a form ID. Example: %s.', 'mailchimp-for-wp'), '<code>[mc4wp_form id="321"]</code>') . '</p>';
             } else {
                 return '';
             }
         }
     }
     // Get the form with the specified ID
     $form = MC4WP_Form::get($attributes['id']);
     // did we find a valid form with this ID?
     if (!$form) {
         if (current_user_can('manage_options')) {
             return '<p>' . __('<strong>Error:</strong> Sign-up form not found. Please check if you used the correct form ID.', 'mailchimp-for-wp') . '</p>';
         }
         return '';
     }
     // make sure to print date fallback later on if form contains a date field
     if ($form->contains_field_type('date')) {
         $this->print_date_fallback = true;
     }
     // does this form have AJAX enabled?
     if ($form->settings['ajax']) {
         $this->load_ajax_scripts();
     }
     // was form submited?
     if ($form->is_submitted($attributes['element_id'])) {
         // enqueue scripts (in footer) if form was submited
         $animate_scroll = apply_filters('mc4wp_form_animate_scroll', true);
         wp_enqueue_script('mc4wp-form-request');
         wp_localize_script('mc4wp-form-request', 'mc4wpFormRequestData', array('success' => $form->request->success ? 1 : 0, 'formElementId' => $form->request->form_element_id, 'data' => $form->request->user_data, 'animate_scroll' => $animate_scroll));
     }
     // make sure scripts are enqueued later
     if (isset($is_IE) && $is_IE) {
         wp_enqueue_script('mc4wp-placeholders');
     }
     // Print small JS snippet later on in the footer.
     add_action('wp_footer', array($this, 'print_js'), 99);
     // output form
     return $form->output($attributes['element_id'], $attributes, false);
 }
 /**
  * Returns the MailChimp for WP form mark-up
  *
  * @param array $attributes
  * @param string $content
  *
  * @return string
  */
 public function output_form($attributes = array(), $content = '')
 {
     // increase count of outputted forms
     $this->outputted_forms_count++;
     // parse shortcode attributes (sets up defaults too)
     $attributes = $this->parse_shortcode_attributes($attributes);
     // create or retrieve form instance
     $form = MC4WP_Form::get($attributes['id']);
     // did we find a valid form with this ID?
     if (!$form) {
         if (current_user_can('manage_options')) {
             return '<p>' . __('<strong>Error:</strong> Sign-up form not found. Please check if you used the correct form ID.', 'mailchimp-for-wp') . '</p>';
         }
         return '';
     }
     // tell asset manager to print assets for this form
     $this->assets->print_form_assets($form);
     // add inline css to form output if it was not printed yet
     $content .= $this->assets->print_css(false);
     // output form
     $content .= $form->output($attributes['element_id'], $attributes, false);
     return $content;
 }
Exemplo n.º 9
0
 /**
  * Outputs the optional form settings metabox
  * @param WP_Post $post
  */
 public function show_optional_form_settings_metabox($post)
 {
     $form = MC4WP_Form::get($post);
     $individual_form_settings = $form->load_settings(false);
     $inherited_settings = mc4wp_get_options('form');
     include MC4WP_PLUGIN_DIR . 'includes/views/metaboxes/optional-form-settings.php';
 }
Exemplo n.º 10
0
 /**
  * @param $item
  *
  * @return string
  */
 public function column_lists($item)
 {
     $form = MC4WP_Form::get($item->ID);
     $content = '';
     if (!empty($form->settings['lists'])) {
         foreach ($form->settings['lists'] as $list_id) {
             $content .= $this->mailchimp->get_list_name($list_id) . '<br />';
         }
     } else {
         return '<a style="color: red; text-decoration: underline;" href="' . get_edit_post_link($item->ID) . '">' . __('No MailChimp list(s) selected yet.', 'mailchimp-for-wp') . '</a>';
     }
     return $content;
 }
 /**
  * Returns the MailChimp for WP form mark-up
  *
  * @param array $attributes
  * @param string $content
  *
  * @return string
  */
 public function output_form($attributes = array(), $content = '')
 {
     global $is_IE;
     // increase count of outputted forms
     $this->outputted_forms_count++;
     $attributes = shortcode_atts(array('id' => 0, 'element_id' => 'mc4wp-form-' . $this->outputted_forms_count), $attributes, 'mc4wp_form');
     // create or retrieve form instance
     $form = MC4WP_Form::get();
     // make sure to print date fallback later on if form contains a date field
     if ($form->contains_field_type('date')) {
         $this->print_date_fallback = true;
     }
     // was form submited?
     if ($form->is_submitted($attributes['element_id'])) {
         // enqueue scripts (in footer) if form was submited
         wp_enqueue_script('mc4wp-form-request');
         wp_localize_script('mc4wp-form-request', 'mc4wpFormRequestData', array('success' => $form->request->success ? 1 : 0, 'formElementId' => $form->request->form_element_id, 'data' => $form->request->data));
     }
     // Print small JS snippet later on in the footer.
     add_action('wp_footer', array($this, 'print_js'));
     // Print CSS to hide honeypot (should be printed in `wp_head` by now)
     $html = '';
     // add inline css if it was not printed yet
     $html .= $this->print_css(false);
     // output form
     $html .= $form->output($attributes['element_id'], $attributes, false);
     return $html;
 }