add_sub_fields( $args ); add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); add_action( 'customize_preview_init', [ $this, 'enqueue_customize_preview_init' ] ); 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'; /** * 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' ], 'input_attrs' => '', 'choices' => [ 'type' => 'hidden', 'parent_type' => 'kirki-typography', ], ], $args ) ); $args['parent_setting'] = $args['settings']; $args['output'] = []; $args['wrapper_atts'] = [ '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, font-weight and font-style. * They are grouped here because all 3 of them are required * in order to get the right googlefont variant. */ if ( isset( $args['default']['font-family'] ) ) { // Figure out how to sort the fonts. $sorting = 'alpha'; $max_fonts = 9999; if ( isset( $args['choices'] ) && isset( $args['choices']['fonts'] ) && isset( $args['choices']['fonts']['google'] ) ) { if ( isset( $args['choices']['fonts']['google'][0] ) && 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]; } } $google = new GoogleFonts(); $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 = [ 'standard' => [ esc_html__( 'Standard Fonts', 'anzu' ), $std_fonts, ], 'google' => [ esc_html__( 'Google Fonts', 'anzu' ), 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; } $args['wrapper_atts']['kirki-typography-subcontrol-type'] = 'font-family'; /** * Add font-family control. */ new \Kirki\Field\ReactSelect( wp_parse_args( [ 'label' => esc_html__( 'Font Family', 'anzu' ), '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' => $choices, 'css_vars' => [], 'output' => [], ], $args ) ); /** * Add font-weight. */ $font_weight = 400; $font_weight = isset( $args['default']['variant'] ) ? $args['default']['variant'] : 400; $font_weight = isset( $args['default']['font-weight'] ) ? $args['default']['font-weight'] : $font_weight; $font_weight = 'regular' === $font_weight || 'italic' === $font_weight ? 400 : (int) $font_weight; $args['wrapper_atts']['kirki-typography-subcontrol-type'] = 'font-weight'; new \Kirki\Field\ReactSelect( wp_parse_args( [ 'label' => esc_html__( 'Font Weight', 'anzu' ), 'description' => '', 'settings' => $args['settings'] . '[font-weight]', 'default' => $font_weight, 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-weight', $args ), 'choices' => [ '100' => esc_html__( '100 - Thin', 'anzu' ), '200' => esc_html__( '200 - Extra Light, Ultra Light', 'anzu' ), '300' => esc_html__( '300 - Light', 'anzu' ), '400' => esc_html__( '400 - Normal, Book, Regular', 'anzu' ), '500' => esc_html__( '500 - Medium', 'anzu' ), '600' => esc_html__( '600 - Semi Bold, Demi Bold', 'anzu' ), '700' => esc_html__( '700 - Bold', 'anzu' ), '800' => esc_html__( '800 - Extra Bold, Ultra Bold', 'anzu' ), '900' => esc_html__( '900 - Black, Heavy', 'anzu' ), ], 'css_vars' => [], 'output' => [], ], $args ) ); /** * Add font-style. */ $is_italic = isset( $args['default']['variant'] ) && false !== strpos( $args['default']['variant'], 'i' ); $is_italic = isset( $args['default']['font-style'] ) && 'italic' === $args['default']['font-style']; $args['wrapper_atts']['kirki-typography-subcontrol-type'] = 'font-style'; if ( isset( $args['default']['font-style'] ) ) { new \Kirki\Field\Radio_Buttonset( wp_parse_args( [ 'label' => esc_html__( 'Italics', 'anzu' ), 'description' => '', 'settings' => $args['settings'] . '[font-style]', 'default' => $is_italic ? 'italic' : 'normal', 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-style', $args ), 'choices' => [ 'normal' => esc_html__( 'No', 'anzu' ), 'italic' => esc_html__( 'Yes', 'anzu' ), ], 'css_vars' => [], 'output' => [], ], $args ) ); } } if ( isset( $args['default']['text-decoration'] ) ) { $args['wrapper_atts']['kirki-typography-subcontrol-type'] = 'text-decoration'; new \Kirki\Field\Radio_Buttonset( wp_parse_args( [ 'label' => esc_html__( 'Underline', 'anzu' ), 'description' => '', 'settings' => $args['settings'] . '[text-decoration]', 'default' => $args['default']['text-decoration'], 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'text-decoration', $args ), 'choices' => [ 'none' => esc_html__( 'No', 'anzu' ), 'underline' => esc_html__( 'Yes', 'anzu' ), ], 'css_vars' => [], 'output' => [], ], $args ) ); } /** * Add font-size. */ if ( isset( $args['default']['font-size'] ) ) { $args['wrapper_atts']['kirki-typography-subcontrol-type'] = 'font-size'; new \Kirki\Field\Dimension( wp_parse_args( [ 'label' => esc_html__( 'Font Size', 'anzu' ), 'description' => '', 'settings' => $args['settings'] . '[font-size]', 'default' => $args['default']['font-size'], 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'font-size', $args ), 'css_vars' => [], 'output' => [], ], $args ) ); } /** * Line-Height. */ if ( isset( $args['default']['line-height'] ) ) { $args['wrapper_atts']['kirki-typography-subcontrol-type'] = 'line-height'; new \Kirki\Field\Dimension( wp_parse_args( [ 'label' => esc_html__( 'Line Height', 'anzu' ), 'description' => '', 'settings' => $args['settings'] . '[line-height]', 'default' => $args['default']['line-height'], 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'line-height', $args ), 'css_vars' => [], 'output' => [], ], $args ) ); } if ( isset( $args['default']['letter-spacing'] ) ) { $args['wrapper_atts']['kirki-typography-subcontrol-type'] = 'letter-spacing'; new \Kirki\Field\Dimension( wp_parse_args( [ 'label' => esc_html__( 'Letter Spacing', 'anzu' ), 'description' => '', 'settings' => $args['settings'] . '[letter-spacing]', 'default' => $args['default']['letter-spacing'], 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'letter-spacing', $args ), 'css_vars' => [], 'output' => [], ], $args ) ); } if ( isset( $args['default']['word-spacing'] ) ) { $args['wrapper_atts']['kirki-typography-subcontrol-type'] = 'word-spacing'; new \Kirki\Field\Dimension( wp_parse_args( [ 'label' => esc_html__( 'Word Spacing', 'anzu' ), 'description' => '', 'settings' => $args['settings'] . '[word-spacing]', 'default' => $args['default']['word-spacing'], 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'word-spacing', $args ), 'css_vars' => [], 'output' => [], ], $args ) ); } if ( isset( $args['default']['text-transform'] ) ) { $args['wrapper_atts']['kirki-typography-subcontrol-type'] = 'text-transform'; new \Kirki\Field\ReactSelect( wp_parse_args( [ 'label' => esc_html__( 'Text Transform', 'anzu' ), 'description' => '', 'settings' => $args['settings'] . '[text-transform]', 'default' => $args['default']['text-transform'], 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'text-transform', $args ), 'choices' => [ 'none' => esc_html__( 'None', 'anzu' ), 'capitalize' => esc_html__( 'Capitalize', 'anzu' ), 'uppercase' => esc_html__( 'Uppercase', 'anzu' ), 'lowercase' => esc_html__( 'Lowercase', 'anzu' ), ], 'css_vars' => [], 'output' => [], ], $args ) ); } if ( isset( $args['default']['text-align'] ) ) { $args['wrapper_atts']['kirki-typography-subcontrol-type'] = 'text-align'; new \Kirki\Field\ReactSelect( wp_parse_args( [ 'label' => esc_html__( 'Text Align', 'anzu' ), 'description' => '', 'settings' => $args['settings'] . '[text-align]', 'default' => $args['default']['text-align'], 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'text-align', $args ), 'choices' => [ 'initial' => esc_html__( 'Initial', 'anzu' ), 'left' => esc_html__( 'Left', 'anzu' ), 'center' => esc_html__( 'Center', 'anzu' ), 'right' => esc_html__( 'Right', 'anzu' ), 'justify' => esc_html__( 'Justify', 'anzu' ), ], 'css_vars' => [], 'output' => [], ], $args ) ); } if ( isset( $args['default']['margin-top'] ) ) { $args['wrapper_atts']['kirki-typography-subcontrol-type'] = 'margin-top'; new \Kirki\Field\Dimension( wp_parse_args( [ 'label' => esc_html__( 'Top Margin', 'anzu' ), 'description' => '', 'settings' => $args['settings'] . '[margin-top]', 'default' => $args['default']['margin-top'], 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'margin-top', $args ), 'css_vars' => [], 'output' => [], ], $args ) ); } if ( isset( $args['default']['margin-bottom'] ) ) { $args['wrapper_atts']['kirki-typography-subcontrol-type'] = 'margin-bottom'; new \Kirki\Field\Dimension( wp_parse_args( [ 'label' => esc_html__( 'Bottom Margin', 'anzu' ), 'description' => '', 'settings' => $args['settings'] . '[margin-bottom]', 'default' => $args['default']['margin-bottom'], 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'margin-bottom', $args ), 'css_vars' => [], 'output' => [], ], $args ) ); } if ( isset( $args['default']['color'] ) ) { $args['wrapper_atts']['kirki-typography-subcontrol-type'] = 'color'; new \Kirki\Field\ReactColor( wp_parse_args( [ 'label' => '', 'description' => '', 'settings' => $args['settings'] . '[color]', 'default' => $args['default']['color'], 'input_attrs' => $this->filter_preferred_choice_setting( 'input_attrs', 'color', $args ), 'css_vars' => [], 'output' => [], 'choices' => [ 'disableAlpha' => true, ], ], $args ) ); } new \Kirki\Field\Custom( [ 'label' => '', 'description' => '', 'default' => '