Пример #1
0
/**
 * @param int $form_id
 * @param bool $inherit
 *
 * @return array
 */
function mc4wp_get_form_settings($form_id, $inherit = false)
{
    $inherited_settings = mc4wp_get_options('form');
    $form_settings = array();
    // set defaults
    $form_settings['lists'] = array();
    $form_settings['email_copy_receiver'] = get_bloginfo('admin_email');
    // fill optional meta keys with empty strings
    $optional_meta_keys = array('double_optin', 'update_existing', 'replace_interests', 'send_welcome', 'ajax', 'hide_after_success', 'redirect', 'text_success', 'text_error', 'text_invalid_email', 'text_already_subscribed', 'send_email_copy', 'text_invalid_captcha', 'text_required_field_missing');
    foreach ($optional_meta_keys as $meta_key) {
        if ($inherit) {
            $form_settings[$meta_key] = $inherited_settings[$meta_key];
        } else {
            $form_settings[$meta_key] = '';
        }
    }
    $meta = get_post_meta($form_id, '_mc4wp_settings', true);
    if (is_array($meta)) {
        foreach ($meta as $key => $value) {
            // only add meta value if not empty
            if ($value != '') {
                $form_settings[$key] = $value;
            }
        }
    }
    return $form_settings;
}
/**
 * Gets the MailChimp for WP API class and injects it with the API key
 *
 * @deprecated 4.0
 * @use mc4wp_get_api_v3
 *
 * @since 1.0
 * @access public
 *
 * @return MC4WP_API
 */
function mc4wp_get_api()
{
    _deprecated_function(__FUNCTION__, '4.0', 'mc4wp_get_api_v3');
    $opts = mc4wp_get_options();
    $instance = new MC4WP_API($opts['api_key']);
    return $instance;
}
Пример #3
0
 /**
  * Get the checkbox options
  *
  * @return array
  */
 public function get_options()
 {
     if ($this->options === null) {
         $this->options = mc4wp_get_options('checkbox');
     }
     return $this->options;
 }
Пример #4
0
 /**
  * Constructor
  *
  * Hooks into the `init` action to start the process of subscribing the person who filled out the form
  */
 public function __construct()
 {
     // store number of submitted form
     $this->form_instance_number = absint($_POST['_mc4wp_form_instance']);
     // store form options
     $this->form_options = mc4wp_get_options('form');
     add_action('init', array($this, 'act'));
 }
Пример #5
0
 /**
  * @return MC4WP_Lite_API
  */
 public function get_api()
 {
     if ($this->api === null) {
         $opts = mc4wp_get_options();
         $this->api = new MC4WP_Lite_API($opts['general']['api_key']);
     }
     return $this->api;
 }
 /**
  * Loads the checkbox stylesheet
  */
 public function load_stylesheet()
 {
     $opts = mc4wp_get_options('checkbox');
     if ($opts['css'] == false) {
         return false;
     }
     wp_enqueue_style('mailchimp-for-wp-checkbox', MC4WP_LITE_PLUGIN_URL . 'assets/css/checkbox.css', array(), MC4WP_LITE_VERSION, 'all');
     return true;
 }
Пример #7
0
 /**
  * Loads the checkbox stylesheet
  */
 public function load_stylesheet()
 {
     $opts = mc4wp_get_options('checkbox');
     if ($opts['css'] == false) {
         return false;
     }
     $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
     wp_enqueue_style('mailchimp-for-wp-checkbox', MC4WP_LITE_PLUGIN_URL . 'assets/css/checkbox' . $suffix . '.css', array(), MC4WP_LITE_VERSION, 'all');
     return true;
 }
Пример #8
0
function CF7_pre_send($cf7)
{
    if (isset($_POST['is_subcribe']) && count($_POST['is_subcribe']) > 0) {
        $option = mc4wp_get_options('form');
        $api = mc4wp_get_api();
        foreach ($option['lists'] as $v) {
            $api->subscribe($v, $cf7->mail['recipient']);
        }
    }
}
 /**
  * @return array
  */
 public function get_tracked_options()
 {
     $checkbox_options = mc4wp_get_options('checkbox');
     $form_options = mc4wp_get_options('form');
     // make sure these keys are always stripped
     $ignored_options = array('api_key', 'license_key', 'lists');
     // filter options
     $checkbox_options = array_diff_key($checkbox_options, array_flip($ignored_options));
     $form_options = array_diff_key($form_options, array_flip($ignored_options));
     // merge options
     $options = array('checkbox' => $checkbox_options, 'form' => $form_options);
     return $options;
 }
Пример #10
0
 /**
  * Initializes the Form functionality
  *
  * - Registers scripts so developers can override them, should they want to.
  */
 public function initialize()
 {
     $this->options = mc4wp_get_options('form');
     $this->register_shortcodes();
     // has a MC4WP form been submitted?
     if (isset($_POST['_mc4wp_form_submit'])) {
         $this->form_request = new MC4WP_Lite_Form_Request($_POST);
     }
     // frontend only
     if (!is_admin()) {
         // load checkbox css if necessary
         add_action('wp_head', array($this, 'print_css'), 90);
         add_action('wp_enqueue_scripts', array($this, 'load_stylesheet'));
         $this->register_scripts();
     }
 }
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->options = mc4wp_get_options('checkbox');
     // load checkbox css if necessary
     add_action('wp_enqueue_scripts', array($this, 'load_stylesheet'));
     add_action('login_enqueue_scripts', array($this, 'load_stylesheet'));
     // Load WP Comment Form Integration
     if ($this->options['show_at_comment_form']) {
         $this->integrations['comment_form'] = new MC4WP_Comment_Form_Integration();
     }
     // Load WordPress Registration Form Integration
     if ($this->options['show_at_registration_form']) {
         $this->integrations['registration_form'] = new MC4WP_Registration_Form_Integration();
     }
     // Load BuddyPress Integration
     if ($this->options['show_at_buddypress_form']) {
         $this->integrations['buddypress_form'] = new MC4WP_BuddyPress_Integration();
     }
     // Load MultiSite Integration
     if ($this->options['show_at_multisite_form']) {
         $this->integrations['multisite_form'] = new MC4WP_MultiSite_Integration();
     }
     // Load bbPress Integration
     if ($this->options['show_at_bbpress_forms']) {
         $this->integrations['bbpress_forms'] = new MC4WP_bbPress_Integration();
     }
     // Load CF7 Integration
     if (function_exists('wpcf7_add_shortcode')) {
         $this->integrations['contact_form_7'] = new MC4WP_CF7_Integration();
     }
     // Load Events Manager integration
     if (defined('EM_VERSION')) {
         $this->integrations['events_manager'] = new MC4WP_Events_Manager_Integration();
     }
     // Load WooCommerce Integration
     if ($this->options['show_at_woocommerce_checkout']) {
         $this->integrations['woocommerce'] = new MC4WP_WooCommerce_Integration();
     }
     // Load EDD Integration
     if ($this->options['show_at_edd_checkout']) {
         $this->integrations['easy_digital_downloads'] = new MC4WP_EDD_Integration();
     }
     // load General Integration on POST requests
     if ($_SERVER['REQUEST_METHOD'] === 'POST') {
         $this->integrations['general'] = new MC4WP_General_Integration();
     }
 }
Пример #12
0
 /**
  * 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_options = mc4wp_get_options('form');
     $this->is_valid = $this->validate();
     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
         if ($this->map_data($this->data)) {
             // subscribe using the processed data
             $this->success = $this->subscribe($this->lists_fields_map);
         }
     }
     // send HTTP response
     $this->send_http_response();
     return $this->success;
 }
 /**
  * Initialize form stuff
  *
  * - Registers post type
  * - Registers scripts
  */
 public function initialize()
 {
     $this->options = mc4wp_get_options('form');
     // register post type
     register_post_type('mc4wp-form', array('labels' => array('name' => 'MailChimp Sign-up Forms', 'singular_name' => 'Sign-up Form', 'add_new_item' => 'Add New Form', 'edit_item' => 'Edit Form', 'new_item' => 'New Form', 'all_items' => 'All Forms', 'view_item' => null), 'public' => false, 'show_ui' => true, 'show_in_menu' => false));
     $this->register_shortcodes();
     // has a form been submitted, either by ajax or manually?
     if (isset($_POST['_mc4wp_form_submit'])) {
         $this->form_request = new MC4WP_Form_Request($_POST);
     }
     // frontend only
     if (!is_admin()) {
         add_action('wp_head', array($this, 'print_css'), 90);
         add_action('wp_enqueue_scripts', array($this, 'load_stylesheet'));
         $this->register_scripts();
         if (isset($_GET['_mc4wp_css_preview'])) {
             $this->show_form_preview();
             die;
         }
     }
 }
	/**
	 * Acts on the submitted data
	 * - Validates internal fields
	 * - Formats email and merge_vars
	 * - Sends off the subscribe request to MailChimp
	 * - Returns state
	 *
	 * @return bool True on success, false on failure.
	 */
	public function act() {

		// store number of submitted form
		$this->form_instance_number = absint( $_POST['_mc4wp_form_instance'] );

		// store form options
		$this->form_options = mc4wp_get_options( 'form' );

		// validate form nonce
		if ( ! isset( $_POST['_mc4wp_form_nonce'] ) || ! wp_verify_nonce( $_POST['_mc4wp_form_nonce'], '_mc4wp_form_nonce' ) ) {
			$this->error_code = 'invalid_nonce';
			return false;
		}

		// ensure honeypot was not filed
		if ( isset( $_POST['_mc4wp_required_but_not_really'] ) && ! empty( $_POST['_mc4wp_required_but_not_really'] ) ) {
			$this->error_code = 'spam';
			return false;
		}

		// check if captcha was present and valid
		if( isset( $_POST['_mc4wp_has_captcha'] ) && $_POST['_mc4wp_has_captcha'] == 1 && function_exists( 'cptch_check_custom_form' ) && cptch_check_custom_form() !== true ) {
			$this->error_code = 'invalid_captcha';
			return false;
		}

		/**
		 * @filter mc4wp_valid_form_request
		 *
		 * Use this to perform custom form validation.
		 * Return true if the form is valid or an error string if it isn't.
		 * Use the `mc4wp_form_messages` filter to register custom error messages.
		 */
		$valid_form_request = apply_filters( 'mc4wp_valid_form_request', true );
		if( $valid_form_request !== true ) {
			$this->error_code = $valid_form_request;
			return false;
		}

		// get entered form data (sanitized)
		$this->sanitize_form_data();
		$data = $this->get_posted_data();

		// validate email
		if( ! isset( $data['EMAIL'] ) || ! is_email( $data['EMAIL'] ) ) {
			$this->error_code = 'invalid_email';
			return false;
		}

		// setup merge_vars array
		$merge_vars = $data;

		// take email out of $data array, use the rest as merge_vars
		$email = $merge_vars['EMAIL'];
		unset( $merge_vars['EMAIL'] );

		// validate groupings
		if( isset( $data['GROUPINGS'] ) && is_array( $data['GROUPINGS'] ) ) {
			$merge_vars['GROUPINGS'] = $this->format_groupings_data( $data['GROUPINGS'] );
		}

		// subscribe the given email / data combination
		$this->success = $this->subscribe( $email, $merge_vars );

		// do stuff on success
		if( true === $this->success ) {

			// check if we want to redirect the visitor
			if ( ! empty( $this->form_options['redirect'] ) ) {
				wp_redirect( $this->form_options['redirect'] );
				exit;
			}

			// return true on success
			return true;
		}

		// return false on failure
		return false;
	}
Пример #15
0
 /**
  * Runs on plugin activation
  * Transfers settings from MC4WP Lite
  */
 public function on_activation()
 {
     // delete transients
     delete_transient('mc4wp_mailchimp_lists');
     delete_transient('mc4wp_mailchimp_lists_fallback');
     // check if PRO option exists and contains data entered by user
     if (($o = get_option('mc4wp')) != false && (!empty($o['api_key']) || !empty($o['license_key']))) {
         return;
     }
     // user entered no PRO options in the past, let's see if we can transfer from LITE
     $lite_settings = array('general' => (array) get_option('mc4wp_lite'), 'checkbox' => (array) get_option('mc4wp_lite_checkbox'), 'form' => (array) get_option('mc4wp_lite_form'));
     $default_options = mc4wp_get_options();
     foreach ($default_options as $group_key => $options) {
         foreach ($options as $option_key => $option_value) {
             if (isset($lite_settings[$group_key][$option_key]) && !empty($lite_settings[$group_key][$option_key])) {
                 $default_options[$group_key][$option_key] = $lite_settings[$group_key][$option_key];
             }
         }
     }
     $forms = get_posts(array('post_type' => 'mc4wp-form'));
     if (!$forms) {
         // no forms found, try to transfer from lite.
         $form_markup = isset($lite_settings['form']['markup']) ? $lite_settings['form']['markup'] : $this->get_default_form_markup();
         $form_ID = wp_insert_post(array('post_type' => 'mc4wp-form', 'post_title' => 'Sign-Up Form #1', 'post_content' => $form_markup, 'post_status' => 'publish'));
         $lists = isset($lite_settings['form']['lists']) ? $lite_settings['form']['lists'] : array();
         update_post_meta($form_ID, '_mc4wp_settings', array('lists' => $lists));
         update_option('mc4wp_default_form_id', $form_ID);
     }
     // store options
     update_option('mc4wp', $default_options['general']);
     update_option('mc4wp_checkbox', $default_options['checkbox']);
     update_option('mc4wp_form', $default_options['form']);
 }
/**
 * Gets the MailChimp for WP API class and injects it with the API key
 *
 * @staticvar $instance
 *
 * @since 1.0
 * @access public
 *
 * @return MC4WP_API
 */
function mc4wp_get_api()
{
    $opts = mc4wp_get_options();
    $instance = new MC4WP_API($opts['api_key']);
    return $instance;
}
	/**
	 * Returns the various error and success messages in array format
	 *
	 * Example:
	 * array(
	 *      'invalid_email' => array(
	 *          'type' => 'css-class',
	 *          'text' => 'Message text'
	 *      ),
	 *      ...
	 * );
	 *
	 * @return array
	 */
	public function get_form_messages( $form_id = 0 ) {

		$opts = mc4wp_get_options( 'form' );

		$messages = array(
			'already_subscribed' => array(
				'type' => 'notice',
				'text' => $opts['text_already_subscribed']
			),
			'error' => array(
				'type' => 'error',
				'text' => $opts['text_error']
			),
			'invalid_email' => array(
				'type' => 'error',
				'text' => $opts['text_invalid_email']
			),
			'success' => array(
				'type' => 'success',
				'text' => $opts['text_success']
			),
			'invalid_captcha' => array(
				'type' => 'error',
				'text' => $opts['text_invalid_captcha']
			),
			'required_field_missing' => array(
				'type' => 'error',
				'text' => $opts['text_required_field_missing']
			)
		);

		/**
		 * @filter mc4wp_form_messages
		 *
		 * Allows registering custom form messages, useful if you're using custom validation using the `mc4wp_valid_form_request` filter.
		 */
		$messages = apply_filters( 'mc4wp_form_messages', $messages );

		return $messages;
	}
Пример #18
0
 /**
  * @return array
  */
 public function load_settings()
 {
     return mc4wp_get_options('form');
 }
Пример #19
0
 /**
  * Makes a subscription request
  *
  * @param string $email
  * @param array $merge_vars
  * @param string $signup_type
  * @param int $comment_ID
  * @return boolean
  */
 protected function subscribe($email, array $merge_vars = array(), $signup_type = 'comment', $comment_id = null)
 {
     $api = mc4wp_get_api();
     $opts = mc4wp_get_options('checkbox');
     $lists = $this->get_lists();
     if (empty($lists)) {
         if ((!defined('DOING_AJAX') || !DOING_AJAX) && current_user_can('manage_options')) {
             wp_die('<h3>' . __('MailChimp for WordPress - Error', 'mailchimp-for-wp') . '</h3>' . '<p>' . sprintf(__('Please select a list to subscribe to in the <a href="%s">checkbox settings</a>.', 'mailchimp-for-wp'), admin_url('admin.php?page=mc4wp-lite-checkbox-settings')) . '</p>' . '<p style="font-style:italic; font-size:12px;">' . __('This message is only visible to administrators for debugging purposes.', 'mailchimp-for-wp') . '</p>', __('MailChimp for WordPress - Error', 'mailchimp-for-wp'), array('back_link' => true));
         }
         return 'no_lists_selected';
     }
     // maybe guess first and last name
     if (isset($merge_vars['NAME']) && !isset($merge_vars['FNAME']) && !isset($merge_vars['LNAME'])) {
         $strpos = strpos($merge_vars['NAME'], ' ');
         if ($strpos !== false) {
             $merge_vars['FNAME'] = substr($merge_vars['NAME'], 0, $strpos);
             $merge_vars['LNAME'] = substr($merge_vars['NAME'], $strpos);
         } else {
             $merge_vars['FNAME'] = $merge_vars['NAME'];
         }
     }
     // set ip address
     if (!isset($merge_vars['OPTIN_IP']) && isset($_SERVER['REMOTE_ADDR'])) {
         $merge_vars['OPTIN_IP'] = $_SERVER['REMOTE_ADDR'];
     }
     $result = false;
     $merge_vars = apply_filters('mc4wp_merge_vars', $merge_vars, $signup_type);
     $email_type = apply_filters('mc4wp_email_type', 'html');
     do_action('mc4wp_before_subscribe', $email, $merge_vars);
     foreach ($lists as $list_id) {
         $result = $api->subscribe($list_id, $email, $merge_vars, $email_type, $opts['double_optin'], false, true);
     }
     do_action('mc4wp_after_subscribe', $email, $merge_vars, $result);
     if ($result === true) {
         $from_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
         do_action('mc4wp_subscribe_checkbox', $email, $lists, $signup_type, $merge_vars, $comment_id, $from_url);
     }
     // check if result succeeded, show debug message to administrators (only in NON-AJAX requests)
     if ($result !== true && $api->has_error() && current_user_can('manage_options') && (!defined('DOING_AJAX') || !DOING_AJAX) && (!isset($_POST['_wpcf7_is_ajax_call']) || $_POST['_wpcf7_is_ajax_call'] != 1)) {
         wp_die('<h3>' . __('MailChimp for WordPress - Error', 'mailchimp-for-wp') . '</h3>' . '<p>' . __('The MailChimp server returned the following error message as a response to our sign-up request:', 'mailchimp-for-wp') . '</p>' . '<pre>' . $api->get_error_message() . '</pre>' . '<p>' . __('This is the data that was sent to MailChimp:', 'mailchimp-for-wp') . '</p>' . '<strong>' . __('Email address:', 'mailchimp-for-wp') . '</strong>' . '<pre>' . esc_html($email) . '</pre>' . '<strong>' . __('Merge variables:', 'mailchimp-for-wp') . '</strong>' . '<pre>' . esc_html(print_r($merge_vars, true)) . '</pre>' . '<p style="font-style:italic; font-size:12px;">' . __('This message is only visible to administrators for debugging purposes.', 'mailchimp-for-wp') . '</p>', __('MailChimp for WordPress - Error', 'mailchimp-for-wp'), array('back_link' => true));
     }
     return $result;
 }
Пример #20
0
 /**
  * Show the forms settings page
  */
 public function show_form_settings()
 {
     $opts = mc4wp_get_options('form');
     $mailchimp = new MC4WP_MailChimp();
     $lists = $mailchimp->get_lists();
     require MC4WP_LITE_PLUGIN_DIR . 'includes/views/form-settings.php';
 }
Пример #21
0
 /**
  * Returns the MailChimp for WP form mark-up
  *
  * @param array $atts
  * @param string $content
  *
  * @return string
  */
 public function form($atts = array(), $content = '')
 {
     // make sure template functions are loaded
     if (!function_exists('mc4wp_replace_variables')) {
         include_once MC4WP_LITE_PLUGIN_DIR . 'includes/functions/template.php';
     }
     // Get form options
     $opts = mc4wp_get_options('form');
     // was this form submitted?
     $was_submitted = is_object($this->form_request) && $this->form_request->get_form_instance_number() === $this->form_instance_number;
     /**
      * @filter mc4wp_form_action
      * @expects string
      *
      * Sets the `action` attribute of the form element. Defaults to the current URL.
      */
     $form_action = apply_filters('mc4wp_form_action', mc4wp_get_current_url());
     // Generate opening HTML
     $opening_html = "<!-- Form by MailChimp for WordPress plugin v" . MC4WP_LITE_VERSION . " - https://mc4wp.com/ -->";
     $opening_html .= '<form method="post" action="' . $form_action . '" id="mc4wp-form-' . $this->form_instance_number . '" class="' . $this->get_css_classes() . '">';
     // Generate before & after fields HTML
     $before_fields = apply_filters('mc4wp_form_before_fields', '');
     $after_fields = apply_filters('mc4wp_form_after_fields', '');
     // Process fields, if not submitted or not successfull or hide_after_success disabled
     if (!$was_submitted || !$opts['hide_after_success'] || !$this->form_request->is_successful()) {
         // add form fields from settings
         $visible_fields = __($opts['markup'], 'mailchimp-for-wp');
         // replace special values
         $visible_fields = str_ireplace(array('%N%', '{n}'), $this->form_instance_number, $visible_fields);
         $visible_fields = mc4wp_replace_variables($visible_fields, array_values($opts['lists']));
         // insert captcha
         if (function_exists('cptch_display_captcha_custom')) {
             $captcha_fields = '<input type="hidden" name="_mc4wp_has_captcha" value="1" /><input type="hidden" name="cntctfrm_contact_action" value="true" />' . cptch_display_captcha_custom();
             $visible_fields = str_ireplace(array('{captcha}', '[captcha]'), $captcha_fields, $visible_fields);
         }
         /**
          * @filter mc4wp_form_content
          * @param       int     $form_id    The ID of the form that is being shown
          * @expects     string
          *
          * Can be used to customize the content of the form mark-up, eg adding additional fields.
          */
         $visible_fields = apply_filters('mc4wp_form_content', $visible_fields);
         // hidden fields
         $hidden_fields = '<textarea name="_mc4wp_required_but_not_really" style="display: none !important;"></textarea>';
         $hidden_fields .= '<input type="hidden" name="_mc4wp_form_submit" value="1" />';
         $hidden_fields .= '<input type="hidden" name="_mc4wp_form_instance" value="' . $this->form_instance_number . '" />';
         $hidden_fields .= '<input type="hidden" name="_mc4wp_form_nonce" value="' . wp_create_nonce('_mc4wp_form_nonce') . '" />';
     } else {
         $visible_fields = '';
         $hidden_fields = '';
     }
     // empty string for response
     $response_html = '';
     if ($was_submitted) {
         // Enqueue script (only after submit)
         wp_enqueue_script('mc4wp-form-request');
         wp_localize_script('mc4wp-form-request', 'mc4wpFormRequestData', array('success' => $this->form_request->is_successful() ? 1 : 0, 'submittedFormId' => $this->form_request->get_form_instance_number(), 'postData' => $this->form_request->get_data()));
         // get actual response html
         $response_html = $this->form_request->get_response_html();
         // add form response after or before fields if no {response} tag
         if (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_fields = $before_fields . $response_html;
                     break;
                 case 'after':
                     $after_fields = $response_html . $after_fields;
                     break;
             }
         }
     }
     // Always replace {response} tag, either with empty string or actual response
     $visible_fields = str_ireplace('{response}', $response_html, $visible_fields);
     // Generate closing HTML
     $closing_html = "</form>";
     $closing_html .= "<!-- / MailChimp for WP 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'));
     // concatenate and return the HTML parts
     return $opening_html . $before_fields . $visible_fields . $hidden_fields . $after_fields . $closing_html;
 }
Пример #22
0
 /**
  * Show form settings page
  */
 public function show_form_settings()
 {
     $tab = isset($_GET['tab']) ? $_GET['tab'] : 'general-settings';
     $opts = mc4wp_get_options('form');
     if ($tab === 'general-settings') {
         $table = new MC4WP_Forms_Table();
     } else {
         // get all forms
         $forms = get_posts(array('post_type' => 'mc4wp-form', 'post_status' => 'publish', 'posts_per_page' => -1));
         // get form to which styles should apply
         if (isset($_GET['form_id'])) {
             $form_id = absint($_GET['form_id']);
         } elseif (isset($forms[0])) {
             $form_id = $forms[0]->ID;
         } else {
             $form_id = 0;
         }
         // get css settings for this form (or 0)
         $builder = new MC4WP_Styles_Builder();
         $styles = $builder->get_form_styles($form_id);
         // create preview url
         $preview_url = add_query_arg(array('form_id' => $form_id, '_mc4wp_css_preview' => 1));
     }
     require MC4WP_PLUGIN_DIR . 'includes/views/pages/admin-form-settings.php';
 }
 /**
  * Show the API settings page
  */
 public function show_generals_setting_page()
 {
     $opts = mc4wp_get_options();
     $connected = mc4wp('api')->is_connected();
     $lists = $this->mailchimp->get_lists();
     require MC4WP_PLUGIN_DIR . 'includes/views/general-settings.php';
 }
 /**
  * Build file with given CSS values
  *
  * @param array $css Array containing the values of the various CSS fields
  *
  * @return bool
  */
 public static function build_css_file(array $styles)
 {
     $css_string = self::get_css_string($styles);
     // upload CSS file with CSS string as content
     $file = wp_upload_bits('mailchimp-for-wp.css', null, $css_string);
     // Check if file was successfully created
     if (false === $file || !is_array($file) || $file['error'] !== false) {
         $message = sprintf(__('Couldn\'t create the stylesheet. Manually add the generated CSS to your theme stylesheet by using the %sTheme Editor%s or use FTP and edit <em>%s</em>.', 'mailchimp-for-wp'), '<a href="' . admin_url('theme-editor.php') . '">', '</a>', get_stylesheet_directory() . '/style.css');
         $button = sprintf(__('%sShow generated CSS%s', 'mailchimp-for-wp'), '<a class="mc4wp-show-css button" href="javascript:void(0);">', '</a>');
         add_settings_error('mc4wp', 'mc4wp-css', $message . ' ' . $button . '</strong><div id="mc4wp_generated_css" style="display:none;"><pre>' . esc_html($css_string) . '</pre></div><strong>');
         return false;
     }
     // store protocol relative url to CSS file in option
     $custom_stylesheet = str_ireplace(array('http://', 'https://'), '//', $file['url']);
     update_option('mc4wp_custom_css_file', $custom_stylesheet);
     // show notice
     $opts = mc4wp_get_options('form');
     $enqueue_text = $opts['css'] === 'custom' ? '' : sprintf(__('To apply these styles on your website, select "load custom form styles" in the %sform settings%s', 'mailchimp-for-wp'), '<a href="' . admin_url('admin.php?page=mailchimp-for-wp-form-settings') . '">', '</a>.');
     add_settings_error('mc4wp', 'mc4wp-css', sprintf(__('The %sCSS Stylesheet%s has been created.', 'mailchimp-for-wp'), '<a href="' . $file['url'] . '">', '</a>') . ' ' . $enqueue_text, 'updated');
     return true;
 }
Пример #25
0
 /**
  * Get MailChimp Lists to subscribe to
  * 
  * @return array Array of selected MailChimp lists
  */
 public function get_lists()
 {
     $opts = mc4wp_get_options('form');
     $lists = $opts['lists'];
     // get lists from form, if set.
     if (isset($_POST['_mc4wp_lists']) && !empty($_POST['_mc4wp_lists'])) {
         $lists = $_POST['_mc4wp_lists'];
         // make sure lists is an array
         if (!is_array($lists)) {
             $lists = array(trim($lists));
         }
     }
     // allow plugins to alter the lists to subscribe to
     $lists = apply_filters('mc4wp_lists', $lists);
     return $lists;
 }
Пример #26
0
 /**
  * Show the Other Settings page
  */
 public function show_other_setting_page()
 {
     $opts = mc4wp_get_options();
     $log = $this->get_log();
     $log_reader = new MC4WP_Debug_Log_Reader($log->file);
     require MC4WP_PLUGIN_DIR . 'includes/views/other-settings.php';
 }
 /**
  * Shows a notice when API key is not set.
  */
 public function show_api_key_notice()
 {
     // don't show if on settings page already
     if ($this->tools->on_plugin_page('')) {
         return;
     }
     // only show to user with proper permissions
     if (!$this->tools->is_user_authorized()) {
         return;
     }
     // don't show if dismissed
     if (get_transient('mc4wp_api_key_notice_dismissed')) {
         return;
     }
     // don't show if api key is set already
     $options = mc4wp_get_options();
     if (!empty($options['api_key'])) {
         return;
     }
     echo '<div class="notice notice-warning mc4wp-is-dismissible">';
     echo '<p>' . sprintf(__('To get started with MailChimp for WordPress, please <a href="%s">enter your MailChimp API key on the settings page of the plugin</a>.', 'mailchimp-for-wp'), admin_url('admin.php?page=mailchimp-for-wp')) . '</p>';
     echo '<form method="post"><input type="hidden" name="_mc4wp_action" value="dismiss_api_key_notice" /><button type="submit" class="notice-dismiss"><span class="screen-reader-text">Dismiss this notice.</span></button></form>';
     echo '</div>';
 }
Пример #28
0
 /**
  * Show the forms settings page
  */
 public function show_form_settings()
 {
     $opts = mc4wp_get_options('form');
     $mailchimp = new MC4WP_MailChimp();
     $lists = $mailchimp->get_lists();
     // create array of missing form fields
     $missing_form_fields = array();
     // check if form contains EMAIL field
     $search = preg_match('/<(input|textarea)(?=[^>]*name="EMAIL")[^>]*>/i', $opts['markup']);
     if (!$search) {
         $missing_form_fields[] = sprintf(__('An EMAIL field. Example: <code>%s</code>', 'mailchimp-for-wp'), '&lt;input type="email" name="EMAIL" /&gt;');
     }
     // check if form contains submit button
     $search = preg_match('/<(input|button)(?=[^>]*type="submit")[^>]*>/i', $opts['markup']);
     if (!$search) {
         $missing_form_fields[] = sprintf(__('A submit button. Example: <code>%s</code>', 'mailchimp-for-wp'), '&lt;input type="submit" value="' . __('Sign Up', 'mailchimp-for-wp') . '" /&gt;');
     }
     // loop through selected list ids
     if (isset($opts['lists']) && is_array($opts['lists'])) {
         foreach ($opts['lists'] as $list_id) {
             // get list object
             $list = $mailchimp->get_list($list_id);
             if (!is_object($list)) {
                 continue;
             }
             // loop through merge vars of this list
             foreach ($list->merge_vars as $merge_var) {
                 // if field is required, make sure it's in the form mark-up
                 if (!$merge_var->req || $merge_var->tag === 'EMAIL') {
                     continue;
                 }
                 // search for field tag in form mark-up using 'name="FIELD_NAME' without closing " because of array fields
                 $search = stristr($opts['markup'], 'name="' . $merge_var->tag);
                 if (false === $search) {
                     $missing_form_fields[] = sprintf(__('A \'%s\' field', 'mailchimp-for-wp'), $merge_var->tag);
                 }
             }
         }
     }
     require MC4WP_LITE_PLUGIN_DIR . 'includes/views/form-settings.php';
 }
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->options = mc4wp_get_options('form');
 }
Пример #30
0
    private function subscribe($email, array $merge_vars = array(), $signup_type = 'comment', $comment_ID = null)
    {
        $api = mc4wp_get_api();
        $opts = mc4wp_get_options('checkbox');
        if (!$opts['lists'] || empty($opts['lists'])) {
            if ((!defined("DOING_AJAX") || !DOING_AJAX) && current_user_can('manage_options')) {
                wp_die('
					<h3>MailChimp for WP - Error</h3>
					<p>Please select a list to subscribe to in the <a href="' . admin_url('admin.php?page=mc4wp-pro-checkbox-settings') . '">checkbox settings</a>.</p>
					<p style="font-style:italic; font-size:12px;">This message is only visible to administrators for debugging purposes.</p>
					', "Error - MailChimp for WP", array('back_link' => true));
            }
            return 'no_lists_selected';
        }
        // maybe guess first and last name
        if (isset($merge_vars['NAME']) && !isset($merge_vars['FNAME']) && !isset($merge_vars['LNAME'])) {
            $strpos = strpos($merge_vars['NAME'], ' ');
            if ($strpos) {
                $merge_vars['FNAME'] = substr($merge_vars['NAME'], 0, $strpos);
                $merge_vars['LNAME'] = substr($merge_vars['NAME'], $strpos);
            } else {
                $merge_vars['FNAME'] = $merge_vars['NAME'];
            }
        }
        $result = false;
        $merge_vars = apply_filters('mc4wp_merge_vars', $merge_vars, $signup_type);
        $email_type = apply_filters('mc4wp_email_type', 'html');
        $lists = apply_filters('mc4wp_lists', $opts['lists'], $merge_vars);
        foreach ($lists as $list_ID) {
            $result = $api->subscribe($list_ID, $email, $merge_vars, $email_type, $opts['double_optin'], false, true, $opts['send_welcome']);
        }
        if ($result === true) {
            $from_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
            do_action('mc4wp_subscribe_checkbox', $email, $opts['lists'], $signup_type, $merge_vars, $comment_ID, $from_url);
        }
        // check if result succeeded, show debug message to administrators (only in NON-AJAX requests)
        if ($result !== true && $api->has_error() && current_user_can('manage_options') && (!defined("DOING_AJAX") || !DOING_AJAX)) {
            wp_die("<h3>MailChimp for WP - Error</h3>\r\n\t\t\t\t\t<p>The MailChimp server returned the following error message as a response to our sign-up request:</p>\r\n\t\t\t\t\t<pre>" . $api->get_error_message() . "</pre>\r\n\t\t\t\t\t<p>This is the data that was sent to MailChimp: </p>\r\n\t\t\t\t\t<strong>Email</strong>\r\n\t\t\t\t\t<pre>{$email}</pre>\r\n\t\t\t\t\t<strong>Merge variables</strong>\r\n\t\t\t\t\t<pre>" . print_r($merge_vars, true) . "</pre>\r\n\t\t\t\t\t<p style=\"font-style:italic; font-size:12px; \">This message is only visible to administrators for debugging purposes.</p>\r\n\t\t\t\t\t", "Error - MailChimp for WP", array('back_link' => true));
        }
        return $result;
    }