('|', $groups); } // loop through groups and find interest ID $migrated = 0; foreach ($groups as $key => $group_name_or_id) { // do we know the new interest ID? if (empty($map[ $grouping_id ]['groups'][ $group_name_or_id ])) { continue; } $interest_id = $map[ $grouping_id ]['groups'][ $group_name_or_id ]; // add to interests data if (! in_array($interest_id, $data['INTERESTS'], false)) { ++$migrated; $data['INTERESTS'][] = $interest_id; } } // remove old grouping ID if we migrated all groups. if ($migrated === count($groups)) { unset($data['GROUPINGS'][ $grouping_key ]); } } // if everything went well, this is now empty & moved to new INTERESTS key. if (empty($data['GROUPINGS'])) { unset($data['GROUPINGS']); } // is this empty? just unset it then. if (empty($data['INTERESTS'])) { unset($data['INTERESTS']); } return $data; } /** * Guesses merge vars based on given data & current request. * * @since 3.0 * @access public * * @param array $data * * @return array */ function mc4wp_add_name_data($data) { // Guess first and last name if (! empty($data['NAME']) && empty($data['FNAME']) && empty($data['LNAME'])) { $data['NAME'] = trim($data['NAME']); $strpos = strpos($data['NAME'], ' '); if ($strpos !== false) { $data['FNAME'] = trim(substr($data['NAME'], 0, $strpos)); $data['LNAME'] = trim(substr($data['NAME'], $strpos)); } else { $data['FNAME'] = $data['NAME']; } } // Set name value if (empty($data['NAME']) && ! empty($data['FNAME']) && ! empty($data['LNAME'])) { $data['NAME'] = sprintf('%s %s', $data['FNAME'], $data['LNAME']); } return $data; } /** * Gets the "email type" for new subscribers. * * Possible return values are either "html" or "text" * * @access public * @since 3.0 * * @return string */ function mc4wp_get_email_type() { $email_type = 'html'; /** * Filters the email type preference for this new subscriber. * * @param string $email_type */ $email_type = (string) apply_filters('mc4wp_email_type', $email_type); return $email_type; } /** * * @ignore * @return bool */ function _mc4wp_use_sslverify() { // Disable for all transports other than CURL if (! function_exists('curl_version')) { return false; } $curl = curl_version(); // Disable if OpenSSL is not installed if (empty($curl['ssl_version'])) { return false; } // Disable if on WP 4.4, see https://core.trac.wordpress.org/ticket/34935 if ($GLOBALS['wp_version'] === '4.4') { return false; } return true; } /** * This will replace the first half of a string with "*" characters. * * @param string $string * @return string */ function mc4wp_obfuscate_string($string) { if (false === is_string($string) || $string === '') { return $string; } $length = strlen($string); if ($length <= 2) { return $string; } $keep = (int) floor($length / 3); $keep = (int) min($keep, 4); return substr($string, 0, $keep) . str_repeat('*', $length - ($keep * 2)) . substr($string, -$keep); } /** * @param array $m * @return string * @internal * @ignore */ function _mc4wp_obfuscate_email_addresses_callback($m) { return mc4wp_obfuscate_string($m[1]) . '@' . mc4wp_obfuscate_string($m[2]); } /** * Obfuscates email addresses in a string. * * @param string $string String possibly containing email address * @return string */ function mc4wp_obfuscate_email_addresses($string) { return preg_replace_callback('/([A-Z0-9._%+-]{1,64})@([A-Z0-9.-]{1,253}\.[A-Z]{2,63})/i', '_mc4wp_obfuscate_email_addresses_callback', $string); } /** * Truncates a debug log message to a reasonable maximum size. * * @param string $message * @return string */ function mc4wp_truncate_log_message($message) { /** * Filters the maximum length of a debug log message in bytes. * * Return 0 or a negative value to disable truncation. * * @param int $max_length Maximum message length in bytes. */ $max_length = (int) apply_filters('mc4wp_debug_log_message_max_length', 8192); if ($max_length <= 0) { return $message; } $length = strlen($message); if ($length <= $max_length) { return $message; } $suffix = sprintf('... [truncated, original length: %d bytes]', $length); if (strlen($suffix) >= $max_length) { return substr($message, 0, $max_length); } return substr($message, 0, $max_length - strlen($suffix)) . $suffix; } /** * Refreshes Mailchimp lists. This can take a while if the connected Mailchimp account has many lists. * * @return void */ function mc4wp_refresh_mailchimp_lists() { $mailchimp = new MC4WP_MailChimp(); $mailchimp->refresh_lists(); } /** * Get element from array, allows for dot notation eg: "foo.bar" * * @param array $array * @param string|null $key * @param mixed $default * @return mixed */ function mc4wp_array_get($array, $key, $default = null) { if ($key === null) { return $array; } if (isset($array[ $key ])) { return $array[ $key ]; } foreach (explode('.', $key) as $segment) { if (! is_array($array) || ! array_key_exists($segment, $array)) { return $default; } $array = $array[ $segment ]; } return $array; } /** * Filters string and strips out all HTML tags and attributes, except what's in our whitelist. * * @param string $string The string to apply KSES whitelist on * @return string * @since 4.8.8 */ function mc4wp_kses($string) { $always_allowed_attr = array_fill_keys( [ 'aria-describedby', 'aria-details', 'aria-label', 'aria-labelledby', 'aria-hidden', 'class', 'id', 'style', 'title', 'role', 'data-*', 'tabindex', ], true ); $input_allowed_attr = array_merge( $always_allowed_attr, array_fill_keys( [ 'type', 'required', 'placeholder', 'value', 'name', 'step', 'min', 'max', 'checked', 'width', 'autocomplete', 'autofocus', 'minlength', 'maxlength', 'size', 'pattern', 'disabled', 'readonly', ], true ) ); $allowed = [ 'p' => $always_allowed_attr, 'label' => array_merge($always_allowed_attr, [ 'for' => true ]), 'input' => $input_allowed_attr, 'button' => $input_allowed_attr, 'fieldset' => $always_allowed_attr, 'legend' => $always_allowed_attr, 'ul' => $always_allowed_attr, 'ol' => $always_allowed_attr, 'li' => $always_allowed_attr, 'select' => array_merge($input_allowed_attr, [ 'multiple' => true ]), 'option' => array_merge($input_allowed_attr, [ 'selected' => true ]), 'optgroup' => [ 'disabled' => true, 'label' => true, ], 'textarea' => array_merge( $input_allowed_attr, [ 'rows' => true, 'cols' => true, ] ), 'div' => $always_allowed_attr, 'strong' => $always_allowed_attr, 'b' => $always_allowed_attr, 'i' => $always_allowed_attr, 'br' => [], 'em' => $always_allowed_attr, 'span' => $always_allowed_attr, 'a' => array_merge($always_allowed_attr, [ 'href' => true ]), 'img' => array_merge( $always_allowed_attr, [ 'src' => true, 'alt' => true, 'width' => true, 'height' => true, 'srcset' => true, 'sizes' => true, 'referrerpolicy' => true, ] ), 'u' => $always_allowed_attr, ]; return wp_kses($string, $allowed); } /** * Helper function for safely deprecating a changed filter hook. * * @param string $old_hook * @param string $new_hook * * @return void */ function mc4wp_apply_deprecated_filters($old_hook, $new_hook) { add_filter($new_hook, function ($value, $a = null, $b = null, $c = null) use ($new_hook, $old_hook) { return apply_filters_deprecated($old_hook, [ $value, $a, $b, $c ], '4.9.0', $new_hook); }, 10, 3); }