a['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 ) { $length = strlen( $string ); $obfuscated_length = ceil( $length / 2 ); $string = str_repeat( '*', $obfuscated_length ) . substr( $string, $obfuscated_length ); return $string; } /** * @internal * @ignore */ function _mc4wp_obfuscate_email_addresses_callback( $m ) { $one = $m[1] . str_repeat( '*', strlen( $m[2] ) ); $two = $m[3] . str_repeat( '*', strlen( $m[4] ) ); $three = $m[5]; return sprintf( '%s@%s.%s', $one, $two, $three ); } /** * Obfuscates email addresses in a string. * * @param $string String possibly containing email address * @return string */ function mc4wp_obfuscate_email_addresses( $string ) { return preg_replace_callback( '/([\w\.]{1,4})([\w\.]*)\@(\w{1,2})(\w*)\.(\w+)/', '_mc4wp_obfuscate_email_addresses_callback', $string ); } /** * 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 $key * @param mixed $default * @return mixed */ function mc4wp_array_get( $array, $key, $default = null ) { if ( is_null( $key ) ) { 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( array( '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( array( 'type', 'required', 'placeholder', 'value', 'name', 'step', 'min', 'max', 'checked', 'width', 'autocomplete', 'autofocus', 'minlength', 'maxlength', 'size', 'pattern', 'disabled', 'readonly', ), true ) ); $allowed = array( 'p' => $always_allowed_attr, 'label' => array_merge( $always_allowed_attr, array( '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, array( 'multiple' => true ) ), 'option' => array_merge( $input_allowed_attr, array( 'selected' => true ) ), 'optgroup' => array( 'disabled' => true, 'label' => true, ), 'textarea' => array_merge( $input_allowed_attr, array( 'rows' => true, 'cols' => true, ) ), 'div' => $always_allowed_attr, 'strong' => $always_allowed_attr, 'b' => $always_allowed_attr, 'i' => $always_allowed_attr, 'br' => array(), 'em' => $always_allowed_attr, 'span' => $always_allowed_attr, 'a' => array_merge( $always_allowed_attr, array( 'href' => true ) ), 'img' => array_merge( $always_allowed_attr, array( '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, array( $value, $a, $b, $c ), '4.9.0', $new_hook ); }, 10, 3 ); }