first commit

This commit is contained in:
DESKTOP-GBA0BK8\Admin
2023-04-08 12:19:53 -04:00
commit 7c8c8b1c76
4586 changed files with 2050693 additions and 0 deletions
@@ -0,0 +1,201 @@
<?php
/**
* Class MC4WP_Integration_Admin
*
* @ignore
* @access private
*/
class MC4WP_Integration_Admin
{
/**
* @var MC4WP_Integration_Manager
*/
protected $integrations;
/**
* @var MC4WP_MailChimp
*/
protected $mailchimp;
/**
* @var MC4WP_Admin_Messages
*/
protected $messages;
/**
* @param MC4WP_Integration_Manager $integrations
* @param MC4WP_MailChimp $mailchimp
* @param MC4WP_Admin_Messages $messages
*/
public function __construct(MC4WP_Integration_Manager $integrations, MC4WP_Admin_Messages $messages, MC4WP_MailChimp $mailchimp)
{
$this->integrations = $integrations;
$this->mailchimp = $mailchimp;
$this->messages = $messages;
}
/**
* Add hooks
*/
public function add_hooks()
{
add_action('admin_init', array( $this, 'register_setting' ));
add_action('mc4wp_admin_enqueue_assets', array( $this, 'enqueue_assets' ), 10, 2);
add_filter('mc4wp_admin_menu_items', array( $this, 'add_menu_item' ));
}
/**
* Register settings
*/
public function register_setting()
{
register_setting('mc4wp_integrations_settings', 'mc4wp_integrations', array( $this, 'save_integration_settings' ));
}
/**
* Enqueue assets
*
* @param string $suffix
* @param string $page
*
* @return void
*/
public function enqueue_assets($suffix, $page = '')
{
// only load on integrations pages
if ($page !== 'integrations') {
return;
}
wp_register_script('mc4wp-integrations-admin', MC4WP_PLUGIN_URL . 'assets/js/integrations-admin' . $suffix . '.js', array( 'mc4wp-admin' ), MC4WP_VERSION, true);
wp_enqueue_script('mc4wp-integrations-admin');
}
/**
* @param $items
*
* @return array
*/
public function add_menu_item($items)
{
$items[] = array(
'title' => __('Integrations', 'mailchimp-for-wp'),
'text' => __('Integrations', 'mailchimp-for-wp'),
'slug' => 'integrations',
'callback' => array( $this, 'show_integrations_page' ),
'position' => 20
);
return $items;
}
/**
* @param array $new_settings
* @return array
*/
public function save_integration_settings(array $new_settings)
{
$integrations = $this->integrations->get_all();
$current_settings = (array) get_option('mc4wp_integrations', array());
$settings = array();
foreach ($integrations as $slug => $integration) {
$settings[ $slug ] = $this->parse_integration_settings($slug, $current_settings, $new_settings);
}
return $settings;
}
/**
* @since 3.0
* @param $slug
* @param $current
* @param $new
*
* @return array
*/
protected function parse_integration_settings($slug, $current, $new)
{
$settings = array();
// start with current settings
if (! empty($current[ $slug ])) {
$settings = $current[ $slug ];
}
// if no new settings were given, return current settings.
if (empty($new[ $slug ])) {
return $settings;
}
// merge new settings with currents (to allow passing partial setting arrays)
$settings = array_merge($settings, $new[ $slug]);
// sanitize settings
$settings = $this->sanitize_integration_settings($settings);
return $settings;
}
/**
* @param array $settings
*
* @return array
*/
protected function sanitize_integration_settings($settings)
{
// filter null values from lists setting
if (! empty($settings['lists'])) {
$settings['lists'] = array_filter($settings['lists']);
} else {
$settings['lists'] = array();
}
return $settings;
}
/**
* Show the Integration Settings page
*
* @internal
*/
public function show_integrations_page()
{
if (! empty($_GET['integration'])) {
$this->show_integration_settings_page($_GET['integration']);
return;
}
// get all installed & enabled integrations
$enabled_integrations = $this->integrations->get_enabled_integrations();
// get all integrations but remove enabled integrations from the resulting array
$integrations = $this->integrations->get_all();
require dirname(__FILE__) . '/views/integrations.php';
}
/**
* @param string $slug
*
* @internal
*/
public function show_integration_settings_page($slug)
{
try {
$integration = $this->integrations->get($slug);
} catch (Exception $e) {
echo sprintf('<h3>Integration not found.</h3><p>No integration with slug <strong>%s</strong> was found.</p>', esc_html($slug));
return;
}
$opts = $integration->options;
$lists = $this->mailchimp->get_lists();
require dirname(__FILE__) . '/views/integration-settings.php';
}
}
@@ -0,0 +1,104 @@
<?php
/**
* Class MC4WP_Integration_Fixture
*
* @since 3.0
* @ignore
*/
class MC4WP_Integration_Fixture
{
/**
* @var string
*/
public $slug;
/**
* @var string
*/
public $class;
/**
* @var bool
*/
public $enabled = false;
/**
* @var bool
*/
public $enabled_by_default = true;
/**
* @var MC4WP_Integration
*/
public $instance;
/**
* @var array
*/
public $options;
/**
* @param string $slug
* @param string $class
* @param bool $enabled_by_default
* @param array $options
*/
public function __construct($slug, $class, $enabled_by_default = false, array $options = array())
{
$this->slug = $slug;
$this->class = $class;
$this->enabled = $this->enabled_by_default = $enabled_by_default;
$this->options = $options;
if (! empty($options['enabled'])) {
$this->enabled = true;
}
}
/**
* Returns the actual instance
*
* @return MC4WP_Integration
*/
public function load()
{
if (! $this->instance instanceof MC4WP_Integration) {
$this->instance = new $this->class($this->slug, $this->options);
}
return $this->instance;
}
/**
* Tunnel everything to MC4WP_Integration class
*
* @param $name
* @param $arguments
*
* @return MC4WP_Integration
*/
public function __call($name, $arguments)
{
return call_user_func_array(array( $this->load(), $name ), $arguments);
}
/**
* @param $name
*
* @return string
*/
public function __get($name)
{
return $this->load()->$name;
}
/**
* @return string
*/
public function __toString()
{
return $this->slug;
}
}
@@ -0,0 +1,190 @@
<?php
/**
* Class MC4WP_Integration_Manager
*
* @ignore
* @access private
*/
class MC4WP_Integration_Manager
{
/**
* @var MC4WP_Integration_Fixture[]
*/
protected $integrations = array();
/**
* @var MC4WP_Integration_Tags
*/
protected $tags;
/**
* Constructor
*/
public function __construct()
{
$this->tags = new MC4WP_Integration_Tags();
}
/**
* Add hooks
*/
public function add_hooks()
{
add_action('after_setup_theme', array( $this, 'initialize' ));
$this->tags->add_hooks();
}
/**
* Add hooks
*/
public function initialize()
{
/*** @var MC4WP_Integration_Fixture $integration */
$enabled_integrations = $this->get_enabled_integrations();
foreach ($enabled_integrations as $integration) {
$integration->load()->initialize();
}
}
/**
* Get an integration instance
*
* @return MC4WP_Integration_Fixture[]
* @throws Exception
*/
public function get_all()
{
return $this->integrations;
}
/**
* Get an integration instance
*
* @param string $slug
* @return MC4WP_Integration
* @throws Exception
*/
public function get($slug)
{
if (! isset($this->integrations[ $slug ])) {
throw new Exception(sprintf("No integration with slug %s has been registered.", $slug));
}
return $this->integrations[ $slug ]->load();
}
/**
* Register a new integration class
*
* @param string $slug
* @param string $class
* @param bool $enabled
*/
public function register_integration($slug, $class, $enabled = false)
{
$raw_options = $this->get_integration_options($slug);
$this->integrations[ $slug ] = new MC4WP_Integration_Fixture($slug, $class, $enabled, $raw_options);
}
/**
* Deregister an integration class
*
* @param string $slug
*/
public function deregister_integration($slug)
{
if (isset($this->integrations[ $slug ])) {
unset($this->integrations[ $slug ]);
}
}
/**
* Checks whether a certain integration is enabled (in the settings)
*
* This is decoupled from the integration class itself as checking an array is way "cheaper" than instantiating an object
*
* @param MC4WP_Integration_Fixture $integration
*
* @return bool
*/
public function is_enabled(MC4WP_Integration_Fixture $integration)
{
return $integration->enabled;
}
/**
* @param MC4WP_Integration $integration
* @return bool
*/
public function is_installed($integration)
{
return $integration->is_installed();
}
/**
* Get the integrations which are enabled
*
* - Some integrations are always enabled because they need manual work
* - Other integrations can be enabled in the settings page
* - Only returns installed integrations
*
* @return array
*/
public function get_enabled_integrations()
{
// get all enabled integrations
$enabled_integrations = array_filter($this->integrations, array( $this, 'is_enabled' ));
// remove duplicate values, for whatever reason..
$enabled_integrations = array_unique($enabled_integrations);
// filter out integrations which are not installed
$installed_enabled_integrations = array_filter($enabled_integrations, array( $this, 'is_installed' ));
return $installed_enabled_integrations;
}
/**
* Gets all integration options in a keyed array
*
* @return array
*/
private function load_options()
{
$options = (array) get_option('mc4wp_integrations', array());
/**
* Filters global integration options
*
* This array holds ALL integration settings
*
* @since 3.0
* @param array $options
* @ignore
*/
return (array) apply_filters('mc4wp_integration_options', $options);
}
/**
* Gets the raw options for an integration
*
* @param $slug
* @return array
*/
public function get_integration_options($slug)
{
static $options;
if ($options === null) {
$options = $this->load_options();
}
return isset($options[ $slug ]) ? $options[ $slug ] : array();
}
}
@@ -0,0 +1,79 @@
<?php
/**
* Class MC4WP_Integration_Tags
*
* @ignore
* @access private
*/
class MC4WP_Integration_Tags
{
/**
* @var MC4WP_Dynamic_Content_Tags
*/
protected $tags;
/**
* @var MC4WP_Integration
*/
protected $integration;
/**
* Constructor
*/
public function __construct()
{
$this->tags = new MC4WP_Dynamic_Content_Tags('integrations');
}
/**
* Add hooks
*/
public function add_hooks()
{
add_filter('mc4wp_dynamic_content_tags_integrations', array( $this, 'register' ));
add_filter('mc4wp_integration_checkbox_label', array( $this, 'replace' ), 10, 2);
}
/**
* Register dynamic content tags for integrations
*
* @hooked `mc4wp_dynamic_content_tags_integrations`
* @param array $tags
* @return array
*/
public function register(array $tags)
{
$tags['subscriber_count'] = array(
'description' => __('Replaced with the number of subscribers on the selected list(s)', 'mailchimp-for-wp'),
'callback' => array( $this, 'get_subscriber_count' )
);
return $tags;
}
/**
* @hooked `mc4wp_integration_checkbox_label`
* @param string $string
* @param MC4WP_Integration $integration
* @return string
*/
public function replace($string, MC4WP_Integration $integration)
{
$this->integration = $integration;
$string = $this->tags->replace($string);
return $string;
}
/**
* Returns the number of subscribers on the selected lists (for the form context)
*
* @return int
*/
public function get_subscriber_count()
{
$mailchimp = new MC4WP_MailChimp();
$count = $mailchimp->get_subscriber_count($this->integration->get_lists());
return number_format($count);
}
}
@@ -0,0 +1,567 @@
<?php
/**
* Class MC4WP_Integration
*
* Base class for all integrations.
*
* Extend this class and implement the `add_hooks` method to get a settings page.
*
* @access public
* @since 3.0
* @abstract
*/
abstract class MC4WP_Integration
{
/**
* @var string Name of this integration.
*/
public $name = '';
/**
* @var string Description
*/
public $description = '';
/**
* @var string Slug, used as an unique identifier for this integration.
*/
public $slug = '';
/**
* @var array Array of settings
*/
public $options = array();
/**
* @var string Name attribute for the checkbox element. Will be created from slug if empty.
*/
protected $checkbox_name = '';
/**
* Constructor
*
* @param string $slug
* @param array $options
*/
public function __construct($slug, array $options)
{
$this->slug = $slug;
$this->options = $this->parse_options($options);
// if checkbox name is not set, set a good custom value
if (empty($this->checkbox_name)) {
$this->checkbox_name = '_mc4wp_subscribe_' . $this->slug;
}
}
/**
* Return array of default options
*
* @return array
*/
protected function get_default_options()
{
return array(
'css' => 0,
'double_optin' => 1,
'enabled' => 0,
'implicit' => 0,
'label' => __('Sign me up for the newsletter!', 'mailchimp-for-wp'),
'lists' => array(),
'precheck' => 0,
'replace_interests' => 0,
'update_existing' => 0,
'wrap_p' => 1
);
}
/**
* @param array $options
*
* @return array
*/
protected function parse_options(array $options)
{
$slug = $this->slug;
$default_options = $this->get_default_options();
$options = array_merge($default_options, $options);
/**
* @deprecated Use mc4wp_integration_{$slug}_options instead
*/
$options = (array) apply_filters('mc4wp_' . $slug . '_integration_options', $options);
/**
* Filters options for a specific integration
*
* The dynamic portion of the hook, `$slug`, refers to the slug of the ingration.
*
* @param array $integration_options
*/
return (array) apply_filters('mc4wp_integration_' . $slug . '_options', $options);
}
/**
* Initialize the integration
*/
public function initialize()
{
$this->add_required_hooks();
$this->add_hooks();
}
/**
* Adds the required hooks for core functionality, like adding checkbox reset CSS.
*/
protected function add_required_hooks()
{
if ($this->options['css'] && ! $this->options['implicit']) {
add_action('wp_head', array( $this, 'print_css_reset' ));
}
}
/**
* Was integration triggered?
*
* Will always return true when integration is implicit. Otherwise, will check value of checkbox.
*
* @param int $object_id Useful when overriding method. (optional)
* @return bool
*/
public function triggered($object_id = null)
{
return $this->options['implicit'] || $this->checkbox_was_checked();
}
/**
* Adds the hooks which are specific to this integration
*/
abstract protected function add_hooks();
/**
* Print CSS reset
*
* @hooked `wp_head`
*/
public function print_css_reset()
{
$suffix = defined('SCRIPT_DEBUG') ? '' : '.min';
$css = file_get_contents(MC4WP_PLUGIN_DIR . 'assets/css/checkbox-reset' . $suffix . '.css');
// replace selector by integration specific selector so the css affects just this checkbox
$css = str_ireplace('__INTEGRATION_SLUG__', $this->slug, $css);
printf('<style type="text/css">%s</style>', $css);
}
/**
* Get the text for the label element
*
* @return string
*/
public function get_label_text()
{
$integration = $this;
$label = $this->options['label'];
/**
* Filters the checkbox label
*
* @since 3.0
*
* @param string $label
* @param MC4WP_Integration $integration
* @ignore
*/
$label = (string) apply_filters('mc4wp_integration_checkbox_label', $label, $integration);
return $label;
}
/**
* Was the integration checkbox checked?
*
* @return bool
*/
public function checkbox_was_checked()
{
$data = $this->get_data();
return (isset($data[ $this->checkbox_name ]) && $data[ $this->checkbox_name ] == 1);
}
/**
* Get a string of attributes for the checkbox element.
*
* @return string
*/
protected function get_checkbox_attributes()
{
$integration = $this;
$slug = $this->slug;
$attributes = array();
if ($this->options['precheck']) {
$attributes['checked'] = 'checked';
}
/**
* Filters the attributes array.
*
* @param array $attributes
* @param MC4WP_Integration $integration
* @ignore
*/
$attributes = (array) apply_filters('mc4wp_integration_checkbox_attributes', $attributes, $integration);
/**
* Filters the attributes array.
*
* The dynamic portion of the hook, `$slug`, refers to the slug for this integration.
*
* @param array $attributes
* @param MC4WP_Integration $integration
* @ignore
*/
$attributes = (array) apply_filters('mc4wp_integration_' . $slug . '_checkbox_attributes', $attributes, $integration);
$string = '';
foreach ($attributes as $key => $value) {
$string .= sprintf('%s="%s"', $key, esc_attr($value));
}
return $string;
}
/**
* Outputs a checkbox
*/
public function output_checkbox()
{
echo $this->get_checkbox_html();
}
/**
* Get HTML for the checkbox
*
* @return string
*/
public function get_checkbox_html()
{
$show_checkbox = empty($this->options['implicit']);
$integration_slug = $this->slug;
/**
* Filters whether to show the sign-up checkbox for this integration.
*
* @param bool $show_checkbox
* @param string $integration_slug
*/
$show_checkbox = (bool) apply_filters('mc4wp_integration_show_checkbox', $show_checkbox, $integration_slug);
if (! $show_checkbox) {
return '';
}
ob_start();
echo sprintf('<!-- Mailchimp for WordPress v%s - https://mc4wp.com/ -->', MC4WP_VERSION);
/** @ignore */
do_action('mc4wp_integration_before_checkbox_wrapper', $this);
/** @ignore */
do_action('mc4wp_integration_'. $this->slug .'_before_checkbox_wrapper', $this);
$wrapper_tag = $this->options['wrap_p'] ? 'p' : 'span';
// Hidden field to make sure "0" is sent to server
echo sprintf('<input type="hidden" name="%s" value="0" />', esc_attr($this->checkbox_name));
echo sprintf('<%s class="mc4wp-checkbox mc4wp-checkbox-%s">', $wrapper_tag, esc_attr($this->slug));
echo '<label>';
echo sprintf('<input type="checkbox" name="%s" value="1" %s />', esc_attr($this->checkbox_name), $this->get_checkbox_attributes());
echo sprintf('<span>%s</span>', $this->get_label_text());
echo '</label>';
echo sprintf('</%s>', $wrapper_tag);
/** @ignore */
do_action('mc4wp_integration_after_checkbox_wrapper', $this);
/** @ignore */
do_action('mc4wp_integration_'. $this->slug .'_after_checkbox_wrapper', $this);
echo '<!-- / Mailchimp for WordPress -->';
$html = ob_get_clean();
return $html;
}
/**
* Get the selected Mailchimp lists
*
* @return array Array of List ID's
*/
public function get_lists()
{
$data = $this->get_data();
$integration = $this;
$slug = $this->slug;
// get checkbox lists options
$lists = $this->options['lists'];
// get lists from request, if set.
if (! empty($data['_mc4wp_lists'])) {
$lists = $data['_mc4wp_lists'];
// ensure lists is an array
if (! is_array($lists)) {
$lists = explode(',', $lists);
$lists = array_map('trim', $lists);
}
}
/**
* Allow plugins to filter final lists value. This filter is documented elsewhere.
*
* @since 2.0
* @see MC4WP_Form::get_lists
* @ignore
*/
$lists = (array) apply_filters('mc4wp_lists', $lists);
/**
* Filters the Mailchimp lists this integration should subscribe to
*
* @since 3.0
*
* @param array $lists
* @param MC4WP_Integration $integration
*/
$lists = (array) apply_filters('mc4wp_integration_lists', $lists, $integration);
/**
* Filters the Mailchimp lists a specific integration should subscribe to
*
* The dynamic portion of the hook, `$slug`, refers to the slug of the integration.
*
* @since 3.0
*
* @param array $lists
* @param MC4WP_Integration $integration
*/
$lists = (array) apply_filters('mc4wp_integration_' . $slug . '_lists', $lists, $integration);
return $lists;
}
/**
* Makes a subscription request
*
* @param array $data
* @param int $related_object_id
*
* @return boolean
*/
protected function subscribe(array $data, $related_object_id = 0)
{
$integration = $this;
$slug = $this->slug;
$mailchimp = new MC4WP_MailChimp();
$log = $this->get_log();
$list_ids = $this->get_lists();
/** @var MC4WP_MailChimp_Subscriber $subscriber */
$subscriber = null;
$result = false;
// validate lists
if (empty($list_ids)) {
$log->warning(sprintf('%s > No Mailchimp lists were selected', $this->name));
return false;
}
/**
* Filters data for integration requests.
*
* @param array $data
*/
$data = apply_filters('mc4wp_integration_data', $data);
/**
* Filters data for a specific integration request.
*
* The dynamic portion of the hook, `$slug`, refers to the integration slug.
*
* @param array $data
* @param int $related_object_id
*/
$data = apply_filters("mc4wp_integration_{$slug}_data", $data, $related_object_id);
/**
* @ignore
* @deprecated 4.0
*/
$data = apply_filters('mc4wp_merge_vars', $data);
/**
* @deprecated 4.0
* @ignore
*/
$data = apply_filters('mc4wp_integration_merge_vars', $data, $integration);
/**
* @deprecated 4.0
* @ignore
*/
$data = apply_filters("mc4wp_integration_{$slug}_merge_vars", $data, $integration);
$email_type = mc4wp_get_email_type();
$mapper = new MC4WP_List_Data_Mapper($data, $list_ids);
/** @var MC4WP_MailChimp_Subscriber[] $map */
$map = $mapper->map();
foreach ($map as $list_id => $subscriber) {
$subscriber->status = $this->options['double_optin'] ? 'pending' : 'subscribed';
$subscriber->email_type = $email_type;
$subscriber->ip_signup = mc4wp_get_request_ip_address();
/** @ignore (documented elsewhere) */
$subscriber = apply_filters('mc4wp_subscriber_data', $subscriber);
/**
* Filters subscriber data before it is sent to Mailchimp. Only fires for integration requests.
*
* @param MC4WP_MailChimp_Subscriber $subscriber
*/
$subscriber = apply_filters('mc4wp_integration_subscriber_data', $subscriber);
/**
* Filters subscriber data before it is sent to Mailchimp. Only fires for integration requests.
*
* The dynamic portion of the hook, `$slug`, refers to the integration slug.
*
* @param MC4WP_MailChimp_Subscriber $subscriber
* @param int $related_object_id
*/
$subscriber = apply_filters("mc4wp_integration_{$slug}_subscriber_data", $subscriber, $related_object_id);
$result = $mailchimp->list_subscribe($list_id, $subscriber->email_address, $subscriber->to_array(), $this->options['update_existing'], $this->options['replace_interests']);
}
// if result failed, show error message
if (! $result) {
// log error
if ($mailchimp->get_error_code() == 214) {
$log->warning(sprintf("%s > %s is already subscribed to the selected list(s)", $this->name, $subscriber->email_address));
} else {
$log->error(sprintf('%s > Mailchimp API Error: %s', $this->name, $mailchimp->get_error_message()));
}
// bail
return false;
}
$log->info(sprintf('%s > Successfully subscribed %s', $this->name, $subscriber->email_address));
/**
* Runs right after someone is subscribed using an integration
*
* @since 3.0
*
* @param MC4WP_Integration $integration
* @param string $email_address
* @param array $merge_vars
* @param MC4WP_MailChimp_Subscriber[] $subscriber_data
* @param int $related_object_id
*/
do_action('mc4wp_integration_subscribed', $integration, $subscriber->email_address, $subscriber->merge_fields, $map, $related_object_id);
return $result;
}
/**
* Are the required dependencies for this integration installed?
*
* @return bool
*/
public function is_installed()
{
return false;
}
/**
* Which UI elements should we show on the settings page for this integration?
*
* @return array
*/
public function get_ui_elements()
{
return array_keys($this->options);
}
/**
* Does integration have the given UI element?
*
* @param $element
* @return bool
*/
public function has_ui_element($element)
{
$elements = $this->get_ui_elements();
return in_array($element, $elements);
}
/**
* Return a string to the admin settings page for this object (if any)
*
* @param int $object_id
* @return string
*/
public function get_object_link($object_id)
{
return '';
}
/**
* 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()
{
$data = array_merge((array) $_GET, (array) $_POST);
return $data;
}
/**
* @return MC4WP_Debug_Log
*/
protected function get_log()
{
return mc4wp('log');
}
/**
* @return MC4WP_API_v3
*/
protected function get_api()
{
return mc4wp('api');
}
}
@@ -0,0 +1,50 @@
<?php
defined('ABSPATH') or exit;
/**
* Class MC4WP_User_Integration
*
* @access public
* @since 2.0
*/
abstract class MC4WP_User_Integration extends MC4WP_Integration
{
/**
* @param WP_User $user
*
* @return array
*/
protected function user_merge_vars(WP_User $user)
{
// start with user_login as name, since that's always known
$data = array(
'EMAIL' => $user->user_email,
'NAME' => $user->user_login,
);
if ('' !== $user->first_name) {
$data['NAME'] = $user->first_name;
$data['FNAME'] = $user->first_name;
}
if ('' !== $user->last_name) {
$data['LNAME'] = $user->last_name;
}
if ('' !== $user->first_name && '' !== $user->last_name) {
$data['NAME'] = sprintf('%s %s', $user->first_name, $user->last_name);
}
/**
* @since 3.0
* @deprecated 4.0
* @ignore
*/
$data = (array) apply_filters('mc4wp_user_merge_vars', $data, $user);
return $data;
}
}
@@ -0,0 +1,57 @@
<?php
/**
* Gets an array of all registered integrations
*
* @since 3.0
* @access public
*
* @return MC4WP_Integration[]
*/
function mc4wp_get_integrations()
{
return mc4wp('integrations')->get_all();
}
/**
* Get an instance of a registered integration class
*
* @since 3.0
* @access public
*
* @param string $slug
*
* @return MC4WP_Integration
*/
function mc4wp_get_integration($slug)
{
return mc4wp('integrations')->get($slug);
}
/**
* Register a new integration with Mailchimp for WordPress
*
* @since 3.0
* @access public
*
* @param string $slug
* @param string $class
*
* @param bool $always_enabled
*/
function mc4wp_register_integration($slug, $class, $always_enabled = false)
{
return mc4wp('integrations')->register_integration($slug, $class, $always_enabled);
}
/**
* Deregister a previously registered integration with Mailchimp for WordPress
*
* @since 3.0
* @access public
* @param string $slug
*/
function mc4wp_deregister_integration($slug)
{
mc4wp('integrations')->deregister_integration($slug);
}
@@ -0,0 +1,263 @@
<?php defined('ABSPATH') or exit;
/** @var MC4WP_Integration $integration */
/** @var array $opts */
?>
<div id="mc4wp-admin" class="wrap mc4wp-settings">
<p class="breadcrumbs">
<span class="prefix"><?php echo __('You are here: ', 'mailchimp-for-wp'); ?></span>
<a href="<?php echo admin_url('admin.php?page=mailchimp-for-wp'); ?>">Mailchimp for WordPress</a> &rsaquo;
<a href="<?php echo admin_url('admin.php?page=mailchimp-for-wp-integrations'); ?>"><?php _e('Integrations', 'mailchimp-for-wp'); ?></a> &rsaquo;
<span class="current-crumb"><strong><?php echo esc_html($integration->name); ?></strong></span>
</p>
<div class="main-content row">
<!-- Main Content -->
<div class="main-content col col-4 col-sm-6">
<h1 class="page-title">
<?php printf(__('%s integration', 'mailchimp-for-wp'), esc_html($integration->name)); ?>
</h1>
<h2 style="display: none;"></h2>
<?php settings_errors(); ?>
<div id="notice-additional-fields" class="notice notice-warning" style="display: none;">
<p><?php _e('The selected Mailchimp lists require non-default fields, which may prevent this integration from working.', 'mailchimp-for-wp'); ?></p>
<p><?php echo sprintf(__('Please ensure you <a href="%s">configure the plugin to send all required fields</a> or <a href="%s">log into your Mailchimp account</a> and make sure only the email & name fields are marked as required fields for the selected list(s).', 'mailchimp-for-wp'), 'https://kb.mc4wp.com/send-additional-fields-from-integrations/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=integrations-page', 'https://admin.mailchimp.com/lists/'); ?></p>
</div>
<p>
<?php _e($integration->description, 'mailchimp-for-wp'); ?>
</p>
<!-- Settings form -->
<form method="post" action="<?php echo admin_url('options.php'); ?>">
<?php settings_fields('mc4wp_integrations_settings'); ?>
<?php
/**
* Runs just before integration settings are outputted in admin.
*
* @since 3.0
*
* @param MC4WP_Integration $integration
* @param array $opts
* @ignore
*/
do_action('mc4wp_admin_before_integration_settings', $integration, $opts);
/**
* @ignore
*/
do_action('mc4wp_admin_before_' . $integration->slug . '_integration_settings', $integration, $opts);
?>
<table class="form-table">
<?php if ($integration->has_ui_element('enabled')) {
?>
<tr valign="top">
<th scope="row"><?php _e('Enabled?', 'mailchimp-for-wp'); ?></th>
<td class="nowrap integration-toggles-wrap">
<label><input type="radio" name="mc4wp_integrations[<?php echo $integration->slug; ?>][enabled]" value="1" <?php checked($opts['enabled'], 1); ?> /> <?php _e('Yes'); ?></label> &nbsp;
<label><input type="radio" name="mc4wp_integrations[<?php echo $integration->slug; ?>][enabled]" value="0" <?php checked($opts['enabled'], 0); ?> /> <?php _e('No'); ?></label>
<p class="help"><?php printf(__('Enable the %s integration? This will add a sign-up checkbox to the form.', 'mailchimp-for-wp'), $integration->name); ?></p>
</td>
</tr>
<?php
} ?>
<?php $config = array( 'element' => 'mc4wp_integrations['. $integration->slug .'][enabled]', 'value' => '1', 'hide' => false ); ?>
<tbody class="integration-toggled-settings" data-showif="<?php echo esc_attr(json_encode($config)); ?>">
<?php if ($integration->has_ui_element('implicit')) {
?>
<tr valign="top">
<th scope="row"><?php _e('Implicit?', 'mailchimp-for-wp'); ?></th>
<td class="nowrap">
<label><input type="radio" name="mc4wp_integrations[<?php echo $integration->slug; ?>][implicit]" value="1" <?php checked($opts['implicit'], 1); ?> /> <?php _e('Yes'); ?></label> &nbsp;
<label><input type="radio" name="mc4wp_integrations[<?php echo $integration->slug; ?>][implicit]" value="0" <?php checked($opts['implicit'], 0); ?> /> <?php _e('No'); ?> <?php echo '<em>' . __('(recommended)', 'mailchimp-for-wp') . '</em>'; ?>
</label>
<p class="help">
<?php _e('Select "yes" if you want to subscribe people without asking them explicitly.', 'mailchimp-for-wp');
echo '<br />';
printf(__('<strong>Warning: </strong> enabling this may affect your <a href="%s">GDPR compliance</a>.', 'mailchimp-for-wp'), 'https://kb.mc4wp.com/gdpr-compliance/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=integrations-page'); ?>
</p>
</td>
</tr>
<?php
} ?>
<?php if ($integration->has_ui_element('lists')) {
?>
<?php // hidden input to make sure a value is sent to the server when no checkboxes were selected?>
<input type="hidden" name="mc4wp_integrations[<?php echo $integration->slug; ?>][lists][]" value="" />
<tr valign="top">
<th scope="row"><?php _e('Mailchimp Lists', 'mailchimp-for-wp'); ?></th>
<?php if (! empty($lists)) {
echo '<td>';
echo '<ul style="margin-bottom: 20px; max-height: 300px; overflow-y: auto;">';
foreach ($lists as $list) {
echo '<li><label>';
echo sprintf('<input type="checkbox" name="mc4wp_integrations[%s][lists][]" value="%s" class="mc4wp-list-input" %s> ', $integration->slug, $list->id, checked(in_array($list->id, $opts['lists']), true, false));
echo esc_html($list->name);
echo '</label></li>';
}
echo '</ul>';
echo '<p class="help">';
_e('Select the list(s) to which people who check the checkbox should be subscribed.', 'mailchimp-for-wp');
echo '</p>';
echo '</td>';
} else {
echo '<td>' . sprintf(__('No lists found, <a href="%s">are you connected to Mailchimp</a>?', 'mailchimp-for-wp'), admin_url('admin.php?page=mailchimp-for-wp')) . '</td>';
} ?>
</tr>
<?php
} // end if UI has lists?>
<?php if ($integration->has_ui_element('label')) {
$config = array( 'element' => 'mc4wp_integrations['. $integration->slug .'][implicit]', 'value' => 0 ); ?>
<tr valign="top" data-showif="<?php echo esc_attr(json_encode($config)); ?>">
<th scope="row"><label for="mc4wp_checkbox_label"><?php _e('Checkbox label text', 'mailchimp-for-wp'); ?></label></th>
<td>
<input type="text" class="widefat" id="mc4wp_checkbox_label" name="mc4wp_integrations[<?php echo $integration->slug; ?>][label]" value="<?php echo esc_attr($opts['label']); ?>" required />
<p class="help"><?php printf(__('HTML tags like %s are allowed in the label text.', 'mailchimp-for-wp'), '<code>' . esc_html('<strong><em><a>') . '</code>'); ?></p>
</td>
</tr>
<?php
} // end if UI label?>
<?php if ($integration->has_ui_element('precheck')) {
$config = array( 'element' => 'mc4wp_integrations['. $integration->slug .'][implicit]', 'value' => 0 ); ?>
<tr valign="top" data-showif="<?php echo esc_attr(json_encode($config)); ?>">
<th scope="row"><?php _e('Pre-check the checkbox?', 'mailchimp-for-wp'); ?></th>
<td class="nowrap">
<label><input type="radio" name="mc4wp_integrations[<?php echo $integration->slug; ?>][precheck]" value="1" <?php checked($opts['precheck'], 1); ?> /> <?php _e('Yes'); ?></label> &nbsp;
<label><input type="radio" name="mc4wp_integrations[<?php echo $integration->slug; ?>][precheck]" value="0" <?php checked($opts['precheck'], 0); ?> /> <?php _e('No'); ?> <?php echo '<em>' . __('(recommended)', 'mailchimp-for-wp') . '</em>'; ?></label>
<p class="help">
<?php _e('Select "yes" if the checkbox should be pre-checked.', 'mailchimp-for-wp');
echo '<br />';
printf(__('<strong>Warning: </strong> enabling this may affect your <a href="%s">GDPR compliance</a>.', 'mailchimp-for-wp'), 'https://kb.mc4wp.com/gdpr-compliance/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=integrations-page'); ?>
</p>
</td>
<?php
} // end if UI precheck?>
<?php if ($integration->has_ui_element('css')) {
$config = array( 'element' => 'mc4wp_integrations['. $integration->slug .'][implicit]', 'value' => 0 ); ?>
<tr valign="top" data-showif="<?php echo esc_attr(json_encode($config)); ?>">
<th scope="row"><?php _e('Load some default CSS?', 'mailchimp-for-wp'); ?></th>
<td class="nowrap">
<label><input type="radio" name="mc4wp_integrations[<?php echo $integration->slug; ?>][css]" value="1" <?php checked($opts['css'], 1); ?> />&rlm; <?php _e('Yes'); ?></label> &nbsp;
<label><input type="radio" name="mc4wp_integrations[<?php echo $integration->slug; ?>][css]" value="0" <?php checked($opts['css'], 0); ?> />&rlm; <?php _e('No'); ?></label>
<p class="help"><?php _e('Select "yes" if the checkbox appears in a weird place.', 'mailchimp-for-wp'); ?></p>
</td>
</tr>
<?php
} // end if UI css?>
<?php if ($integration->has_ui_element('double_optin')) {
?>
<tr valign="top">
<th scope="row"><?php _e('Double opt-in?', 'mailchimp-for-wp'); ?></th>
<td class="nowrap">
<label>
<input type="radio" name="mc4wp_integrations[<?php echo $integration->slug; ?>][double_optin]" value="1" <?php checked($opts['double_optin'], 1); ?> />&rlm;
<?php _e('Yes'); ?>
</label> &nbsp;
<label>
<input type="radio" id="mc4wp_checkbox_double_optin_0" name="mc4wp_integrations[<?php echo $integration->slug; ?>][double_optin]" value="0" <?php checked($opts['double_optin'], 0); ?> />&rlm;
<?php _e('No'); ?>
</label>
<p class="help">
<?php _e('Select "yes" if you want people to confirm their email address before being subscribed (recommended)', 'mailchimp-for-wp'); ?>
</p>
</td>
</tr>
<?php
} // end if UI double_optin?>
<?php if ($integration->has_ui_element('update_existing')) {
?>
<tr valign="top">
<th scope="row"><?php _e('Update existing subscribers?', 'mailchimp-for-wp'); ?></th>
<td class="nowrap">
<label>
<input type="radio" name="mc4wp_integrations[<?php echo $integration->slug; ?>][update_existing]" value="1" <?php checked($opts['update_existing'], 1); ?> />&rlm;
<?php _e('Yes'); ?>
</label> &nbsp;
<label>
<input type="radio" name="mc4wp_integrations[<?php echo $integration->slug; ?>][update_existing]" value="0" <?php checked($opts['update_existing'], 0); ?> />&rlm;
<?php _e('No'); ?>
</label>
<p class="help"><?php _e('Select "yes" if you want to update existing subscribers with the data that is sent.', 'mailchimp-for-wp'); ?></p>
</td>
</tr>
<?php
} // end if UI update_existing?>
<?php if ($integration->has_ui_element('replace_interests')) {
$config = array( 'element' => 'mc4wp_integrations['. $integration->slug .'][update_existing]', 'value' => 1 ); ?>
<tr valign="top" data-showif="<?php echo esc_attr(json_encode($config)); ?>">
<th scope="row"><?php _e('Replace interest groups?', 'mailchimp-for-wp'); ?></th>
<td class="nowrap">
<label>
<input type="radio" name="mc4wp_integrations[<?php echo $integration->slug; ?>][replace_interests]" value="1" <?php checked($opts['replace_interests'], 1); ?> />&rlm;
<?php _e('Yes'); ?>
</label> &nbsp;
<label>
<input type="radio" name="mc4wp_integrations[<?php echo $integration->slug; ?>][replace_interests]" value="0" <?php checked($opts['replace_interests'], 0); ?> />&rlm;
<?php _e('No'); ?>
</label>
<p class="help">
<?php _e('Select "no" if you want to add the selected interests to any previously selected interests when updating a subscriber.', 'mailchimp-for-wp'); ?>
<?php printf(' <a href="%s" target="_blank">' . __('What does this do?', 'mailchimp-for-wp') . '</a>', 'https://kb.mc4wp.com/what-does-replace-groupings-mean/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=integrations-page'); ?>
</p>
</td>
</tr>
<?php
} // end if UI replace_interests?>
</tbody>
</table>
<?php
/**
* Runs right after integration settings are outputted (before the submit button).
*
* @param MC4WP_Integration $integration
* @param array $opts
* @ignore
*/
do_action('mc4wp_admin_after_integration_settings', $integration, $opts);
/**
* @ignore
*/
do_action('mc4wp_admin_after_' . $integration->slug . '_integration_settings', $integration, $opts);
?>
<?php if (count($integration->get_ui_elements()) > 0) {
submit_button();
} ?>
</form>
</div>
<!-- Sidebar -->
<div class="sidebar col col-2">
<?php include MC4WP_PLUGIN_DIR . '/includes/views/parts/admin-sidebar.php'; ?>
</div>
</div>
</div>
@@ -0,0 +1,134 @@
<?php defined('ABSPATH') or exit;
/** @var MC4WP_Integration_Fixture[] $enabled_integrations */
/** @var MC4WP_Integration_Fixture[] $available_integrations */
/** @var MC4WP_Integration $integration */
function _mc4wp_integrations_table_row($integration) {
?>
<tr style="<?php if (! $integration->is_installed()) {
echo 'opacity: 0.4;';
} ?>">
<!-- Integration Name -->
<td>
<?php
if ($integration->is_installed()) {
printf('<strong><a href="%s" title="%s">%s</a></strong>', esc_attr(add_query_arg(array( 'integration' => $integration->slug ))), __('Configure this integration', 'mailchimp-for-wp'), $integration->name);
} else {
echo $integration->name;
} ?>
</td>
<td class="desc">
<?php
_e($integration->description, 'mailchimp-for-wp'); ?>
</td>
<td>
<?php
if ($integration->enabled && $integration->is_installed()) {
echo '<span class="green">' . __('Active', 'mailchimp-for-wp') . '</span>';
} elseif($integration->is_installed()) {
echo '<span class="neutral">' . __('Inactive', 'mailchimp-for-wp') . '</span>';
} else {
echo '<span class="red">' . __('Not installed', 'mailchimp-for-wp') . '</span>';
}
?>
</td>
</tr>
<?php
}
/**
* Render a table with integrations
*
* @param $integrations
* @ignore
*/
function _mc4wp_integrations_table($integrations)
{
?>
<table class="mc4wp-table widefat striped">
<thead>
<tr>
<th><?php _e('Name', 'mailchimp-for-wp'); ?></th>
<th><?php _e('Description', 'mailchimp-for-wp'); ?></th>
<th><?php _e('Status', 'mailchimp-for-wp'); ?></th>
</tr>
</thead>
<tbody>
<?php
// active & enabled integrations first
foreach ($integrations as $integration) {
if ( $integration->is_installed() && $integration->enabled) {
_mc4wp_integrations_table_row($integration);
}
}
// active & disabled integrations next
foreach ($integrations as $integration) {
if ( $integration->is_installed() && ! $integration->enabled) {
_mc4wp_integrations_table_row($integration);
}
}
// rest
foreach ($integrations as $integration) {
if (! $integration->is_installed()) {
_mc4wp_integrations_table_row($integration);
}
}
?>
</tbody>
</table><?php
}
?>
<div id="mc4wp-admin" class="wrap mc4wp-settings">
<p class="breadcrumbs">
<span class="prefix"><?php echo __('You are here: ', 'mailchimp-for-wp'); ?></span>
<a href="<?php echo admin_url('admin.php?page=mailchimp-for-wp'); ?>">Mailchimp for WordPress</a> &rsaquo;
<span class="current-crumb"><strong><?php _e('Integrations', 'mailchimp-for-wp'); ?></strong></span>
</p>
<div class="main-content row">
<!-- Main Content -->
<div class="col col-4">
<h1 class="page-title">Mailchimp for WordPress: <?php _e('Integrations', 'mailchimp-for-wp'); ?></h1>
<h2 style="display: none;"></h2>
<?php settings_errors(); ?>
<p>
<?php _e('The table below shows all available integrations.', 'mailchimp-for-wp'); ?>
<?php _e('Click on the name of an integration to edit all settings specific to that integration.', 'mailchimp-for-wp'); ?>
</p>
<form action="<?php echo admin_url('options.php'); ?>" method="post">
<?php settings_fields('mc4wp_integrations_settings'); ?>
<h3><?php _e('Integrations', 'mailchimp-for-wp'); ?></h3>
<?php _mc4wp_integrations_table($integrations); ?>
<p><?php echo __("Greyed out integrations will become available after installing & activating the corresponding plugin.", 'mailchimp-for-wp'); ?></p>
</form>
</div>
<!-- Sidebar -->
<div class="sidebar col col-2">
<?php include MC4WP_PLUGIN_DIR . '/includes/views/parts/admin-sidebar.php'; ?>
</div>
</div>
</div>