コード例 #1
0
/**
* Loads the MailChimp for WP plugin files
*
* @return boolean True if the plugin files were loaded, false otherwise.
*/
function mc4wp_load_plugin()
{
    global $mc4wp;
    // don't load plugin if user has the premium version installed and activated
    if (defined('MC4WP_VERSION')) {
        return false;
    }
    // load autoloader
    require_once dirname(__FILE__) . '/vendor/autoload_52.php';
    // define some constants
    require dirname(__FILE__) . '/bootstrap.php';
    // Initialize the plugin and store an instance in the global scope
    $mc4wp = mc4wp();
    $mc4wp->init();
    if (is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX)) {
        // load admin class
        $admin = new MC4WP_Admin(__FILE__);
        $admin->add_hooks();
        $admin->load_translations();
        // load promotional elements
        $promotional_elements = new MC4WP_Admin_Ads();
        $promotional_elements->add_hooks();
    }
    return true;
}
コード例 #2
0
/**
 * Bootstrap the MailChimp for WordPress plugin
 *
 * @ignore
 * @access private
 * @return bool
 */
function _mc4wp_load_plugin()
{
    global $mc4wp;
    // Don't run if MailChimp for WP Pro 2.x is activated
    if (defined('MC4WP_VERSION')) {
        return false;
    }
    // bootstrap the core plugin
    define('MC4WP_VERSION', '4.0.9');
    define('MC4WP_PLUGIN_DIR', dirname(__FILE__) . '/');
    define('MC4WP_PLUGIN_URL', plugins_url('/', __FILE__));
    define('MC4WP_PLUGIN_FILE', __FILE__);
    // load autoloader if function not yet exists (for compat with sitewide autoloader)
    if (!function_exists('mc4wp')) {
        require_once MC4WP_PLUGIN_DIR . 'vendor/autoload_52.php';
    }
    /**
     * @global MC4WP_Container $GLOBALS['mc4wp']
     * @name $mc4wp
     */
    $mc4wp = mc4wp();
    $mc4wp['api'] = 'mc4wp_get_api_v3';
    $mc4wp['request'] = array('MC4WP_Request', 'create_from_globals');
    $mc4wp['log'] = 'mc4wp_get_debug_log';
    // forms
    $mc4wp['forms'] = new MC4WP_Form_Manager();
    $mc4wp['forms']->add_hooks();
    // integration core
    $mc4wp['integrations'] = new MC4WP_Integration_Manager();
    $mc4wp['integrations']->add_hooks();
    // bootstrap custom integrations
    require_once MC4WP_PLUGIN_DIR . 'integrations/bootstrap.php';
    // Doing cron? Load Usage Tracking class.
    if (defined('DOING_CRON') && DOING_CRON) {
        MC4WP_Usage_Tracking::instance()->add_hooks();
    }
    // Initialize admin section of plugin
    if (is_admin()) {
        $admin_tools = new MC4WP_Admin_Tools();
        if (defined('DOING_AJAX') && DOING_AJAX) {
            $ajax = new MC4WP_Admin_Ajax($admin_tools);
            $ajax->add_hooks();
        } else {
            $messages = new MC4WP_Admin_Messages();
            $mc4wp['admin.messages'] = $messages;
            $mailchimp = new MC4WP_MailChimp();
            $admin = new MC4WP_Admin($admin_tools, $messages, $mailchimp);
            $admin->add_hooks();
            $forms_admin = new MC4WP_Forms_Admin($messages, $mailchimp);
            $forms_admin->add_hooks();
            $integrations_admin = new MC4WP_Integration_Admin($mc4wp['integrations'], $messages, $mailchimp);
            $integrations_admin->add_hooks();
        }
    }
    return true;
}
コード例 #3
0
/**
 * Bootstrap the MailChimp for WordPress plugin
 *
 * @ignore
 * @access private
 * @return bool
 */
function __mc4wp_load_plugin()
{
    global $mc4wp;
    // Don't run if MailChimp for WP Pro 2.x is activated
    if (defined('MC4WP_VERSION')) {
        return false;
    }
    // bootstrap the core plugin
    define('MC4WP_VERSION', '3.0.11-dev');
    define('MC4WP_PLUGIN_DIR', dirname(__FILE__) . '/');
    define('MC4WP_PLUGIN_URL', plugins_url('/', __FILE__));
    define('MC4WP_PLUGIN_FILE', __FILE__);
    // load autoloader
    require_once MC4WP_PLUGIN_DIR . 'vendor/autoload_52.php';
    /**
     * @global MC4WP_Container $GLOBALS['mc4wp']
     * @name $mc4wp
     */
    $mc4wp = mc4wp();
    $mc4wp['api'] = 'mc4wp_get_api';
    $mc4wp['request'] = array('MC4WP_Request', 'create_from_globals');
    // forms
    $mc4wp['forms'] = new MC4WP_Form_Manager();
    $mc4wp['forms']->add_hooks();
    // integration core
    $mc4wp['integrations'] = new MC4WP_Integration_Manager();
    $mc4wp['integrations']->add_hooks();
    // visitor tracking
    $mc4wp['tracking'] = new MC4WP_Visitor_Tracking();
    $mc4wp['tracking']->add_hooks();
    // bootstrap custom integrations
    require_once MC4WP_PLUGIN_DIR . 'integrations/bootstrap.php';
    // Doing cron? Load Usage Tracking class.
    if (defined('DOING_CRON') && DOING_CRON) {
        MC4WP_Usage_Tracking::instance()->add_hooks();
    }
    // Initialize admin section of plugin
    if (is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX)) {
        $messages = new MC4WP_Admin_Messages();
        $mailchimp = new MC4WP_MailChimp();
        $admin = new MC4WP_Admin($messages, $mailchimp);
        $admin->add_hooks();
        $forms_admin = new MC4WP_Forms_Admin($messages, $mailchimp);
        $forms_admin->add_hooks();
        $integrations_admin = new MC4WP_Integration_Admin($mc4wp['integrations'], $messages, $mailchimp);
        $integrations_admin->add_hooks();
    }
    return true;
}
コード例 #4
0
 /**
  * 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';
 }
コード例 #5
0
 /**
  * @return MC4WP_Debug_Log
  */
 protected function get_log()
 {
     return mc4wp('log');
 }
コード例 #6
0
 /**
  * @return string
  */
 public function get_email()
 {
     // first, try request
     $request = mc4wp('request');
     $email = $request->params->get('EMAIL', '');
     if ($email) {
         return $email;
     }
     // then , try logged-in user
     if (is_user_logged_in()) {
         $user = wp_get_current_user();
         return $user->user_email;
     }
     // then, try visitor tracking
     return mc4wp('tracking')->get_field('EMAIL', '');
 }
コード例 #7
0
/**
 * Deregister a previously registered integration with MailChimp for WordPress
 *
 * @since 3.0
 * @access public
 *
 * @param string $slug
 *
 * @return void
 */
function mc4wp_deregister_integration($slug)
{
    return mc4wp('integrations')->deregister_integration($slug);
}
コード例 #8
0
/**
 * Guesses merge vars based on given data & current request.
 *
 * @since 3.0
 * @access public
 *
 * @param array $merge_vars
 *
 * @return array
 */
function mc4wp_guess_merge_vars($merge_vars = array())
{
    // maybe guess first and last name
    if (isset($merge_vars['NAME'])) {
        if (!isset($merge_vars['FNAME']) && !isset($merge_vars['LNAME'])) {
            $strpos = strpos($merge_vars['NAME'], ' ');
            if ($strpos !== false) {
                $merge_vars['FNAME'] = trim(substr($merge_vars['NAME'], 0, $strpos));
                $merge_vars['LNAME'] = trim(substr($merge_vars['NAME'], $strpos));
            } else {
                $merge_vars['FNAME'] = $merge_vars['NAME'];
            }
        }
    }
    // set ip address
    if (empty($merge_vars['OPTIN_IP'])) {
        $optin_ip = mc4wp('request')->get_client_ip();
        if (!empty($optin_ip)) {
            $merge_vars['OPTIN_IP'] = $optin_ip;
        }
    }
    /**
     * Filters merge vars which are sent to MailChimp
     *
     * @param array $merge_vars
     */
    $merge_vars = (array) apply_filters('mc4wp_merge_vars', $merge_vars);
    return $merge_vars;
}
コード例 #9
0
 /**
  * MC4WP_MailChimp constructor.
  */
 public function __construct()
 {
     $this->api = mc4wp('api');
 }
コード例 #10
0
 /**
  * @return MC4WP_API_v3
  */
 protected function get_api()
 {
     return mc4wp('api');
 }
コード例 #11
0
<?php

defined('ABSPATH') or exit;
$tags = mc4wp('forms')->get_tags();
?>
<h2><?php 
_e('Add dynamic form variable', 'mailchimp-for-wp');
?>
</h2>
<p>
	<?php 
echo sprintf(__('The following list of variables can be used to <a href="%s">add some dynamic content to your form or success and error messages</a>.', 'mailchimp-for-wp'), 'https://mc4wp.com/kb/using-variables-in-your-form-or-messages/') . ' ' . __('This allows you to personalise your form or response messages.', 'mailchimp-for-wp');
?>
</p>
<table class="widefat striped">
	<?php 
foreach ($tags as $tag => $config) {
    $tag = !empty($config['example']) ? $config['example'] : $tag;
    ?>
		<tr>
			<td>
				<input type="text" class="widefat" value="<?php 
    echo esc_attr(sprintf('{%s}', $tag));
    ?>
" readonly="readonly" onfocus="this.select();" />
				<p class="help" style="margin-bottom:0;"><?php 
    echo esc_html($config['description']);
    ?>
</p>
			</td>
		</tr>
コード例 #12
0
 /**
  * Show the forms settings page
  */
 public function show_form_settings()
 {
     $opts = mc4wp()->forms->options;
     $lists = MC4WP_MailChimp_Tools::get_lists();
     require MC4WP_PLUGIN_DIR . 'src/views/form-settings.php';
 }
コード例 #13
0
 /**
  * @return array
  */
 public function load_settings()
 {
     return mc4wp()->forms->options;
 }
コード例 #14
0
 /**
  * @return MC4WP_Request
  */
 private function get_request()
 {
     return mc4wp('request');
 }
コード例 #15
0
 /**
  * Get an array of list_id => number of subscribers
  *
  * @return array
  */
 public function get_subscriber_counts()
 {
     // get from transient
     $list_counts = get_transient($this->list_counts_transient_name);
     if (is_array($list_counts)) {
         return $list_counts;
     }
     // transient not valid, fetch from API
     $api = mc4wp('api');
     $lists = $api->get_lists();
     $list_counts = array();
     if (is_array($lists)) {
         // we got a valid response
         foreach ($lists as $list) {
             $list_counts["{$list->id}"] = $list->stats->member_count;
         }
         $seconds = 1200;
         /**
          * Filters the cache time for MailChimp lists configuration. Defaults to 1200.
          *
          * @since 2.0
          * @param int $seconds
          */
         $transient_lifetime = (int) apply_filters('mc4wp_lists_count_cache_time', $seconds);
         set_transient($this->list_counts_transient_name, $list_counts, $transient_lifetime);
         // bail
         return $list_counts;
     }
     // api call failed, get from stored lists
     $lists = $this->get_lists(true);
     foreach ($lists as $list) {
         $list_counts["{$list->id}"] = $list->subscriber_count;
     }
     return $list_counts;
 }
コード例 #16
0
 /**
  * Returns HTML for sign-up form with the given $form_id.
  *
  * @param array|int $atts
  * @return string HTML of given form_id.
  */
 function mc4wp_get_form($atts = array())
 {
     if (is_numeric($atts)) {
         $id = $atts;
         $atts = array('id' => $id);
     }
     return mc4wp()->forms->output_form($atts);
 }
コード例 #17
0
 /**
  * @return string
  */
 public function get_email()
 {
     // first, try request
     $request = mc4wp('request');
     $email = $request->params->get('EMAIL', '');
     if ($email) {
         return $email;
     }
     // then , try logged-in user
     if (is_user_logged_in()) {
         $user = wp_get_current_user();
         return $user->user_email;
     }
     // TODO: Read from cookie? Or add $_COOKIE support to {data} tag?
     return '';
 }
コード例 #18
0
ファイル: functions.php プロジェクト: nihrain/accelerate
/**
 * Gets an instance of the submitted form, if any.
 *
 * @access public
 *
 * @return MC4WP_Form|null
 */
function mc4wp_get_submitted_form()
{
    return mc4wp('forms')->get_submitted_form();
}
コード例 #19
0
 /**
  * Get the data for this integration request
  *
  * By default, this will return a combination of all $_GET and $_POST parameters.
  * Override this method if you need data from somewhere else.
  *
  * This data should contain the value of the checkbox (required)
  * and the lists to which should be subscribed (optional)
  *
  * @see MC4WP_Integration::$checkbox_name
  * @see MC4WP_Integration::get_lists
  * @see MC4WP_Integration::checkbox_was_checked
  *
  * @return array
  */
 public function get_data()
 {
     $request = mc4wp('request');
     $data = $request->params->all();
     return $data;
 }
コード例 #20
0
 /**
  * @return MC4WP_Request
  */
 protected function get_request()
 {
     return mc4wp('request');
 }