*/ public static function config( $place = '' ) { if ( ! in_array( $place, array( 'checkout', 'account' ), true ) ) { $place = function_exists( 'is_checkout' ) && is_checkout() ? 'checkout' : 'account'; } $groups = array(); foreach ( Settings::GROUPS as $group ) { $groups[ $group ] = array( 'only' => array_map( 'strtolower', Countries::allowed( $group ) ), 'types' => Checkout::allowed_types( $group, $place ), ); } $config = array( 'mode' => (string) Settings::get( 'mode' ), 'ns' => Checkout::NS, 'store' => strtolower( Countries::store() ), 'popular' => array_map( 'strtolower', (array) Settings::get( 'popular' ) ), 'groups' => $groups, 'messages' => array(), 'names' => array(), 'formatAsYouType' => false, 'i18n' => array( 'invalid' => __( 'Please enter a valid phone number.', 'dialtidy' ), 'warn' => __( 'This doesn’t look like a valid phone number. Please check it.', 'dialtidy' ), 'notAllowed' => __( 'Phone numbers from this region are not accepted here. Please enter another number.', 'dialtidy' ), 'close' => __( 'Close', 'dialtidy' ), /* translators: 1: country name, 2: dialing code such as +43. */ 'selected' => __( 'Change country for phone number, currently selected %1$s (%2$s)', 'dialtidy' ), 'noCountry' => __( 'Select country for phone number', 'dialtidy' ), 'countryList' => __( 'List of countries', 'dialtidy' ), 'search' => __( 'Search', 'dialtidy' ), 'clearSearch' => __( 'Clear search', 'dialtidy' ), 'noResults' => __( 'No results found', 'dialtidy' ), 'oneResult' => __( '1 result found', 'dialtidy' ), /* translators: %d: number of countries found. */ 'results' => __( '%d results found', 'dialtidy' ), ), ); return self::extend( $config, $place ); } /** * Adds the values other plugins may set: messages per reason, country names for them, spacing while typing. * * @param array $config Settings for the script. * @param string $place checkout or account. * @return array */ private static function extend( array $config, $place ) { /** * Phone field settings for the browser. Only these keys are used: * messages (reason => text, %s is the country name), names (lower-case country code => name), formatAsYouType (bool). * * @param array $extra Values. * @param string $place checkout or account. */ $extra = apply_filters( 'dialtidy_script_config', array( 'messages' => array(), 'names' => array(), 'formatAsYouType' => false, ), $place ); if ( ! is_array( $extra ) ) { return $config; } if ( isset( $extra['messages'] ) && is_array( $extra['messages'] ) ) { foreach ( Phone::REASONS as $reason ) { if ( isset( $extra['messages'][ $reason ] ) && is_string( $extra['messages'][ $reason ] ) && '' !== trim( wp_strip_all_tags( $extra['messages'][ $reason ] ) ) ) { $config['messages'][ $reason ] = trim( wp_strip_all_tags( $extra['messages'][ $reason ] ) ); } } } if ( isset( $extra['names'] ) && is_array( $extra['names'] ) ) { foreach ( $extra['names'] as $code => $name ) { if ( is_string( $code ) && preg_match( '/^[a-z]{2}$/', $code ) && is_string( $name ) && '' !== trim( $name ) ) { $config['names'][ $code ] = html_entity_decode( wp_strip_all_tags( $name ), ENT_QUOTES, 'UTF-8' ); } } } $config['formatAsYouType'] = isset( $extra['formatAsYouType'] ) && true === $extra['formatAsYouType']; return $config; } }