first commit
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?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,42 @@
|
||||
<?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,64 @@
|
||||
<?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,41 @@
|
||||
<?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,39 @@
|
||||
<?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,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