[ $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 ) {} } Men – Herbal Succeed