get( 'Version' ); wp_enqueue_script( 'athlonx-options', get_template_directory_uri() . '/assets/js/options.min.js', array( 'jquery', 'customize-preview' ), $theme_version, true ); } ); /** * Register and add Customizer Theme Options panel. */ add_action( 'customize_register', function( $wp_customize ) { $attrs = array( 'priority' => 180, 'capability' => 'edit_theme_options', 'title' => __( 'Theme Options', 'athlonx' ), 'desc' => __( 'AthlonX theme options pane.', 'athlonx' ), 'panel' => '', 'description_hidden' => true, ); call_user_func_array( array( $wp_customize, 'add_section' ), array( 'athlonx_theme_options', $attrs ) ); }, 10, 1 ); /** * Register and add Customizer Theme Options (and other) secondary modification variables. */ add_action( 'customize_register', function( $wp_customize ) { // Header title (inside 'Header Image' panel). $wp_customize_control['athlonx_header_title'] = new \WP_Customize_Control( $wp_customize, 'athlonx_header_title', array( 'section' => 'header_image', 'label' => 'Header title', 'description' => '', 'type' => 'text', 'priority' => 10, 'setting' => $wp_customize->add_setting( 'athlonx_header_title', array( 'default' => get_bloginfo( 'name' ), 'transport' => 'refresh', 'sanitize_callback' => 'esc_html', ) ) ) ); // Hedaer text (inside 'Header Image' panel). $wp_customize_control['athlonx_header_text'] = new \WP_Customize_Control( $wp_customize, 'athlonx_header_text', array( 'section' => 'header_image', 'label' => 'Header text', 'description' => '', 'type' => 'text', 'priority' => 10, 'setting' => $wp_customize->add_setting( 'athlonx_header_text', array( 'default' => get_bloginfo( 'description' ), 'transport' => 'refresh', 'sanitize_callback' => 'esc_html', ) ) ) ); // Header button text (inside 'Header Image' panel). $wp_customize_control['athlonx_header_button_text'] = new \WP_Customize_Control( $wp_customize, 'athlonx_header_button_text', array( 'section' => 'header_image', 'label' => 'Header button', 'description' => 'Enter target button text and link.', 'type' => 'text', 'priority' => 10, 'setting' => $wp_customize->add_setting( 'athlonx_header_button_text', array( 'default' => 'Read more...', 'transport' => 'refresh', 'sanitize_callback' => 'esc_html', ) ) ) ); // Header button link (inside 'Header Image' panel). $wp_customize_control['athlonx_header_button_link'] = new \WP_Customize_Control( $wp_customize, 'athlonx_header_button_link', array( 'section' => 'header_image', 'label' => '', 'description' => '', 'type' => 'text', 'priority' => 10, 'setting' => $wp_customize->add_setting( 'athlonx_header_button_link', array( 'default' => esc_url( home_url() ), 'transport' => 'refresh', 'sanitize_callback' => 'esc_html', ) ) ) ); // Color palette (inside 'Theme Options' panel). $wp_customize_control['athlonx_color_palette'] = new \WP_Customize_Control( $wp_customize, 'athlonx_color_palette', array( 'section' => 'athlonx_theme_options', 'label' => 'Color Palette', 'description' => 'Select color palette.', 'type' => 'select', 'choices' => array( 'amber' => 'Amber', 'blue-grey' => 'Blue Grey', 'emerald' => 'Emerald (default)', 'indigo' => 'Indigo', 'teal' => 'Teal', ), 'priority' => 0, 'setting' => $wp_customize->add_setting( 'athlonx_color_palette', array( 'default' => 'emerald', 'transport' => 'postMessage', 'sanitize_callback' => 'esc_html', ) ) ) ); // Font family (inside 'Theme Options' panel). $wp_customize_control['athlonx_font_family'] = new \WP_Customize_Control( $wp_customize, 'athlonx_font_family', array( 'section' => 'athlonx_theme_options', 'label' => 'Font Family', 'description' => 'Select primary font family.', 'type' => 'select', 'choices' => array( 'inconsolata' => 'Inconsolata', 'lato' => 'Lato', 'montserrat' => 'Montserrat (default)', 'merriweather' => 'Merriweather', 'pt sans' => 'PT Sans', 'pt serif' => 'PT Serif', 'poppins' => 'Poppins', 'raleway' => 'Raleway', 'roboto' => 'Roboto', 'ubuntu' => 'Ubuntu', ), 'priority' => 0, 'setting' => $wp_customize->add_setting( 'athlonx_font_family', array( 'default' => 'montserrat', 'transport' => 'postMessage', 'sanitize_callback' => 'esc_html', ) ) ) ); // Body container width (inside 'Theme Options' panel). $wp_customize_control['athlonx_theme_options'] = new \WP_Customize_Control( $wp_customize, 'athlonx_container_width', array( 'section' => 'athlonx_theme_options', 'label' => 'Container Width', 'description' => 'Select body container width.', 'type' => 'select', 'choices' => array( '960' => '960px', '1024' => '1024px', '1200' => '1200px (default)', '1440' => '1440px', '1680' => '1680px', '2000' => '2000px', ), 'priority' => 0, 'setting' => $wp_customize->add_setting( 'athlonx_container_width', array( 'default' => '1200', 'transport' => 'postMessage', 'sanitize_callback' => 'esc_html', ) ) ) ); // Blog sidebar (inside 'Theme Options' panel). $wp_customize_control['athlonx_blog_sidebar'] = new \WP_Customize_Control( $wp_customize, 'athlonx_blog_sidebar', array( 'section' => 'athlonx_theme_options', 'label' => 'Blog sidebar', 'description' => 'Select blog sidebar visibility.', 'type' => 'select', 'choices' => array( 'show' => 'show (default)', 'hide' => 'hide', ), 'priority' => 0, 'setting' => $wp_customize->add_setting( 'athlonx_blog_sidebar', array( 'default' => 'show', 'transport' => 'postMessage', 'sanitize_callback' => 'esc_html', ) ) ) ); foreach ( $wp_customize_control as $uuid => $wp_customize_control_options ) { $wp_customize->add_control( $wp_customize_control_options ); // $wp_customize->selective_refresh->add_partial( $uuid ); } }, 10, 1 ); add_action( 'init', 'athlonx_theme_customize_options' ); /** * Get and define theme Customizer modificaiton variables. */ function athlonx_theme_customize_options() { $theme_version = wp_get_theme()->get( 'Version' ); $color_palette = esc_html( get_theme_mod( 'athlonx_color_palette', false ) ); $font_family = esc_html( get_theme_mod( 'athlonx_font_family', false ) ); $container_width = esc_html( get_theme_mod( 'athlonx_container_width', false ) ); if ( $color_palette ) { add_action( 'wp_enqueue_scripts', function() use( $color_palette, $theme_version ) { wp_dequeue_style( 'athlonx-style' ); wp_enqueue_style( 'athlonx-style', get_template_directory_uri() . '/assets/css/style-' . $color_palette . '.css', array(), $theme_version, 'all' ); }, 1 ); } if ( $font_family ) { add_action( 'wp_enqueue_scripts', function() use( $font_family, $theme_version ) { wp_dequeue_style( 'google-font-style' ); wp_enqueue_style( 'google-font-style', 'https://fonts.googleapis.com/css?family=' . ucwords( $font_family ) . ':300,400,700,900&display=swap', array(), '', 'all' ); wp_add_inline_style( 'athlonx-style', 'html { font-family: ' . ucwords( $font_family ) . ', sans-seif; }' ); }, 1 ); } if ( $container_width ) { add_action( 'wp_enqueue_scripts', function() use( $container_width, $theme_version ) { wp_add_inline_style( 'athlonx-style', '.container { max-width: ' . $container_width . 'px; } div.post .post-meta, div.post .post-related, .alignfull, .post-comments { margin-left: calc((' . $container_width . 'px - 4rem - 100vw) / 2); } .alignwide { margin-left: calc((' . $container_width . 'px - 4rem - 1440px) / 2); } .footer-gallery .container .widgets { width: ' . ( $container_width - 64 ) . 'px; } @media (max-width: 1200px) { div.post .post-meta, div.post .post-related, .alignfull, .alignwide, .post-comments { margin-left: -2rem; } .footer-gallery .container .widgets { width: calc(100% - 4rem); } }' ); }, 1 ); } }