예제 #1
0
 public function column_lists($item)
 {
     $form_settings = mc4wp_get_form_settings($item->ID, true);
     $content = '';
     if (!empty($form_settings['lists'])) {
         foreach ($form_settings['lists'] as $list_id) {
             $content .= $this->admin->get_mailchimp_list_name($list_id) . "<br />";
         }
     } else {
         return '<span style="color:red;">No list(s) selected. <a href="' . get_edit_post_link($item->ID) . '">Fix now &raquo;</a></span>';
     }
     return $content;
 }
 /**
  * Outputs a form with the given ID
  *
  * @param array $atts
  * @param string $content
  * @return string
  */
 public function output_form($atts = array(), $content = '')
 {
     // include the necessary functions file
     if (!function_exists('mc4wp_replace_variables')) {
         include_once MC4WP_PLUGIN_DIR . 'includes/functions/template.php';
     }
     // try to get default form ID if it wasn't specified in the shortcode atts
     if (false === isset($atts['id'])) {
         // try to get default form id
         $atts['id'] = get_option('mc4wp_default_form_id', false);
         if (false === $atts['id']) {
             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>';
             }
             return '';
         }
     }
     // Get the form with the specified ID
     $form = $this->get_form($atts['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 '';
     }
     // was this form submitted?
     $was_submitted = is_object($this->form_request) && $this->form_request->get_form_instance_number() === $this->form_instance_number;
     $opts = mc4wp_get_form_settings($form->ID, true);
     // add some useful css classes
     $css_classes = $this->get_form_css_classes($form->ID);
     // Start building content string
     $opening_html = '<!-- MailChimp for WordPress Pro v' . MC4WP_VERSION . ' - https://mc4wp.com/ -->';
     $opening_html .= '<div id="mc4wp-form-' . $this->form_instance_number . '" class="' . $css_classes . '">';
     // Generate before & after fields HTML
     $before_form = apply_filters('mc4wp_form_before_form', '');
     $after_form = apply_filters('mc4wp_form_after_form', '');
     $form_opening_html = '';
     $form_closing_html = '';
     $visible_fields = '';
     $hidden_fields = '';
     $before_fields = apply_filters('mc4wp_form_before_fields', '');
     $after_fields = apply_filters('mc4wp_form_after_fields', '');
     // only generate form & fields HTML if necessary
     if (!$was_submitted || !$opts['hide_after_success'] || !$this->form_request->is_successful()) {
         $form_opening_html = '<form method="post">';
         $visible_fields = $this->get_visible_form_fields($form, $opts);
         // make sure to print date fallback later on if form contains a date field
         if ($this->form_contains_field_type($visible_fields, 'date')) {
             $this->print_date_fallback = true;
         }
         $hidden_fields = $this->get_hidden_form_fields($form);
         $form_closing_html = '</form>';
     }
     // empty string for response
     $response_html = '';
     // does this form have AJAX enabled?
     if ($opts['ajax']) {
         // load ajax scripts (in footer)
         $this->load_ajax_scripts();
         // set placeholder div for ajax response
         $response_html .= '<div class="mc4wp-response"></div>';
         // Add AJAX loader span to output
         $hidden_fields .= '<span class="mc4wp-ajax-loader" style="display: none;"></span>';
     }
     // was form submited?
     if ($was_submitted) {
         // enqueue scripts (in footer) if form was submited
         wp_enqueue_script('mc4wp-form-request');
         wp_localize_script('mc4wp-form-request', 'mc4wpFormRequestData', array('success' => $this->form_request->is_successful() ? 1 : 0, 'formId' => $this->form_request->get_form_instance_number(), 'data' => $this->form_request->get_data()));
         // set response html
         $response_html .= $this->form_request->get_response_html();
     }
     // add form response to content, if no {response} tag present
     if ('' !== $response_html && (stristr($visible_fields, '{response}') === false || $opts['hide_after_success'])) {
         /**
          * @filter mc4wp_form_message_position
          * @expects string before|after
          *
          * Can be used to change the position of the form success & error messages.
          * Valid options are 'before' or 'after'
          */
         $message_position = apply_filters('mc4wp_form_message_position', 'after');
         switch ($message_position) {
             case 'before':
                 $before_form = $before_form . $response_html;
                 break;
             case 'after':
                 $after_form = $response_html . $after_form;
                 break;
         }
         // reset response html, we only need it once
         $response_html = '';
     }
     // Always replace {response} tag, either with empty string or actual response
     $visible_fields = str_ireplace('{response}', $response_html, $visible_fields);
     $closing_html = '</div><!-- / MailChimp for WP Pro Plugin -->';
     // increase form instance number in case there is more than one form on a page
     $this->form_instance_number++;
     // make sure scripts are enqueued later
     global $is_IE;
     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'));
     ob_start();
     // echo HTML parts of form
     echo $opening_html;
     echo $before_form;
     echo $form_opening_html;
     echo $before_fields;
     echo $visible_fields;
     echo $hidden_fields;
     echo $after_fields;
     echo $form_closing_html;
     echo $after_form;
     echo $closing_html;
     // print css to hide honeypot, if not printed already
     $this->print_css();
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
 }
 /**
  * Constructor
  *
  * @param array $form_data
  */
 public function __construct($form_data)
 {
     $this->data = $this->normalize_form_data($form_data);
     // store number of submitted form
     $this->form_instance_number = absint($this->data['_MC4WP_FORM_INSTANCE']);
     $this->form_id = absint($this->data['_MC4WP_FORM_ID']);
     $this->form_options = mc4wp_get_form_settings($this->form_id, true);
     // validate request
     $this->is_valid = $this->validate();
     // only proceed if request is valid
     if ($this->is_valid) {
         // add some data to the posted data, like FNAME and LNAME
         $this->data = $this->guess_missing_fields($this->data);
         // map fields to corresponding MailChimp lists
         // abandon if mapping failed (missing required field, etc..)
         if ($this->map_data()) {
             // subscribe using the processed data
             $this->success = $this->subscribe($this->lists_fields_map);
         }
     }
     // format a HTTP / AJAX response
     if (defined('DOING_AJAX') && DOING_AJAX) {
         $this->send_ajax_response();
     } else {
         $this->send_http_response();
     }
     return $this->success;
 }
예제 #4
0
 public function show_optional_form_settings_metabox($post)
 {
     $form_settings = mc4wp_get_form_settings($post->ID);
     $inherited_settings = mc4wp_get_options('form');
     $final_settings = mc4wp_get_form_settings($post->ID, true);
     include MC4WP_PLUGIN_DIR . 'includes/views/metaboxes/optional-form-settings.php';
 }
 /**
  * @param $item
  *
  * @return string
  */
 public function column_lists($item)
 {
     $form_settings = mc4wp_get_form_settings($item->ID, true);
     $content = '';
     if (!empty($form_settings['lists'])) {
         $mailchimp = new MC4WP_MailChimp();
         foreach ($form_settings['lists'] as $list_id) {
             $content .= $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;
 }