add_section( 'typography_options', array( * 'title' => esc_html__( 'Typography Options', 'beetan' ), * 'priority' => 35, * ) ); * * new Beetan_Customize_Typography( $wp_customize, 'logo_font', array( * 'default' => array( * 'family' => '', * 'style' => '', * 'subset' => '', * 'size' => '', * ), * * 'label' => esc_html__( 'Logo Font', 'beetan' ), * 'section' => 'typography_options', * ) ); */ if ( ! class_exists( 'Beetan_Customize_Typography_Control' ) ): class Beetan_Customize_Typography_Control extends WP_Customize_Control { public $type = 'typography'; private $placeholder; private $extras = array(); public function __construct( $manager, $id, $args = array() ) { parent::__construct( $manager, $id, $args ); $this->placeholder = isset( $args[ 'placeholder' ] ) ? $args[ 'placeholder' ] : ''; $this->extras = isset( $args[ 'extras' ] ) ? $args[ 'extras' ] : array(); } public function to_json() { parent::to_json(); $this->json[ 'placeholder' ] = $this->placeholder; $this->json[ 'extras' ] = $this->extras; } public function enqueue() { $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_style( 'select2', esc_url( get_theme_file_uri( "/assets/css/select2{$suffix}.css" ) ) ); wp_enqueue_script( 'select2', esc_url( get_theme_file_uri( "/assets/js/select2{$suffix}.js" ) ), array( 'jquery' ), FALSE, TRUE ); wp_enqueue_script( 'customize-typography-control', esc_url( get_theme_file_uri( "/assets/js/customize-typography-control$suffix.js" ) ), array( 'jquery', 'select2' ), FALSE, TRUE ); // wp_localize_script( 'customize-typography-control', 'CustomizeTypographyObject', array( // 'standardFonts' => beetan_standard_fonts(), // 'standardFontStyles' => beetan_standard_font_styles(), // 'googleFonts' => beetan_all_google_fonts() // ) ); wp_enqueue_style( 'customize-typography-control', esc_url( get_theme_file_uri( "/assets/css/customize-typography-control$suffix.css" ) ) ); } protected function render_content() { if ( empty( $this->choices ) ) { return; } ?> add_settings( $wp_customize, $id, $args ); $this->add_controls( $wp_customize, $id, $args ); } private function add_settings( $wp_customize, $id, $args = array() ) { $wp_customize->add_setting( sprintf( '%s[family]', $id ), array( 'default' => isset( $args[ 'default' ][ 'family' ] ) ? $args[ 'default' ][ 'family' ] : FALSE, 'sanitize_callback' => 'sanitize_key', ) ); $wp_customize->add_setting( sprintf( '%s[style]', $id ), array( 'default' => isset( $args[ 'default' ][ 'style' ] ) ? $args[ 'default' ][ 'style' ] : FALSE, 'sanitize_callback' => 'sanitize_key', ) ); $wp_customize->add_setting( sprintf( '%s[subset]', $id ), array( 'default' => isset( $args[ 'default' ][ 'subset' ] ) ? $args[ 'default' ][ 'subset' ] : FALSE, 'sanitize_callback' => 'sanitize_key', ) ); $wp_customize->add_setting( sprintf( '%s[size]', $id ), array( 'default' => isset( $args[ 'default' ][ 'size' ] ) ? $args[ 'default' ][ 'size' ] : '0px', 'sanitize_callback' => 'esc_attr', ) ); } private function add_controls( $wp_customize, $id, $args ) { $wp_customize->add_control( new Beetan_Customize_Typography_Control( $wp_customize, sprintf( '%s[family]', $id ), array( 'label' => sprintf( esc_html__( '%s Family', 'beetan' ), $args[ 'label' ] ), // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment 'description' => wp_kses_post( isset( $args[ 'description' ] ) ? $args[ 'description' ] : '' ), 'placeholder' => esc_html__( 'Font Family', 'beetan' ), 'section' => $args[ 'section' ], 'choices' => array( array( 'label' => esc_html__( 'Standard Fonts', 'beetan' ), 'options' => beetan_standard_fonts() ), array( 'label' => esc_html__( 'Google Fonts', 'beetan' ), 'options' => beetan_google_fonts() ), ), 'extras' => array( 'id' => $id ) ) ) ); $wp_customize->add_control( new Beetan_Customize_Typography_Control( $wp_customize, sprintf( '%s[style]', $id ), array( 'label' => sprintf( esc_html__( '%s Style', 'beetan' ), $args[ 'label' ] ), // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment 'description' => wp_kses_post( isset( $args[ 'description' ] ) ? $args[ 'description' ] : '' ), 'placeholder' => esc_html__( 'Font Style', 'beetan' ), 'section' => $args[ 'section' ], 'choices' => beetan_standard_font_styles(), 'extras' => array( 'id' => $id ) ) ) ); $wp_customize->add_control( new Beetan_Customize_Typography_Control( $wp_customize, sprintf( '%s[subset]', $id ), array( 'label' => sprintf( esc_html__( '%s Subset', 'beetan' ), $args[ 'label' ] ), // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment 'description' => wp_kses_post( isset( $args[ 'description' ] ) ? $args[ 'description' ] : '' ), 'placeholder' => esc_html__( 'Font Subset', 'beetan' ), 'section' => $args[ 'section' ], 'choices' => beetan_standard_font_styles(), 'extras' => array( 'id' => $id ) ) ) ); $wp_customize->add_control( new Beetan_Customize_Unit_Control( $wp_customize, sprintf( '%s[size]', $id ), array( 'label' => sprintf( esc_html__( '%s Size', 'beetan' ), $args[ 'label' ] ), // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment 'description' => wp_kses_post( isset( $args[ 'description' ] ) ? $args[ 'description' ] : '' ), 'placeholder' => esc_html__( 'Font Size', 'beetan' ), 'section' => $args[ 'section' ], 'required' => array( sprintf( '%s[family]', $id ) ) ) ) ); } } endif;