first commit
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
class MC4WP_Admin_Ajax {
|
||||
|
||||
|
||||
/**
|
||||
* @var MC4WP_Admin_Tools
|
||||
*/
|
||||
protected $tools;
|
||||
|
||||
/**
|
||||
* MC4WP_Admin_Ajax constructor.
|
||||
*
|
||||
* @param MC4WP_Admin_Tools $tools
|
||||
*/
|
||||
public function __construct( MC4WP_Admin_Tools $tools ) {
|
||||
$this->tools = $tools;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook AJAX actions
|
||||
*/
|
||||
public function add_hooks() {
|
||||
add_action( 'wp_ajax_mc4wp_renew_mailchimp_lists', array( $this, 'refresh_mailchimp_lists' ) );
|
||||
add_action( 'wp_ajax_mc4wp_get_list_details', array( $this, 'get_list_details' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty lists cache & fetch lists again.
|
||||
*/
|
||||
public function refresh_mailchimp_lists() {
|
||||
if ( ! $this->tools->is_user_authorized() ) {
|
||||
wp_send_json( false );
|
||||
}
|
||||
|
||||
$mailchimp = new MC4WP_MailChimp();
|
||||
$success = $mailchimp->refresh_lists();
|
||||
wp_send_json( $success );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve details (merge fields and interest categories) for one or multiple lists in Mailchimp
|
||||
* @throws MC4WP_API_Exception
|
||||
*/
|
||||
public function get_list_details() {
|
||||
$list_ids = (array) explode( ',', $_GET['ids'] );
|
||||
$data = array();
|
||||
$mailchimp = new MC4WP_MailChimp();
|
||||
foreach ( $list_ids as $list_id ) {
|
||||
$merge_fields = $mailchimp->get_list_merge_fields( $list_id );
|
||||
$interest_categories = $mailchimp->get_list_interest_categories( $list_id );
|
||||
$data[] = (object) array(
|
||||
'id' => $list_id,
|
||||
'merge_fields' => $merge_fields,
|
||||
'interest_categories' => $interest_categories,
|
||||
);
|
||||
}
|
||||
wp_send_json( $data );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class MC4WP_Admin_Messages
|
||||
*
|
||||
* @ignore
|
||||
* @since 3.0
|
||||
*/
|
||||
class MC4WP_Admin_Messages {
|
||||
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $bag;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $dirty = false;
|
||||
|
||||
/**
|
||||
* Add hooks
|
||||
*/
|
||||
public function add_hooks() {
|
||||
add_action( 'admin_notices', array( $this, 'show' ) );
|
||||
register_shutdown_function( array( $this, 'save' ) );
|
||||
}
|
||||
|
||||
private function load() {
|
||||
if ( is_null( $this->bag ) ) {
|
||||
$this->bag = get_option( 'mc4wp_flash_messages', array() );
|
||||
}
|
||||
}
|
||||
|
||||
// empty flash bag
|
||||
private function reset() {
|
||||
$this->bag = array();
|
||||
$this->dirty = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flash a message (shows on next pageload)
|
||||
*
|
||||
* @param $message
|
||||
* @param string $type
|
||||
*/
|
||||
public function flash( $message, $type = 'success' ) {
|
||||
$this->load();
|
||||
$this->bag[] = array(
|
||||
'text' => $message,
|
||||
'type' => $type,
|
||||
);
|
||||
$this->dirty = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Show queued flash messages
|
||||
*/
|
||||
public function show() {
|
||||
$this->load();
|
||||
|
||||
foreach ( $this->bag as $message ) {
|
||||
echo sprintf( '<div class="notice notice-%s is-dismissible"><p>%s</p></div>', $message['type'], $message['text'] );
|
||||
}
|
||||
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save queued messages
|
||||
*
|
||||
* @hooked `shutdown`
|
||||
*/
|
||||
public function save() {
|
||||
if ( $this->dirty ) {
|
||||
update_option( 'mc4wp_flash_messages', $this->bag, false );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class MC4WP_Admin_Texts
|
||||
*
|
||||
* @ignore
|
||||
* @since 3.0
|
||||
*/
|
||||
class MC4WP_Admin_Texts {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $plugin_file;
|
||||
|
||||
/**
|
||||
* @param string $plugin_file
|
||||
*/
|
||||
public function __construct( $plugin_file ) {
|
||||
$this->plugin_file = $plugin_file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add hooks
|
||||
*/
|
||||
public function add_hooks() {
|
||||
global $pagenow;
|
||||
|
||||
add_filter( 'admin_footer_text', array( $this, 'footer_text' ) );
|
||||
|
||||
// Hooks for Plugins overview page
|
||||
if ( $pagenow === 'plugins.php' ) {
|
||||
add_filter( 'plugin_action_links_' . $this->plugin_file, array( $this, 'add_plugin_settings_link' ), 10, 2 );
|
||||
add_filter( 'plugin_row_meta', array( $this, 'add_plugin_meta_links' ), 10, 2 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask for a plugin review in the WP Admin footer, if this is one of the plugin pages.
|
||||
*
|
||||
* @param $text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function footer_text( $text ) {
|
||||
if ( ! empty( $_GET['page'] ) && strpos( $_GET['page'], 'mailchimp-for-wp' ) === 0 ) {
|
||||
$text = sprintf( 'If you enjoy using <strong>Mailchimp for WordPress</strong>, please <a href="%s" target="_blank">leave us a ★★★★★ rating</a>. A <strong style="text-decoration: underline;">huge</strong> thank you in advance!', 'https://wordpress.org/support/view/plugin-reviews/mailchimp-for-wp?rate=5#postform' );
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the settings link to the Plugins overview
|
||||
*
|
||||
* @param array $links
|
||||
* @param $file
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_plugin_settings_link( $links, $file ) {
|
||||
if ( $file !== $this->plugin_file ) {
|
||||
return $links;
|
||||
}
|
||||
|
||||
$settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=mailchimp-for-wp' ), esc_html__( 'Settings', 'mailchimp-for-wp' ) );
|
||||
array_unshift( $links, $settings_link );
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds meta links to the plugin in the WP Admin > Plugins screen
|
||||
*
|
||||
* @param array $links
|
||||
* @param string $file
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_plugin_meta_links( $links, $file ) {
|
||||
if ( $file !== $this->plugin_file ) {
|
||||
return $links;
|
||||
}
|
||||
|
||||
$links[] = '<a href="https://www.mc4wp.com/kb/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=plugins-page">' . esc_html__( 'Documentation', 'mailchimp-for-wp' ) . '</a>';
|
||||
|
||||
/**
|
||||
* Filters meta links shown on the Plugins overview page
|
||||
*
|
||||
* This takes an array of strings
|
||||
*
|
||||
* @since 3.0
|
||||
* @param array $links
|
||||
* @ignore
|
||||
*/
|
||||
$links = (array) apply_filters( 'mc4wp_admin_plugin_meta_links', $links );
|
||||
|
||||
return $links;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
class MC4WP_Admin_Tools {
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_plugin_page() {
|
||||
if ( empty( $_GET['page'] ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$prefix = 'mailchimp-for-wp';
|
||||
$page = ltrim( substr( $_GET['page'], strlen( $prefix ) ), '-' );
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $page
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function on_plugin_page( $page = null ) {
|
||||
// any settings page
|
||||
if ( is_null( $page ) ) {
|
||||
return isset( $_GET['page'] ) && strpos( $_GET['page'], 'mailchimp-for-wp' ) === 0;
|
||||
}
|
||||
|
||||
// specific page
|
||||
return $this->get_plugin_page() === $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the logged-in user have the required capability?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_user_authorized() {
|
||||
return current_user_can( $this->get_required_capability() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get required capability to access settings page and view dashboard widgets.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_required_capability() {
|
||||
$capability = 'manage_options';
|
||||
|
||||
/**
|
||||
* Filters the required user capability to access the settings pages & dashboard widgets.
|
||||
*
|
||||
* @ignore
|
||||
* @deprecated 3.0
|
||||
*/
|
||||
$capability = apply_filters( 'mc4wp_settings_cap', $capability );
|
||||
|
||||
/**
|
||||
* Filters the required user capability to access the Mailchimp for WordPress' settings pages, view the dashboard widgets.
|
||||
*
|
||||
* Defaults to `manage_options`
|
||||
*
|
||||
* @since 3.0
|
||||
* @param string $capability
|
||||
* @see https://codex.wordpress.org/Roles_and_Capabilities
|
||||
*/
|
||||
$capability = (string) apply_filters( 'mc4wp_admin_required_capability', $capability );
|
||||
|
||||
return $capability;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,525 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class MC4WP_Admin
|
||||
*
|
||||
* @ignore
|
||||
* @access private
|
||||
*/
|
||||
class MC4WP_Admin {
|
||||
|
||||
|
||||
/**
|
||||
* @var string The relative path to the main plugin file from the plugins dir
|
||||
*/
|
||||
protected $plugin_file;
|
||||
|
||||
/**
|
||||
* @var MC4WP_Admin_Messages
|
||||
*/
|
||||
protected $messages;
|
||||
|
||||
/**
|
||||
* @var MC4WP_Admin_Ads
|
||||
*/
|
||||
protected $ads;
|
||||
|
||||
/**
|
||||
* @var MC4WP_Admin_Tools
|
||||
*/
|
||||
protected $tools;
|
||||
|
||||
/**
|
||||
* @var MC4WP_Admin_Review_Notice
|
||||
*/
|
||||
protected $review_notice;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param MC4WP_Admin_Tools $tools
|
||||
* @param MC4WP_Admin_Messages $messages
|
||||
*/
|
||||
public function __construct( MC4WP_Admin_Tools $tools, MC4WP_Admin_Messages $messages ) {
|
||||
$this->tools = $tools;
|
||||
$this->messages = $messages;
|
||||
$this->plugin_file = plugin_basename( MC4WP_PLUGIN_FILE );
|
||||
$this->ads = new MC4WP_Admin_Ads();
|
||||
$this->review_notice = new MC4WP_Admin_Review_Notice( $tools );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all hooks
|
||||
*/
|
||||
public function add_hooks() {
|
||||
|
||||
// Actions used globally throughout WP Admin
|
||||
add_action( 'admin_menu', array( $this, 'build_menu' ) );
|
||||
add_action( 'admin_init', array( $this, 'initialize' ) );
|
||||
|
||||
add_action( 'current_screen', array( $this, 'customize_admin_texts' ) );
|
||||
add_action( 'wp_dashboard_setup', array( $this, 'register_dashboard_widgets' ) );
|
||||
add_action( 'mc4wp_admin_empty_lists_cache', array( $this, 'renew_lists_cache' ) );
|
||||
add_action( 'mc4wp_admin_empty_debug_log', array( $this, 'empty_debug_log' ) );
|
||||
|
||||
add_action( 'admin_notices', array( $this, 'show_api_key_notice' ) );
|
||||
add_action( 'mc4wp_admin_dismiss_api_key_notice', array( $this, 'dismiss_api_key_notice' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
|
||||
|
||||
$this->ads->add_hooks();
|
||||
$this->messages->add_hooks();
|
||||
$this->review_notice->add_hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes various stuff used in WP Admin
|
||||
*
|
||||
* - Registers settings
|
||||
*/
|
||||
public function initialize() {
|
||||
|
||||
// register settings
|
||||
register_setting( 'mc4wp_settings', 'mc4wp', array( $this, 'save_general_settings' ) );
|
||||
|
||||
// Load upgrader
|
||||
$this->init_upgrade_routines();
|
||||
|
||||
// listen for custom actions
|
||||
$this->listen_for_actions();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Listen for `_mc4wp_action` requests
|
||||
*/
|
||||
public function listen_for_actions() {
|
||||
|
||||
// listen for any action (if user is authorised)
|
||||
if ( ! $this->tools->is_user_authorized() || ! isset( $_REQUEST['_mc4wp_action'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$action = (string) $_REQUEST['_mc4wp_action'];
|
||||
|
||||
/**
|
||||
* Allows you to hook into requests containing `_mc4wp_action` => action name.
|
||||
*
|
||||
* The dynamic portion of the hook name, `$action`, refers to the action name.
|
||||
*
|
||||
* By the time this hook is fired, the user is already authorized. After processing all the registered hooks,
|
||||
* the request is redirected back to the referring URL.
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
do_action( 'mc4wp_admin_' . $action );
|
||||
|
||||
// redirect back to where we came from (to prevent double submit)
|
||||
if ( isset( $_POST['_redirect_to'] ) ) {
|
||||
$redirect_url = $_POST['_redirect_to'];
|
||||
} elseif ( isset( $_GET['_redirect_to'] ) ) {
|
||||
$redirect_url = $_GET['_redirect_to'];
|
||||
} else {
|
||||
$redirect_url = remove_query_arg( '_mc4wp_action' );
|
||||
}
|
||||
wp_redirect( $redirect_url );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register dashboard widgets
|
||||
*/
|
||||
public function register_dashboard_widgets() {
|
||||
if ( ! $this->tools->is_user_authorized() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup dashboard widget, users are authorized by now.
|
||||
*
|
||||
* Use this hook to register your own dashboard widgets for users with the required capability.
|
||||
*
|
||||
* @since 3.0
|
||||
* @ignore
|
||||
*/
|
||||
do_action( 'mc4wp_dashboard_setup' );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade routine
|
||||
*/
|
||||
private function init_upgrade_routines() {
|
||||
|
||||
// upgrade routine for upgrade routine....
|
||||
$previous_version = get_option( 'mc4wp_lite_version', 0 );
|
||||
if ( $previous_version ) {
|
||||
delete_option( 'mc4wp_lite_version' );
|
||||
update_option( 'mc4wp_version', $previous_version );
|
||||
}
|
||||
|
||||
$previous_version = get_option( 'mc4wp_version', 0 );
|
||||
|
||||
// allow setting migration version from URL, to easily re-run previous migrations.
|
||||
if ( isset( $_GET['mc4wp_run_migration'] ) ) {
|
||||
$previous_version = $_GET['mc4wp_run_migration'];
|
||||
}
|
||||
|
||||
// Ran upgrade routines before?
|
||||
if ( empty( $previous_version ) ) {
|
||||
update_option( 'mc4wp_version', MC4WP_VERSION );
|
||||
|
||||
// if we have at least one form, we're going to run upgrade routine for v3 => v4 anyway.
|
||||
$posts = get_posts(
|
||||
array(
|
||||
'post_type' => 'mc4wp-form',
|
||||
'posts_per_page' => 1,
|
||||
)
|
||||
);
|
||||
if ( empty( $posts ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$previous_version = '3.9';
|
||||
}
|
||||
|
||||
// Rollback'ed?
|
||||
if ( version_compare( $previous_version, MC4WP_VERSION, '>' ) ) {
|
||||
update_option( 'mc4wp_version', MC4WP_VERSION );
|
||||
return false;
|
||||
}
|
||||
|
||||
// This means we're good!
|
||||
if ( version_compare( $previous_version, MC4WP_VERSION ) > -1 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
define( 'MC4WP_DOING_UPGRADE', true );
|
||||
$upgrade_routines = new MC4WP_Upgrade_Routines( $previous_version, MC4WP_VERSION, __DIR__ . '/migrations' );
|
||||
$upgrade_routines->run();
|
||||
update_option( 'mc4wp_version', MC4WP_VERSION );
|
||||
}
|
||||
|
||||
/**
|
||||
* Renew Mailchimp lists cache
|
||||
*/
|
||||
public function renew_lists_cache() {
|
||||
// try getting new lists to fill cache again
|
||||
$mailchimp = new MC4WP_MailChimp();
|
||||
$lists = $mailchimp->refresh_lists();
|
||||
|
||||
if ( ! empty( $lists ) ) {
|
||||
$this->messages->flash( esc_html__( 'Success! The cached configuration for your Mailchimp lists has been renewed.', 'mailchimp-for-wp' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Customize texts throughout WP Admin
|
||||
*/
|
||||
public function customize_admin_texts() {
|
||||
$texts = new MC4WP_Admin_Texts( $this->plugin_file );
|
||||
$texts->add_hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the General settings
|
||||
* @param array $settings
|
||||
* @return array
|
||||
*/
|
||||
public function save_general_settings( array $settings ) {
|
||||
$current = mc4wp_get_options();
|
||||
|
||||
// merge with current settings to allow passing partial arrays to this method
|
||||
$settings = array_merge( $current, $settings );
|
||||
|
||||
// toggle usage tracking
|
||||
if ( $settings['allow_usage_tracking'] !== $current['allow_usage_tracking'] ) {
|
||||
MC4WP_Usage_Tracking::instance()->toggle( $settings['allow_usage_tracking'] );
|
||||
}
|
||||
|
||||
// Make sure not to use obfuscated key
|
||||
if ( strpos( $settings['api_key'], '*' ) !== false ) {
|
||||
$settings['api_key'] = $current['api_key'];
|
||||
}
|
||||
|
||||
// Sanitize API key
|
||||
$settings['api_key'] = sanitize_text_field( $settings['api_key'] );
|
||||
|
||||
// if API key changed, empty Mailchimp cache
|
||||
if ( $settings['api_key'] !== $current['api_key'] ) {
|
||||
delete_transient( 'mc4wp_mailchimp_lists' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs right before general settings are saved.
|
||||
*
|
||||
* @param array $settings The updated settings array
|
||||
* @param array $current The old settings array
|
||||
*/
|
||||
do_action( 'mc4wp_save_settings', $settings, $current );
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load scripts and stylesheet on Mailchimp for WP Admin pages
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function enqueue_assets() {
|
||||
global $wp_scripts;
|
||||
|
||||
if ( ! $this->tools->on_plugin_page() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$opts = mc4wp_get_options();
|
||||
$page = $this->tools->get_plugin_page();
|
||||
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
|
||||
$mailchimp = new MC4WP_MailChimp();
|
||||
|
||||
// css
|
||||
wp_register_style( 'mc4wp-admin', mc4wp_plugin_url( 'assets/css/admin-styles' . $suffix . '.css' ), array(), MC4WP_VERSION );
|
||||
wp_enqueue_style( 'mc4wp-admin' );
|
||||
|
||||
// js
|
||||
wp_register_script( 'mc4wp-admin', mc4wp_plugin_url( 'assets/js/admin' . $suffix . '.js' ), array(), MC4WP_VERSION, true );
|
||||
wp_enqueue_script( 'mc4wp-admin' );
|
||||
$connected = ! empty( $opts['api_key'] );
|
||||
$mailchimp_lists = $connected ? $mailchimp->get_lists() : array();
|
||||
wp_localize_script(
|
||||
'mc4wp-admin',
|
||||
'mc4wp_vars',
|
||||
array(
|
||||
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
||||
'mailchimp' => array(
|
||||
'api_connected' => $connected,
|
||||
'lists' => $mailchimp_lists,
|
||||
),
|
||||
'countries' => MC4WP_Tools::get_countries(),
|
||||
'i18n' => array(
|
||||
'invalid_api_key' => __( 'The given value does not look like a valid Mailchimp API key.', 'mailchimp-for-wp' ),
|
||||
'pro_only' => __( 'This is a premium feature. Please upgrade to Mailchimp for WordPress Premium to be able to use it.', 'mailchimp-for-wp' ),
|
||||
'renew_mailchimp_lists' => __( 'Renew Mailchimp lists', 'mailchimp-for-wp' ),
|
||||
'fetching_mailchimp_lists' => __( 'Fetching Mailchimp lists', 'mailchimp-for-wp' ),
|
||||
'fetching_mailchimp_lists_done' => __( 'Done! Mailchimp lists renewed.', 'mailchimp-for-wp' ),
|
||||
'fetching_mailchimp_lists_error' => __( 'Failed to renew your lists. An error occured.', 'mailchimp-for-wp' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Hook to enqueue your own custom assets on the Mailchimp for WordPress setting pages.
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
* @param string $suffix
|
||||
* @param string $page
|
||||
*/
|
||||
do_action( 'mc4wp_admin_enqueue_assets', $suffix, $page );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Register the setting pages and their menu items
|
||||
*/
|
||||
public function build_menu() {
|
||||
$required_cap = $this->tools->get_required_capability();
|
||||
|
||||
$menu_items = array(
|
||||
array(
|
||||
'title' => esc_html__( 'Mailchimp API Settings', 'mailchimp-for-wp' ),
|
||||
'text' => 'Mailchimp',
|
||||
'slug' => '',
|
||||
'callback' => array( $this, 'show_generals_setting_page' ),
|
||||
'position' => 0,
|
||||
),
|
||||
array(
|
||||
'title' => esc_html__( 'Other Settings', 'mailchimp-for-wp' ),
|
||||
'text' => esc_html__( 'Other', 'mailchimp-for-wp' ),
|
||||
'slug' => 'other',
|
||||
'callback' => array( $this, 'show_other_setting_page' ),
|
||||
'position' => 90,
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters the menu items to appear under the main menu item.
|
||||
*
|
||||
* To add your own item, add an associative array in the following format.
|
||||
*
|
||||
* $menu_items[] = array(
|
||||
* 'title' => 'Page title',
|
||||
* 'text' => 'Menu text',
|
||||
* 'slug' => 'Page slug',
|
||||
* 'callback' => 'my_page_function',
|
||||
* 'position' => 50
|
||||
* );
|
||||
*
|
||||
* @param array $menu_items
|
||||
* @since 3.0
|
||||
*/
|
||||
$menu_items = (array) apply_filters( 'mc4wp_admin_menu_items', $menu_items );
|
||||
|
||||
// add top menu item
|
||||
$icon = file_get_contents( MC4WP_PLUGIN_DIR . 'assets/img/icon.svg' );
|
||||
add_menu_page( 'Mailchimp for WP', 'MC4WP', $required_cap, 'mailchimp-for-wp', array( $this, 'show_generals_setting_page' ), 'data:image/svg+xml;base64,' . base64_encode( $icon ), '99.68491' );
|
||||
|
||||
// sort submenu items by 'position'
|
||||
usort( $menu_items, array( $this, 'sort_menu_items_by_position' ) );
|
||||
|
||||
// add sub-menu items
|
||||
foreach ( $menu_items as $item ) {
|
||||
$this->add_menu_item( $item );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $item
|
||||
*/
|
||||
public function add_menu_item( array $item ) {
|
||||
|
||||
// generate menu slug
|
||||
$slug = 'mailchimp-for-wp';
|
||||
if ( ! empty( $item['slug'] ) ) {
|
||||
$slug .= '-' . $item['slug'];
|
||||
}
|
||||
|
||||
// provide some defaults
|
||||
$parent_slug = ! empty( $item['parent_slug'] ) ? $item['parent_slug'] : 'mailchimp-for-wp';
|
||||
$capability = ! empty( $item['capability'] ) ? $item['capability'] : $this->tools->get_required_capability();
|
||||
|
||||
// register page
|
||||
$hook = add_submenu_page( $parent_slug, $item['title'] . ' - Mailchimp for WordPress', $item['text'], $capability, $slug, $item['callback'] );
|
||||
|
||||
// register callback for loading this page, if given
|
||||
if ( array_key_exists( 'load_callback', $item ) ) {
|
||||
add_action( 'load-' . $hook, $item['load_callback'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the API Settings page
|
||||
*/
|
||||
public function show_generals_setting_page() {
|
||||
$opts = mc4wp_get_options();
|
||||
$api_key = mc4wp_get_api_key();
|
||||
$lists = array();
|
||||
$connected = ! empty( $api_key );
|
||||
|
||||
if ( $connected ) {
|
||||
try {
|
||||
$connected = $this->get_api()->is_connected();
|
||||
$mailchimp = new MC4WP_MailChimp();
|
||||
$lists = $mailchimp->get_lists();
|
||||
} catch ( MC4WP_API_Connection_Exception $e ) {
|
||||
$message = sprintf( '<strong>%s</strong> %s %s ', esc_html__( 'Error connecting to Mailchimp:', 'mailchimp-for-wp' ), $e->getCode(), $e->getMessage() );
|
||||
|
||||
if ( is_object( $e->data ) && ! empty( $e->data->ref_no ) ) {
|
||||
$message .= '<br />' . sprintf( esc_html__( 'Looks like your server is blocked by Mailchimp\'s firewall. Please contact Mailchimp support and include the following reference number: %s', 'mailchimp-for-wp' ), $e->data->ref_no );
|
||||
}
|
||||
|
||||
$message .= '<br /><br />' . sprintf( '<a href="%s">' . esc_html__( 'Here\'s some info on solving common connectivity issues.', 'mailchimp-for-wp' ) . '</a>', 'https://www.mc4wp.com/kb/solving-connectivity-issues/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=settings-notice' );
|
||||
|
||||
$this->messages->flash( $message, 'error' );
|
||||
$connected = false;
|
||||
} catch ( MC4WP_API_Exception $e ) {
|
||||
$message = sprintf( '<strong>%s</strong><br /> %s', esc_html__( 'Mailchimp returned the following error:', 'mailchimp-for-wp' ), nl2br( (string) $e ) );
|
||||
$this->messages->flash( $message, 'error' );
|
||||
$connected = false;
|
||||
}
|
||||
}
|
||||
|
||||
$obfuscated_api_key = mc4wp_obfuscate_string( $api_key );
|
||||
require MC4WP_PLUGIN_DIR . 'includes/views/general-settings.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $a
|
||||
* @param $b
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function sort_menu_items_by_position( $a, $b ) {
|
||||
$pos_a = isset( $a['position'] ) ? $a['position'] : 80;
|
||||
$pos_b = isset( $b['position'] ) ? $b['position'] : 90;
|
||||
return $pos_a < $pos_b ? -1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empties the log file
|
||||
*/
|
||||
public function empty_debug_log() {
|
||||
$log = $this->get_log();
|
||||
file_put_contents( $log->file, '' );
|
||||
|
||||
$this->messages->flash( esc_html__( 'Log successfully emptied.', 'mailchimp-for-wp' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
$api_key = mc4wp_get_api_key();
|
||||
if ( ! empty( $api_key ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<div class="notice notice-warning mc4wp-is-dismissible">';
|
||||
echo '<p>', sprintf( wp_kses( __( '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' ), array( 'a' => array( 'href' => array() ) ) ), 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>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Dismisses the API key notice for 1 week
|
||||
*/
|
||||
public function dismiss_api_key_notice() {
|
||||
set_transient( 'mc4wp_api_key_notice_dismissed', 1, 3600 * 24 * 7 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MC4WP_Debug_Log
|
||||
*/
|
||||
protected function get_log() {
|
||||
return mc4wp( 'log' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MC4WP_API_V3
|
||||
*/
|
||||
protected function get_api() {
|
||||
return mc4wp( 'api' );
|
||||
}
|
||||
}
|
||||
174
wp-content/plugins/mailchimp-for-wp/includes/admin/class-ads.php
Normal file
174
wp-content/plugins/mailchimp-for-wp/includes/admin/class-ads.php
Normal file
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class MC4WP_Admin_Ads
|
||||
*
|
||||
* @ignore
|
||||
* @access private
|
||||
*/
|
||||
class MC4WP_Admin_Ads {
|
||||
|
||||
|
||||
/**
|
||||
* @return bool Adds hooks
|
||||
*/
|
||||
public function add_hooks() {
|
||||
|
||||
// don't hook if Premium is activated
|
||||
if ( defined( 'MC4WP_PREMIUM_VERSION' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
add_filter( 'mc4wp_admin_plugin_meta_links', array( $this, 'plugin_meta_links' ) );
|
||||
add_action( 'mc4wp_admin_form_after_behaviour_settings_rows', array( $this, 'after_form_settings_rows' ) );
|
||||
add_action( 'mc4wp_admin_form_after_appearance_settings_rows', array( $this, 'after_form_appearance_settings_rows' ) );
|
||||
add_action( 'mc4wp_admin_sidebar', array( $this, 'admin_sidebar' ) );
|
||||
add_action( 'mc4wp_admin_footer', array( $this, 'admin_footer' ) );
|
||||
add_action( 'mc4wp_admin_other_settings', array( $this, 'ecommerce' ), 90 );
|
||||
|
||||
add_filter( 'mc4wp_admin_menu_items', array( $this, 'add_menu_item' ) );
|
||||
|
||||
add_action( 'mc4wp_admin_after_woocommerce_integration_settings', array( $this, 'ecommerce' ) );
|
||||
return true;
|
||||
}
|
||||
|
||||
public function add_menu_item( $items ) {
|
||||
$items['extensions'] = array(
|
||||
'title' => __( 'Add-ons', 'mailchimp-for-wp' ),
|
||||
'text' => __( 'Add-ons', 'mailchimp-for-wp' ),
|
||||
'slug' => 'extensions',
|
||||
'callback' => array( $this, 'show_extensions_page' ),
|
||||
'position' => 100,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text row to "Form > Appearance" tab.
|
||||
*/
|
||||
public function after_form_appearance_settings_rows() {
|
||||
echo '<tr valign="top">';
|
||||
echo '<td colspan="2">';
|
||||
echo '<p class="help">';
|
||||
echo sprintf( __( 'Want to customize the style of your form? <a href="%s">Try our Styles Builder</a> & edit the look of your forms with just a few clicks.', 'mailchimp-for-wp' ), 'https://www.mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=form-settings-link' );
|
||||
echo '</p>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text row to "Form > Settings" tab.
|
||||
*/
|
||||
public function after_form_settings_rows() {
|
||||
echo '<tr valign="top">';
|
||||
echo '<td colspan="2">';
|
||||
echo '<p class="help">';
|
||||
|
||||
if ( rand( 1, 2 ) === 1 ) {
|
||||
echo sprintf( __( 'Be notified whenever someone subscribes? <a href="%s">Mailchimp for WordPress Premium</a> allows you to set up email notifications for your forms.', 'mailchimp-for-wp' ), 'https://www.mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=footer-link' );
|
||||
} else {
|
||||
echo sprintf( __( 'Increased conversions? <a href="%s">Mailchimp for WordPress Premium</a> submits forms without reloading the entire page, resulting in a much better experience for your visitors.', 'mailchimp-for-wp' ), 'https://www.mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=form-settings-link' );
|
||||
}
|
||||
|
||||
echo '</p>';
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $links
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function plugin_meta_links( $links ) {
|
||||
$links[] = '<a href="https://www.mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=plugins-upgrade-link">' . __( 'Upgrade to Premium', 'mailchimp-for-wp' ) . '</a>';
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add several texts to admin footer.
|
||||
*/
|
||||
public function admin_footer() {
|
||||
if ( isset( $_GET['view'] ) && $_GET['view'] === 'edit-form' ) {
|
||||
|
||||
// WPML & Polylang specific message
|
||||
if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
|
||||
echo '<p class="help">' . sprintf( __( 'Do you want translated forms for all of your languages? <a href="%s">Try Mailchimp for WordPress Premium</a>, which does just that plus more.', 'mailchimp-for-wp' ), 'https://www.mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=footer-link' ) . '</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
// General "edit form" message
|
||||
echo '<p class="help">' . sprintf( __( 'Do you want to create more than one form? Our Premium add-on does just that! <a href="%s">Have a look at all Premium benefits</a>.', 'mailchimp-for-wp' ), 'https://www.mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=footer-link' ) . '</p>';
|
||||
return;
|
||||
}
|
||||
|
||||
// General message
|
||||
echo '<p class="help">' . sprintf( __( 'Are you enjoying this plugin? The Premium add-on unlocks several powerful features. <a href="%s">Find out about all benefits now</a>.', 'mailchimp-for-wp' ), 'https://www.mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=footer-link' ) . '</p>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add email opt-in form to sidebar
|
||||
*/
|
||||
public function admin_sidebar() {
|
||||
echo '<div class="mc4wp-box">';
|
||||
echo '<div style="border: 5px dotted #cc4444; padding: 0 20px; background: white;">';
|
||||
echo '<h3>Mailchimp for WordPress Premium</h3>';
|
||||
echo '<p>This plugin has a Premium add-on, unlocking several powerful features. <a href="https://www.mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=upgrade-box">Have a look at its benefits</a>!</p>';
|
||||
echo '</div>';
|
||||
echo '</div>'; ?>
|
||||
<div class="mc4wp-box" id="mc4wp-optin-box">
|
||||
|
||||
<?php $user = wp_get_current_user(); ?>
|
||||
<!-- Begin Mailchimp Signup Form -->
|
||||
<div id="mc_embed_signup">
|
||||
<h4 class="mc4wp-title"><?php _e( 'More subscribers, better newsletters.', 'mailchimp-for-wp' ); ?></h4>
|
||||
<p><?php _e( 'Learn how to best grow your lists & write better emails by subscribing to our monthly tips.', 'mailchimp-for-wp' ); ?></p>
|
||||
<form action="//mc4wp.us1.list-manage.com/subscribe/post?u=a2d08947dcd3683512ce174c5&id=a940232df9" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" target="_blank">
|
||||
<p>
|
||||
<label for="mc4wp-email"><?php _e( 'Email Address', 'mailchimp-for-wp' ); ?></label>
|
||||
<input type="email" value="<?php echo esc_attr( $user->user_email ); ?>" name="EMAIL" class="regular-text" id="mc4wp-email" required>
|
||||
</p>
|
||||
<p>
|
||||
<label for="mc4wp-fname"><?php _e( 'First Name', 'mailchimp-for-wp' ); ?></label>
|
||||
<input type="text" value="<?php echo esc_attr( $user->user_firstname ); ?>" name="FNAME" class="regular-text" id="mc4wp-fname">
|
||||
</p>
|
||||
<div style="position: absolute; left: -5000px;">
|
||||
<input type="text" name="b_a2d08947dcd3683512ce174c5_a940232df9" tabindex="-1" value="" autocomplete="off" />
|
||||
</div>
|
||||
<p>
|
||||
<input type="submit" value="<?php esc_attr_e( 'Subscribe', 'mailchimp-for-wp' ); ?>" name="subscribe" class="button">
|
||||
</p>
|
||||
|
||||
<input type="hidden" name="SOURCE" value="free-plugin" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Show notice about E-Commerce integration in Premium.
|
||||
*/
|
||||
public function ecommerce() {
|
||||
|
||||
// detect whether WooCommerce is installed & activated.
|
||||
if ( ! class_exists( 'WooCommerce' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<div class="medium-margin">';
|
||||
echo '<h3>Advanced WooCommerce integration for Mailchimp</h3>';
|
||||
echo '<p>';
|
||||
echo __( 'Do you want to track all WooCommerce orders in Mailchimp so you can send emails based on the purchase activity of your subscribers?', 'mailchimp-for-wp' );
|
||||
echo '</p>';
|
||||
echo '<p>';
|
||||
echo sprintf( __( '<a href="%1$s">Upgrade to Mailchimp for WordPress Premium</a> or <a href="%2$s">read more about Mailchimp\'s E-Commerce features</a>.', 'mailchimp-for-wp' ) . '</p>', 'https://www.mc4wp.com/premium-features/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=other-settings-link', 'https://www.mc4wp.com/kb/what-is-ecommerce360/#utm_source=wp-plugin&utm_medium=mailchimp-for-wp&utm_campaign=other-settings-link' );
|
||||
echo '</p>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
public function show_extensions_page() {
|
||||
require MC4WP_PLUGIN_DIR . 'includes/views/extensions.php';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class MC4WP_Admin_Review_Notice
|
||||
*
|
||||
* @ignore
|
||||
*/
|
||||
class MC4WP_Admin_Review_Notice {
|
||||
|
||||
|
||||
/**
|
||||
* @var MC4WP_Admin_Tools
|
||||
*/
|
||||
protected $tools;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $meta_key_dismissed = '_mc4wp_review_notice_dismissed';
|
||||
|
||||
/**
|
||||
* MC4WP_Admin_Review_Notice constructor.
|
||||
*
|
||||
* @param MC4WP_Admin_Tools $tools
|
||||
*/
|
||||
public function __construct( MC4WP_Admin_Tools $tools ) {
|
||||
$this->tools = $tools;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add action & filter hooks.
|
||||
*/
|
||||
public function add_hooks() {
|
||||
add_action( 'admin_notices', array( $this, 'show' ) );
|
||||
add_action( 'mc4wp_admin_dismiss_review_notice', array( $this, 'dismiss' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set flag in user meta so notice won't be shown.
|
||||
*/
|
||||
public function dismiss() {
|
||||
$user = wp_get_current_user();
|
||||
update_user_meta( $user->ID, $this->meta_key_dismissed, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function show() {
|
||||
// only show on Mailchimp for WordPress' pages.
|
||||
if ( ! $this->tools->on_plugin_page() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// only show if 2 weeks have passed since first use.
|
||||
$two_weeks_in_seconds = ( 60 * 60 * 24 * 14 );
|
||||
if ( $this->time_since_first_use() <= $two_weeks_in_seconds ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// only show if user did not dismiss before
|
||||
$user = wp_get_current_user();
|
||||
if ( get_user_meta( $user->ID, $this->meta_key_dismissed, true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
echo '<div class="notice notice-info mc4wp-is-dismissible" id="mc4wp-review-notice">';
|
||||
echo '<p>';
|
||||
echo esc_html__( 'You\'ve been using Mailchimp for WordPress for some time now; we hope you love it!', 'mailchimp-for-wp' ), ' <br />';
|
||||
echo sprintf( wp_kses( __( 'If you do, please <a href="%s">leave us a 5★ rating on WordPress.org</a>. It would be of great help to us.', 'mailchimp-for-wp' ), array( 'a' => array( 'href' => array() ) ) ), 'https://wordpress.org/support/view/plugin-reviews/mailchimp-for-wp?rate=5#new-post' );
|
||||
echo '</p>';
|
||||
echo '<form method="POST" id="mc4wp-dismiss-review-form"><button type="submit" class="notice-dismiss"><span class="screen-reader-text">', esc_html__( 'Dismiss this notice.', 'mailchimp-for-wp' ), '</span></button><input type="hidden" name="_mc4wp_action" value="dismiss_review_notice"/></form>';
|
||||
echo '</div>';
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
private function time_since_first_use() {
|
||||
$options = get_option( 'mc4wp' );
|
||||
|
||||
// option was never added before, do it now.
|
||||
if ( empty( $options['first_activated_on'] ) ) {
|
||||
$options['first_activated_on'] = time();
|
||||
update_option( 'mc4wp', $options );
|
||||
}
|
||||
|
||||
return time() - $options['first_activated_on'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
class MC4WP_Update_Optin {
|
||||
|
||||
|
||||
/**
|
||||
* @const string
|
||||
*/
|
||||
const CAPABILITY = 'install_plugins';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $plugin_file = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $to_version;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $view_file;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $option_enable;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $option_notice;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $active = false;
|
||||
|
||||
/**
|
||||
* @param string $to_version
|
||||
* @param string $plugin_file
|
||||
* @param string $view_file
|
||||
*/
|
||||
public function __construct( $to_version, $plugin_file, $view_file ) {
|
||||
$this->to_version = $to_version;
|
||||
$this->plugin_file = $plugin_file;
|
||||
$this->view_file = $view_file;
|
||||
|
||||
$this->option_enable = 'mc4wp_enable_' . sanitize_key( $this->to_version );
|
||||
$this->option_notice = 'mc4wp_notice_' . sanitize_key( $this->to_version );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add hooks
|
||||
*/
|
||||
public function add_hooks() {
|
||||
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'maybe_hide_update' ) );
|
||||
add_action( 'init', array( $this, 'listen' ) );
|
||||
|
||||
global $pagenow;
|
||||
$on_settings_page = isset( $_GET['page'] ) && stristr( $_GET['page'], dirname( $this->plugin_file ) ) !== false;
|
||||
if ( $pagenow === 'plugins.php' || $pagenow === 'update-core.php' || $on_settings_page ) {
|
||||
add_action( 'admin_notices', array( $this, 'show_update_optin' ) );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Listen for actions
|
||||
*/
|
||||
public function listen() {
|
||||
|
||||
// only show to users with required capability
|
||||
if ( ! current_user_can( self::CAPABILITY ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $_GET[ $this->option_enable ] ) ) {
|
||||
$this->enable_major_updates();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Prevents updates from showing
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function maybe_hide_update( $data ) {
|
||||
if ( empty( $data->response ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
// do nothing if the specified version is not out there yet..
|
||||
if ( empty( $data->response[ $this->plugin_file ]->new_version )
|
||||
|| version_compare( $data->response[ $this->plugin_file ]->new_version, $this->to_version, '<' ) ) {
|
||||
|
||||
// reset flags here in case we revert the update
|
||||
if ( ! $this->active ) {
|
||||
delete_option( $this->option_notice );
|
||||
delete_option( $this->option_enable );
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// return unmodified data if already opted-in
|
||||
$opted_in = get_option( $this->option_enable, false );
|
||||
if ( $opted_in ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
// set a flag to start showing "update to x.x" notice
|
||||
update_option( $this->option_notice, 1 );
|
||||
|
||||
// unset update data
|
||||
unset( $data->response[ $this->plugin_file ] );
|
||||
|
||||
// set flag because this filter runs multiple times..
|
||||
$this->active = true;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables major updates (opts-in to 3.x update)
|
||||
*/
|
||||
public function enable_major_updates() {
|
||||
|
||||
// update option
|
||||
update_option( $this->option_enable, 1 );
|
||||
|
||||
// delete site transient so wp core will fetch latest version
|
||||
delete_site_transient( 'update_plugins' );
|
||||
|
||||
// redirect to updates page
|
||||
wp_safe_redirect( admin_url( 'update-core.php' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows update opt-in
|
||||
*/
|
||||
public function show_update_optin() {
|
||||
if ( ! $this->should_show_update_optin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// prepare link URL
|
||||
$update_link = add_query_arg( array( $this->option_enable => 1 ) );
|
||||
|
||||
// show!
|
||||
include $this->view_file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function should_show_update_optin() {
|
||||
|
||||
// don't show if flag is not set
|
||||
if ( ! get_option( $this->option_notice, false ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// stop showing if opted-in already
|
||||
if ( get_option( $this->option_enable, false ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// only show to users with required capability
|
||||
if ( ! current_user_can( self::CAPABILITY ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class MC4WP_DB_Upgrader
|
||||
*
|
||||
* This class takes care of loading migration files from the specified migrations directory.
|
||||
* Migration files should only use default WP functions and NOT use code which might not be there in the future.
|
||||
*
|
||||
* @ignore
|
||||
*/
|
||||
class MC4WP_Upgrade_Routines {
|
||||
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
protected $version_from = 0;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
protected $version_to = 0;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $migrations_dir = '';
|
||||
|
||||
/**
|
||||
* @param float $from
|
||||
* @param float $to
|
||||
*/
|
||||
public function __construct( $from, $to, $migrations_dir ) {
|
||||
$this->version_from = $from;
|
||||
$this->version_to = $to;
|
||||
$this->migrations_dir = $migrations_dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the various upgrade routines, all the way up to the latest version
|
||||
*/
|
||||
public function run() {
|
||||
$migrations = $this->find_migrations();
|
||||
|
||||
// run in sub-function for scope
|
||||
array_map( array( $this, 'run_migration' ), $migrations );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function find_migrations() {
|
||||
$files = glob( rtrim( $this->migrations_dir, '/' ) . '/*.php' );
|
||||
$migrations = array();
|
||||
|
||||
// return empty array when glob returns non-array value.
|
||||
if ( ! is_array( $files ) ) {
|
||||
return $migrations;
|
||||
}
|
||||
|
||||
foreach ( $files as $file ) {
|
||||
$migration = basename( $file );
|
||||
$parts = explode( '-', $migration );
|
||||
$version = $parts[0];
|
||||
|
||||
if ( version_compare( $this->version_from, $version, '<' ) ) {
|
||||
$migrations[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
return $migrations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include a migration file and runs it.
|
||||
*
|
||||
* @param string $file
|
||||
*/
|
||||
protected function run_migration( $file ) {
|
||||
include $file;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class MC4WP_Usage_Tracking
|
||||
*
|
||||
* @access private
|
||||
* @since 2.3
|
||||
* @ignore
|
||||
*/
|
||||
class MC4WP_Usage_Tracking {
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tracking_url = 'https://www.mc4wp.com/api/usage-tracking';
|
||||
|
||||
/**
|
||||
* @var MC4WP_Usage_Tracking The One True Instance
|
||||
*/
|
||||
protected static $instance;
|
||||
|
||||
/**
|
||||
* @return MC4WP_Usage_Tracking
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( ! self::$instance instanceof MC4WP_Usage_Tracking ) {
|
||||
self::$instance = new MC4WP_Usage_Tracking();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add hooks
|
||||
*/
|
||||
public function add_hooks() {
|
||||
add_action( 'mc4wp_usage_tracking', array( $this, 'track' ) );
|
||||
add_filter( 'cron_schedules', array( $this, 'cron_schedules' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new schedule with WP Cron
|
||||
*
|
||||
* @param array $schedules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function cron_schedules( $schedules ) {
|
||||
$schedules['monthly'] = array(
|
||||
'interval' => 30 * DAY_IN_SECONDS,
|
||||
'display' => esc_html__( 'Once a month', 'mailchimp-for-wp' ),
|
||||
);
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable usage tracking
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function enable() {
|
||||
// only schedule if not yet scheduled
|
||||
if ( ! wp_next_scheduled( 'mc4wp_usage_tracking' ) ) {
|
||||
return wp_schedule_event( time(), 'monthly', 'mc4wp_usage_tracking' );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable usage tracking
|
||||
*/
|
||||
public function disable() {
|
||||
wp_clear_scheduled_hook( 'mc4wp_usage_tracking' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle tracking (clears & sets the scheduled tracking event)
|
||||
*
|
||||
* @param bool $enable
|
||||
*/
|
||||
public function toggle( $enable ) {
|
||||
$enable ? $this->enable() : $this->disable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the tracking request. Non-blocking.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function track() {
|
||||
$data = $this->get_tracking_data();
|
||||
|
||||
// send non-blocking request and be done with it
|
||||
wp_remote_post(
|
||||
$this->tracking_url,
|
||||
array(
|
||||
'body' => json_encode( $data ),
|
||||
'headers' => array(
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json',
|
||||
),
|
||||
'blocking' => false,
|
||||
)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function get_tracking_data() {
|
||||
$data = array(
|
||||
// use md5 hash of home_url, we don't need/want to know the actual site url
|
||||
'site' => md5( home_url() ),
|
||||
'number_of_mailchimp_lists' => $this->get_mailchimp_lists_count(),
|
||||
'mc4wp_version' => $this->get_mc4wp_version(),
|
||||
'mc4wp_premium_version' => $this->get_mc4wp_premium_version(),
|
||||
'plugins' => (array) get_option( 'active_plugins', array() ),
|
||||
'php_version' => $this->get_php_version(),
|
||||
'curl_version' => $this->get_curl_version(),
|
||||
'wp_version' => $GLOBALS['wp_version'],
|
||||
'wp_language' => get_locale(),
|
||||
'server_software' => $this->get_server_software(),
|
||||
'using_https' => $this->is_site_using_https(),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function get_php_version() {
|
||||
if ( ! defined( 'PHP_MAJOR_VERSION' ) ) { // defined since PHP 5.2.7
|
||||
return null;
|
||||
}
|
||||
|
||||
return PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_mc4wp_premium_version() {
|
||||
return defined( 'MC4WP_PREMIUM_VERSION' ) ? MC4WP_PREMIUM_VERSION : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Mailchimp for WordPress version
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_mc4wp_version() {
|
||||
return MC4WP_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
protected function get_mailchimp_lists_count() {
|
||||
$mailchimp = new MC4WP_MailChimp();
|
||||
return count( $mailchimp->get_lists() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function get_curl_version() {
|
||||
if ( ! function_exists( 'curl_version' ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$curl_version_info = curl_version();
|
||||
return $curl_version_info['version'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_site_using_https() {
|
||||
$site_url = site_url();
|
||||
return stripos( $site_url, 'https' ) === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function get_server_software() {
|
||||
if ( ! isset( $_SERVER['SERVER_SOFTWARE'] ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $_SERVER['SERVER_SOFTWARE'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
// get options
|
||||
$form_options = get_option( 'mc4wp_lite_form', array() );
|
||||
|
||||
// bail if there are no previous options
|
||||
if ( empty( $form_options ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// bail if there are Pro forms already
|
||||
$has_forms = get_posts(
|
||||
array(
|
||||
'post_type' => 'mc4wp-form',
|
||||
'post_status' => 'publish',
|
||||
'numberposts' => 1,
|
||||
)
|
||||
);
|
||||
|
||||
// There are forms already, don't continue.
|
||||
if ( ! empty( $has_forms ) ) {
|
||||
|
||||
// delete option as it apparently exists.
|
||||
delete_option( 'mc4wp_lite_form' );
|
||||
return;
|
||||
}
|
||||
|
||||
// create post type for form
|
||||
$id = wp_insert_post(
|
||||
array(
|
||||
'post_type' => 'mc4wp-form',
|
||||
'post_status' => 'publish',
|
||||
'post_title' => __( 'Default sign-up form', 'mailchimp-for-wp' ),
|
||||
'post_content' => ( empty( $form_options['markup'] ) ) ? '' : $form_options['markup'],
|
||||
)
|
||||
);
|
||||
|
||||
// set default_form_id
|
||||
update_option( 'mc4wp_default_form_id', $id );
|
||||
|
||||
// set form settings
|
||||
$setting_keys = array(
|
||||
'css',
|
||||
'custom_theme_color',
|
||||
'double_optin',
|
||||
'update_existing',
|
||||
'replace_interests',
|
||||
'send_welcome',
|
||||
'redirect',
|
||||
'hide_after_success',
|
||||
);
|
||||
|
||||
$settings = array();
|
||||
|
||||
foreach ( $setting_keys as $setting_key ) {
|
||||
// use isset to account for "0" settings
|
||||
if ( isset( $form_options[ $setting_key ] ) ) {
|
||||
$settings[ $setting_key ] = $form_options[ $setting_key ];
|
||||
}
|
||||
}
|
||||
|
||||
// get only keys of lists setting
|
||||
if ( isset( $form_options['lists'] ) ) {
|
||||
$settings['lists'] = array_keys( $form_options['lists'] );
|
||||
}
|
||||
|
||||
update_post_meta( $id, '_mc4wp_settings', $settings );
|
||||
|
||||
// set form message texts
|
||||
$message_keys = array(
|
||||
'text_subscribed',
|
||||
'text_error',
|
||||
'text_invalid_email',
|
||||
'text_already_subscribed',
|
||||
'text_required_field_missing',
|
||||
'text_unsubscribed',
|
||||
'text_not_subscribed',
|
||||
);
|
||||
|
||||
foreach ( $message_keys as $message_key ) {
|
||||
if ( ! empty( $form_options[ $message_key ] ) ) {
|
||||
update_post_meta( $id, $message_key, $form_options[ $message_key ] );
|
||||
}
|
||||
}
|
||||
|
||||
// delete old option
|
||||
delete_option( 'mc4wp_lite_form' );
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
$global_options = (array) get_option( 'mc4wp_form', array() );
|
||||
|
||||
// find all form posts
|
||||
$posts = get_posts(
|
||||
array(
|
||||
'post_type' => 'mc4wp-form',
|
||||
'post_status' => 'publish',
|
||||
'numberposts' => -1,
|
||||
)
|
||||
);
|
||||
|
||||
$css_map = array(
|
||||
'default' => 'basic',
|
||||
'custom' => 'styles-builder',
|
||||
'light' => 'theme-light',
|
||||
'dark' => 'theme-dark',
|
||||
'red' => 'theme-red',
|
||||
'green' => 'theme-green',
|
||||
'blue' => 'theme-blue',
|
||||
'custom-color' => 'theme-custom-color',
|
||||
);
|
||||
|
||||
$stylesheets = array();
|
||||
|
||||
foreach ( $posts as $post ) {
|
||||
|
||||
// get form options from post meta directly
|
||||
$options = (array) get_post_meta( $post->ID, '_mc4wp_settings', true );
|
||||
|
||||
// store all global options in scoped form settings
|
||||
// do this BEFORE changing css key, so we take that as well.
|
||||
foreach ( $global_options as $key => $value ) {
|
||||
if ( strlen( $value ) > 0 && ( ! isset( $options[ $key ] ) || strlen( $options[ $key ] ) == 0 ) ) {
|
||||
$options[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// update "css" option value
|
||||
if ( isset( $options['css'] ) && isset( $css_map[ $options['css'] ] ) ) {
|
||||
$options['css'] = $css_map[ $options['css'] ];
|
||||
}
|
||||
|
||||
// create stylesheets option
|
||||
if ( ! empty( $options['css'] ) ) {
|
||||
$stylesheet = $options['css'];
|
||||
if ( strpos( $stylesheet, 'theme-' ) === 0 ) {
|
||||
$stylesheet = 'themes';
|
||||
}
|
||||
|
||||
if ( ! in_array( $stylesheet, $stylesheets ) ) {
|
||||
$stylesheets[] = $stylesheet;
|
||||
}
|
||||
}
|
||||
|
||||
update_post_meta( $post->ID, '_mc4wp_settings', $options );
|
||||
}
|
||||
|
||||
// update stylesheets option
|
||||
update_option( 'mc4wp_form_stylesheets', $stylesheets );
|
||||
|
||||
// delete old options
|
||||
delete_option( 'mc4wp_form' );
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
// find all form posts
|
||||
$posts = get_posts(
|
||||
array(
|
||||
'post_type' => 'mc4wp-form',
|
||||
'post_status' => 'publish',
|
||||
'numberposts' => -1,
|
||||
)
|
||||
);
|
||||
|
||||
// set form message texts
|
||||
$message_keys = array(
|
||||
'text_subscribed',
|
||||
'text_error',
|
||||
'text_invalid_email',
|
||||
'text_already_subscribed',
|
||||
'text_required_field_missing',
|
||||
'text_unsubscribed',
|
||||
'text_not_subscribed',
|
||||
);
|
||||
|
||||
foreach ( $posts as $post ) {
|
||||
$settings = get_post_meta( $post->ID, '_mc4wp_settings', true );
|
||||
|
||||
foreach ( $message_keys as $key ) {
|
||||
if ( empty( $settings[ $key ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$message = $settings[ $key ];
|
||||
|
||||
// move message setting over to post meta
|
||||
update_post_meta( $post->ID, $key, $message );
|
||||
unset( $settings[ $key ] );
|
||||
}
|
||||
|
||||
// update post meta with unset message keys
|
||||
update_post_meta( $post->ID, '_mc4wp_settings', $settings );
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
// transfer option
|
||||
$options = (array) get_option( 'mc4wp_lite', array() );
|
||||
|
||||
// merge options, with Pro options taking precedence
|
||||
$pro_options = (array) get_option( 'mc4wp', array() );
|
||||
$options = array_merge( $options, $pro_options );
|
||||
|
||||
// update options
|
||||
update_option( 'mc4wp', $options );
|
||||
|
||||
// delete old option
|
||||
delete_option( 'mc4wp_lite' );
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
$old_options = get_option( 'mc4wp_lite_checkbox', array() );
|
||||
$pro_options = get_option( 'mc4wp_checkbox', array() );
|
||||
if ( ! empty( $pro_options ) ) {
|
||||
$old_options = array_merge( $old_options, $pro_options );
|
||||
}
|
||||
|
||||
// do we have to do something?
|
||||
if ( empty( $old_options ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// find activated integrations (show_at_xxx options)
|
||||
$new_options = array();
|
||||
$map = array(
|
||||
'comment_form' => 'wp-comment-form',
|
||||
'registration_form' => 'wp-registration-form',
|
||||
'buddypress_form' => 'buddypress',
|
||||
'bbpres_forms' => 'bbpress',
|
||||
'woocommerce_checkout' => 'woocommerce',
|
||||
'edd_checkout' => 'easy-digital-downloads',
|
||||
);
|
||||
|
||||
$option_keys = array(
|
||||
'label',
|
||||
'precheck',
|
||||
'css',
|
||||
'lists',
|
||||
'double_optin',
|
||||
'update_existing',
|
||||
'replace_interests',
|
||||
'send_welcome',
|
||||
);
|
||||
|
||||
foreach ( $map as $old_integration_slug => $new_integration_slug ) {
|
||||
|
||||
// check if integration is enabled using its old slug
|
||||
$show_key = sprintf( 'show_at_%s', $old_integration_slug );
|
||||
if ( empty( $old_options[ $show_key ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'enabled' => 1,
|
||||
);
|
||||
|
||||
foreach ( $option_keys as $option_key ) {
|
||||
if ( isset( $old_options[ $option_key ] ) ) {
|
||||
$options[ $option_key ] = $old_options[ $option_key ];
|
||||
}
|
||||
}
|
||||
|
||||
// add to new options
|
||||
$new_options[ $new_integration_slug ] = $options;
|
||||
}
|
||||
|
||||
// save new settings
|
||||
update_option( 'mc4wp_integrations', $new_options );
|
||||
|
||||
// delete old options
|
||||
delete_option( 'mc4wp_lite_checkbox' );
|
||||
delete_option( 'mc4wp_checkbox' );
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
// move stylebuilders file to bundle
|
||||
$file = (string) get_option( 'mc4wp_custom_css_file', '' );
|
||||
if ( empty( $file ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$uploads = wp_upload_dir();
|
||||
|
||||
// figure out absolute file path
|
||||
$prefix = str_replace( 'http:', '', $uploads['baseurl'] );
|
||||
$relative_path = str_replace( $prefix, '', $file );
|
||||
|
||||
// get part before ?
|
||||
if ( strpos( $relative_path, '?' ) !== false ) {
|
||||
$parts = explode( '?', $relative_path );
|
||||
$relative_path = array_shift( $parts );
|
||||
}
|
||||
|
||||
// This is the absolute path to the file, he he..
|
||||
$file = $uploads['basedir'] . $relative_path;
|
||||
|
||||
if ( file_exists( $file ) ) {
|
||||
|
||||
// create directory, if necessary
|
||||
$dir = $uploads['basedir'] . '/mc4wp-stylesheets';
|
||||
if ( ! file_exists( $dir ) ) {
|
||||
@mkdir( $dir, 0755 );
|
||||
}
|
||||
|
||||
@chmod( $dir, 0755 );
|
||||
|
||||
// Move file to new location
|
||||
$new_file = $dir . '/bundle.css';
|
||||
$success = rename( $file, $new_file );
|
||||
}
|
||||
|
||||
// remove old option
|
||||
delete_option( 'mc4wp_custom_css_file' );
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
$section_widgets = get_option( 'sidebars_widgets', array() );
|
||||
$replaced = false;
|
||||
|
||||
foreach ( $section_widgets as $section => $widgets ) {
|
||||
|
||||
// WP has an "array_version" key that is not an array...
|
||||
if ( ! is_array( $widgets ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// loop through widget ID's
|
||||
foreach ( $widgets as $key => $widget_id ) {
|
||||
|
||||
// does this widget ID start with "mc4wp_widget"?
|
||||
if ( strpos( $widget_id, 'mc4wp_widget' ) === 0 ) {
|
||||
|
||||
// replace "mc4wp_widget" with "mc4wp_form_widget"
|
||||
$new_widget_id = str_replace( 'mc4wp_widget', 'mc4wp_form_widget', $widget_id );
|
||||
$section_widgets[ $section ][ $key ] = $new_widget_id;
|
||||
$replaced = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// update option if we made changes
|
||||
if ( $replaced ) {
|
||||
update_option( 'sidebars_widgets', $section_widgets );
|
||||
}
|
||||
|
||||
// update widget options
|
||||
$options = get_option( 'widget_mc4wp_widget', false );
|
||||
if ( $options ) {
|
||||
update_option( 'widget_mc4wp_form_widget', $options );
|
||||
|
||||
// delete old option
|
||||
delete_option( 'widget_mc4wp_widget' );
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
$options = (array) get_option( 'mc4wp', array() );
|
||||
if ( empty( $options['allow_usage_tracking'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// usage tracking is enabled, reschedule it so it uses new cron schedule.
|
||||
|
||||
// make sure 'monthly' cron schedule is registered
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
function _mc4wp_303_add_monthly_cron_schedule( $schedules ) {
|
||||
$schedules['monthly'] = array(
|
||||
'interval' => 30 * DAY_IN_SECONDS,
|
||||
'display' => 'Once a month',
|
||||
);
|
||||
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
add_filter( 'cron_schedules', '_mc4wp_303_add_monthly_cron_schedule', 1 );
|
||||
|
||||
// reschedule usage tracking event
|
||||
wp_clear_scheduled_hook( 'mc4wp_usage_tracking' );
|
||||
wp_schedule_event( time(), 'monthly', 'mc4wp_usage_tracking' );
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
$options = get_option( 'mc4wp_integrations', array() );
|
||||
|
||||
if ( ! empty( $options['woocommerce'] ) && ! empty( $options['woocommerce']['position'] ) ) {
|
||||
$options['woocommerce']['position'] = sprintf( 'checkout_%s', $options['woocommerce']['position'] );
|
||||
}
|
||||
|
||||
update_option( 'mc4wp_integrations', $options );
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @return object
|
||||
*/
|
||||
function _mc4wp_400_find_grouping_for_interest_category( $groupings, $interest_category ) {
|
||||
foreach ( $groupings as $grouping ) {
|
||||
// cast to stdClass because of missing class
|
||||
$grouping = (object) (array) $grouping;
|
||||
|
||||
if ( $grouping->name === $interest_category->title ) {
|
||||
return $grouping;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @return object
|
||||
*/
|
||||
function _mc4wp_400_find_group_for_interest( $groups, $interest ) {
|
||||
foreach ( $groups as $group_id => $group_name ) {
|
||||
if ( $group_name === $interest->name ) {
|
||||
return (object) array(
|
||||
'name' => $group_name,
|
||||
'id' => $group_id,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// in case the migration is _very_ late to the party
|
||||
if ( ! class_exists( 'MC4WP_API_V3' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$options = get_option( 'mc4wp', array() );
|
||||
if ( empty( $options['api_key'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get current state from transient
|
||||
$lists = get_transient( 'mc4wp_mailchimp_lists_fallback' );
|
||||
if ( empty( $lists ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@set_time_limit( 600 );
|
||||
$api_v3 = new MC4WP_API_V3( $options['api_key'] );
|
||||
$map = array();
|
||||
|
||||
foreach ( $lists as $list ) {
|
||||
|
||||
// cast to stdClass because of missing classes
|
||||
$list = (object) (array) $list;
|
||||
|
||||
// no groupings? easy!
|
||||
if ( empty( $list->groupings ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// fetch (new) interest categories for this list
|
||||
try {
|
||||
$interest_categories = $api_v3->get_list_interest_categories( $list->id );
|
||||
} catch ( MC4WP_API_Exception $e ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
foreach ( $interest_categories as $interest_category ) {
|
||||
|
||||
// compare interest title with grouping name, if it matches, get new id.
|
||||
$grouping = _mc4wp_400_find_grouping_for_interest_category( $list->groupings, $interest_category );
|
||||
if ( ! $grouping ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$groups = array();
|
||||
|
||||
try {
|
||||
$interests = $api_v3->get_list_interest_category_interests( $list->id, $interest_category->id );
|
||||
} catch ( MC4WP_API_Exception $e ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $interests as $interest ) {
|
||||
$group = _mc4wp_400_find_group_for_interest( $grouping->groups, $interest );
|
||||
|
||||
if ( $group ) {
|
||||
$groups[ $group->id ] = $interest->id;
|
||||
$groups[ $group->name ] = $interest->id;
|
||||
}
|
||||
}
|
||||
|
||||
$map[ (string) $grouping->id ] = array(
|
||||
'id' => $interest_category->id,
|
||||
'groups' => $groups,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( ! empty( $map ) ) {
|
||||
update_option( 'mc4wp_groupings_map', $map );
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
/** @ignore */
|
||||
function _mc4wp_400_replace_comma_with_pipe( $matches ) {
|
||||
$old = $matches[1];
|
||||
$new = str_replace( ',', '|', $old );
|
||||
return str_replace( $old, $new, $matches[0] );
|
||||
}
|
||||
|
||||
// get all forms
|
||||
$posts = get_posts(
|
||||
array(
|
||||
'post_type' => 'mc4wp-form',
|
||||
'numberposts' => -1,
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( $posts as $post ) {
|
||||
|
||||
// find hidden field values in form and pass through replace function
|
||||
$old = $post->post_content;
|
||||
$new = preg_replace_callback( '/type="hidden" .* value="(.*)"/i', '_mc4wp_400_replace_comma_with_pipe', $old );
|
||||
|
||||
// update post if we replaced something
|
||||
if ( $new != $old ) {
|
||||
$post->post_content = $new;
|
||||
wp_update_post( $post );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
// get old log filename
|
||||
$upload_dir = wp_upload_dir( null, false );
|
||||
$old_filename = trailingslashit( $upload_dir['basedir'] ) . 'mc4wp-debug.log';
|
||||
$new_filename = trailingslashit( $upload_dir['basedir'] ) . 'mc4wp-debug-log.php';
|
||||
|
||||
// check if old default log file exists
|
||||
if ( ! file_exists( $old_filename ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// rename to new file.
|
||||
@rename( $old_filename, $new_filename );
|
||||
|
||||
// if success, insert php exit tag as first line
|
||||
if ( file_exists( $new_filename ) ) {
|
||||
$handle = fopen( $new_filename, 'r+' );
|
||||
|
||||
if ( is_resource( $handle ) ) {
|
||||
// make sure first line of log file is a PHP tag + exit statement (to prevent direct file access)
|
||||
$line = fgets( $handle );
|
||||
$php_exit_string = '<?php exit; ?>';
|
||||
if ( strpos( $line, $php_exit_string ) !== 0 ) {
|
||||
rewind( $handle );
|
||||
fwrite( $handle, $php_exit_string . PHP_EOL . $line );
|
||||
}
|
||||
|
||||
fclose( $handle );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
if ( function_exists( 'mc4wp_refresh_mailchimp_lists' ) ) {
|
||||
mc4wp_refresh_mailchimp_lists();
|
||||
}
|
||||
|
||||
delete_transient( 'mc4wp_mailchimp_lists_v3' );
|
||||
delete_option( 'mc4wp_mailchimp_lists_v3_fallback' );
|
||||
|
||||
wp_schedule_event( strtotime( 'tomorrow 3 am' ), 'daily', 'mc4wp_refresh_mailchimp_lists' );
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
wp_clear_scheduled_hook( 'mc4wp_refresh_mailchimp_lists' );
|
||||
|
||||
$time_string = sprintf( 'tomorrow %d:%d%d am', rand( 1, 6 ), rand( 0, 5 ), rand( 0, 9 ) );
|
||||
wp_schedule_event( strtotime( $time_string ), 'daily', 'mc4wp_refresh_mailchimp_lists' );
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
global $wpdb;
|
||||
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'mc4wp_mailchimp_list_%'" );
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) or exit;
|
||||
|
||||
// get old filename
|
||||
$upload_dir = wp_upload_dir( null, false );
|
||||
$old_filename = trailingslashit( $upload_dir['basedir'] ) . 'mc4wp-debug-log.php';
|
||||
|
||||
// if old file exists, move it to new location
|
||||
if ( is_file( $old_filename ) ) {
|
||||
$new_filename = $upload_dir['basedir'] . '/mailchimp-for-wp/debug-log.php';
|
||||
$dir = dirname( $new_filename );
|
||||
if ( ! is_dir( $dir ) ) {
|
||||
mkdir( $dir, 0755, true );
|
||||
}
|
||||
|
||||
rename( $old_filename, $new_filename );
|
||||
}
|
||||
Reference in New Issue
Block a user