show_font_family = $args['show_font_family']; } if ( isset( $args['show_font_size'] ) ) { $this->show_font_size = $args['show_font_size']; } if ( isset( $args['show_font_weight'] ) ) { $this->show_font_weight = $args['show_font_weight']; } if ( isset( $args['show_line_height'] ) ) { $this->show_line_height = $args['show_line_height']; } if ( isset( $args['show_letter_spacing'] ) ) { $this->show_letter_spacing = $args['show_letter_spacing']; } if ( isset( $args['show_text_transform'] ) ) { $this->show_text_transform = $args['show_text_transform']; } } /** * Enqueue control related scripts/styles */ public function enqueue() { wp_enqueue_script( 'accepta-typography-control', get_template_directory_uri() . '/inc/customizer-controls/js/typography-control.js', array( 'jquery', 'customize-base' ), wp_get_theme()->get( 'Version' ), true ); wp_enqueue_style( 'accepta-typography-control', get_template_directory_uri() . '/inc/customizer-controls/css/typography-control.css', array(), wp_get_theme()->get( 'Version' ) ); // Load Google Fonts data from JSON file $fonts_file = get_template_directory() . '/inc/customizer-controls/google-fonts.json'; $google_fonts_data = array(); if ( file_exists( $fonts_file ) ) { $fonts_json = file_get_contents( $fonts_file ); $fonts_data = json_decode( $fonts_json, true ); if ( isset( $fonts_data['items'] ) && is_array( $fonts_data['items'] ) ) { $google_fonts_data = $fonts_data['items']; } } // Localize script with minimal data for font styling wp_localize_script( 'accepta-typography-control', 'acceptaTypographyL10n', array( 'systemFonts' => $this->get_system_fonts(), 'googleFonts' => $this->get_google_fonts(), ) ); } /** * Render the control's content */ public function render_content() { $input_id = '_customize-input-' . $this->id; $description_id = '_customize-description-' . $this->id; $describedby_attr = ( ! empty( $this->description ) ) ? ' aria-describedby="' . esc_attr( $description_id ) . '"' : ''; $value = $this->value(); // Parse value if it's JSON if ( is_string( $value ) ) { $value = json_decode( $value, true ); } // Set defaults if ( ! is_array( $value ) ) { $value = array(); } $defaults = array( 'font_family' => '', 'font_size' => '', 'font_size_desktop' => '', 'font_size_tablet' => '', 'font_size_mobile' => '', 'font_weight' => '', 'line_height' => '', 'letter_spacing' => '', 'text_transform' => '', ); $value = wp_parse_args( $value, $defaults ); ?>
label ) ) : ?> label ); ?> description ) ) : ?> description; ?>
show_font_family ) : ?>
show_font_size ) : ?>
px
px
px
show_font_weight ) : ?>
show_line_height ) : ?>
em
show_letter_spacing ) : ?>
px
show_text_transform ) : ?>
link(); ?> value="" class="accepta-typography-hidden" />
'Arial', 'Helvetica, Arial, sans-serif' => 'Helvetica', '"Times New Roman", Times, serif' => 'Times New Roman', 'Georgia, serif' => 'Georgia', '"Courier New", Courier, monospace' => 'Courier New', 'Verdana, Geneva, sans-serif' => 'Verdana', 'Tahoma, Geneva, sans-serif' => 'Tahoma', '"Trebuchet MS", Helvetica, sans-serif' => 'Trebuchet MS', '"Arial Black", Gadget, sans-serif' => 'Arial Black', '"Palatino Linotype", "Book Antiqua", Palatino, serif' => 'Palatino', '"Lucida Sans Unicode", "Lucida Grande", sans-serif' => 'Lucida Sans', '"MS Serif", "New York", serif' => 'MS Serif', '"Comic Sans MS", cursive' => 'Comic Sans MS', 'Impact, Charcoal, sans-serif' => 'Impact', ); } /** * Get Google Fonts from JSON file * * @return array */ private function get_google_fonts() { $fonts_file = get_template_directory() . '/inc/customizer-controls/google-fonts.json'; if ( ! file_exists( $fonts_file ) ) { return array(); } $fonts_json = file_get_contents( $fonts_file ); $fonts_data = json_decode( $fonts_json, true ); if ( ! isset( $fonts_data['items'] ) || ! is_array( $fonts_data['items'] ) ) { return array(); } $fonts = array(); foreach ( $fonts_data['items'] as $font ) { if ( isset( $font['family'] ) ) { $fonts[ $font['family'] ] = $font['family']; } } return $fonts; } }