get_customizer_configurations( $wp_customize ); foreach ( $configurations as $key => $config ) { $config = wp_parse_args( $config, $this->get_astra_customizer_configuration_defaults() ); switch ( $config['type'] ) { case 'panel': // Remove type from configuration. unset( $config['type'] ); $this->register_panel( $config, $wp_customize ); break; case 'section': // Remove type from configuration. unset( $config['type'] ); $this->register_section( $config, $wp_customize ); break; case 'sub-control': // Remove type from configuration. unset( $config['type'] ); $this->register_sub_control_setting( $config, $wp_customize ); break; case 'control': // Remove type from configuration. unset( $config['type'] ); $this->register_setting_control( $config, $wp_customize ); break; } } } /** * Check if string is start with a string provided. * * @param string $string main string. * @param string $start_string string to search. * @since 2.0.0 * @return bool. */ public function starts_with( $string, $start_string ) { $len = strlen( $start_string ); return ( substr( $string, 0, $len ) === $start_string ); } /** * Filter and return Customizer Configurations. * * @param WP_Customize_Manager $wp_customize Reference to WP_Customize_Manager. * @since 1.4.3 * @return Array Customizer Configurations for registering Sections/Panels/Controls. */ private function get_customizer_configurations( $wp_customize ) { if ( ! is_null( self::$configuration ) ) { return self::$configuration; } return apply_filters( 'astra_customizer_configurations', array(), $wp_customize ); } /** * Return default values for the Customize Configurations. * * @since 1.4.3 * @return Array default values for the Customizer Configurations. */ private function get_astra_customizer_configuration_defaults() { return apply_filters( 'astra_customizer_configuration_defaults', array( 'priority' => null, 'title' => null, 'label' => null, 'name' => null, 'type' => null, 'description' => null, 'capability' => null, 'datastore_type' => 'option', // theme_mod or option. Default option. 'settings' => null, 'active_callback' => null, 'sanitize_callback' => null, 'sanitize_js_callback' => null, 'theme_supports' => null, 'transport' => null, 'default' => null, 'selector' => null, 'ast_fields' => array(), ) ); } /** * Register Customizer Panel. * * @param Array $config Panel Configuration settings. * @param WP_Customize_Manager $wp_customize instance of WP_Customize_Manager. * @since 1.4.3 * @return void */ private function register_panel( $config, $wp_customize ) { $wp_customize->add_panel( new Astra_WP_Customize_Panel( $wp_customize, astra_get_prop( $config, 'name' ), $config ) ); } /** * Register Customizer Section. * * @param Array $config Panel Configuration settings. * @param WP_Customize_Manager $wp_customize instance of WP_Customize_Manager. * @since 1.4.3 * @return void */ private function register_section( $config, $wp_customize ) { $callback = astra_get_prop( $config, 'section_callback', 'Astra_WP_Customize_Section' ); $wp_customize->add_section( new $callback( $wp_customize, astra_get_prop( $config, 'name' ), $config ) ); } /** * Register Customizer Control and Setting. * * @param Array $control_config Panel Configuration settings. * @param WP_Customize_Manager $wp_customize instance of WP_Customize_Manager. * @since 2.0.0 * @return void */ private function register_sub_control_setting( $control_config, $wp_customize ) { $sub_control_name = ASTRA_THEME_SETTINGS . '[' . astra_get_prop( $control_config, 'name' ) . ']'; if ( isset( $wp_customize->get_control( $sub_control_name )->id ) ) { return; } $parent = astra_get_prop( $control_config, 'parent' ); $tab = astra_get_prop( $control_config, 'tab' ); if ( empty( self::$group_configs[ $parent ] ) ) { self::$group_configs[ $parent ] = array(); } if ( array_key_exists( 'tab', $control_config ) ) { self::$group_configs[ $parent ]['tabs'][ $tab ][] = $control_config; } else { self::$group_configs[ $parent ][] = $control_config; } $config = array( 'name' => $sub_control_name, 'datastore_type' => 'option', 'transport' => 'postMessage', 'control' => 'ast-hidden', 'section' => astra_get_prop( $control_config, 'section', 'title_tagline' ), 'default' => astra_get_prop( $control_config, 'default' ), 'sanitize_callback' => astra_get_prop( $control_config, 'sanitize_callback', Astra_Customizer_Control_Base::get_sanitize_call( astra_get_prop( $control_config, 'control' ) ) ), ); $wp_customize->add_setting( astra_get_prop( $config, 'name' ), array( 'default' => astra_get_prop( $config, 'default' ), 'type' => astra_get_prop( $config, 'datastore_type' ), 'transport' => astra_get_prop( $config, 'transport', 'refresh' ), 'sanitize_callback' => astra_get_prop( $config, 'sanitize_callback', Astra_Customizer_Control_Base::get_sanitize_call( astra_get_prop( $config, 'control' ) ) ), ) ); $instance = Astra_Customizer_Control_Base::get_control_instance( astra_get_prop( $config, 'control' ) ); if ( false !== $instance ) { $wp_customize->add_control( new $instance( $wp_customize, $sub_control_name, $config ) ); } else { $wp_customize->add_control( $sub_control_name, $config ); } } /** * Register Customizer Control and Setting. * * @param Array $config Panel Configuration settings. * @param WP_Customize_Manager $wp_customize instance of WP_Customize_Manager. * @since 1.4.3 * @return void */ private function register_setting_control( $config, $wp_customize ) { if ( 'ast-settings-group' === $config['control'] ) { $callback = false; } else { $callback = astra_get_prop( $config, 'sanitize_callback', Astra_Customizer_Control_Base::get_sanitize_call( astra_get_prop( $config, 'control' ) ) ); } $wp_customize->add_setting( astra_get_prop( $config, 'name' ), array( 'default' => astra_get_prop( $config, 'default' ), 'type' => astra_get_prop( $config, 'datastore_type' ), 'transport' => astra_get_prop( $config, 'transport', 'refresh' ), 'sanitize_callback' => $callback, ) ); $instance = Astra_Customizer_Control_Base::get_control_instance( astra_get_prop( $config, 'control' ) ); $config['label'] = astra_get_prop( $config, 'title' ); $config['type'] = astra_get_prop( $config, 'control' ); // For ast-font control font-weight and font-family is passed as param `font-type` which needs to be converted to `type`. if ( false !== astra_get_prop( $config, 'font-type', false ) ) { $config['type'] = astra_get_prop( $config, 'font-type', false ); } if ( false !== $instance ) { $wp_customize->add_control( new $instance( $wp_customize, astra_get_prop( $config, 'name' ), $config ) ); } else { $wp_customize->add_control( astra_get_prop( $config, 'name' ), $config ); } if ( astra_get_prop( $config, 'partial', false ) ) { if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( astra_get_prop( $config, 'name' ), array( 'selector' => astra_get_prop( $config['partial'], 'selector' ), 'container_inclusive' => astra_get_prop( $config['partial'], 'container_inclusive' ), 'render_callback' => astra_get_prop( $config['partial'], 'render_callback' ), ) ); } } if ( false !== astra_get_prop( $config, 'required', false ) ) { $this->update_dependency_arr( astra_get_prop( $config, 'name' ), astra_get_prop( $config, 'required' ) ); } } /** * Update dependency in the dependency array. * * @param String $key name of the Setting/Control for which the dependency is added. * @param Array $dependency dependency of the $name Setting/Control. * @since 1.4.3 * @return void */ private function update_dependency_arr( $key, $dependency ) { self::$dependency_arr[ $key ] = $dependency; } /** * Get dependency Array. * * @since 1.4.3 * @return Array Dependencies discovered when registering controls and settings. */ private function get_dependency_arr() { return self::$dependency_arr; } /** * Include Customizer Configuration files. * * @since 1.4.3 * @return void */ public function include_configurations() { require ASTRA_THEME_DIR . 'inc/customizer/configurations/class-astra-customizer-config-base.php'; /** * Register Sections & Panels */ require ASTRA_THEME_DIR . 'inc/customizer/class-astra-customizer-register-sections-panels.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/buttons/class-astra-customizer-button-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/layout/class-astra-site-layout-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/layout/class-astra-header-layout-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/layout/class-astra-site-identity-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/layout/class-astra-blog-layout-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/layout/class-astra-blog-single-layout-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/layout/class-astra-sidebar-layout-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/layout/class-astra-site-container-layout-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/layout/class-astra-footer-layout-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/colors-background/class-astra-body-colors-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/colors-background/class-astra-footer-colors-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/colors-background/class-astra-advanced-footer-colors-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/typography/class-astra-archive-typo-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/typography/class-astra-body-typo-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/typography/class-astra-content-typo-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/typography/class-astra-header-typo-configs.php'; require ASTRA_THEME_DIR . 'inc/customizer/configurations/typography/class-astra-single-typo-configs.php'; } /** * Print Footer Scripts * * @since 1.0.0 * @return void */ public function print_footer_scripts() { $output = ''; echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Register custom section and panel. * * @since 1.0.0 * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ public function customize_register_panel( $wp_customize ) { /** * Register Extended Panel */ $wp_customize->register_panel_type( 'Astra_WP_Customize_Panel' ); $wp_customize->register_section_type( 'Astra_WP_Customize_Section' ); $wp_customize->register_section_type( 'Astra_WP_Customize_Separator' ); if ( ! defined( 'ASTRA_EXT_VER' ) ) { $wp_customize->register_section_type( 'Astra_Pro_Customizer' ); } require ASTRA_THEME_DIR . 'inc/customizer/extend-customizer/class-astra-wp-customize-panel.php'; require ASTRA_THEME_DIR . 'inc/customizer/extend-customizer/class-astra-wp-customize-section.php'; require ASTRA_THEME_DIR . 'inc/customizer/extend-customizer/class-astra-wp-customize-separator.php'; require ASTRA_THEME_DIR . 'inc/customizer/customizer-controls.php'; /** * Add Controls */ Astra_Customizer_Control_Base::add_control( 'color', array( 'callback' => 'WP_Customize_Color_Control', 'sanitize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_hex_color' ), ) ); Astra_Customizer_Control_Base::add_control( 'ast-sortable', array( 'callback' => 'Astra_Control_Sortable', 'sanitize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_multi_choices' ), ) ); Astra_Customizer_Control_Base::add_control( 'ast-radio-image', array( 'callback' => 'Astra_Control_Radio_Image', 'sanitize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_choices' ), ) ); Astra_Customizer_Control_Base::add_control( 'ast-slider', array( 'callback' => 'Astra_Control_Slider', 'sanitize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_number' ), ) ); Astra_Customizer_Control_Base::add_control( 'ast-responsive-slider', array( 'callback' => 'Astra_Control_Responsive_Slider', 'sanitize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_responsive_slider' ), ) ); Astra_Customizer_Control_Base::add_control( 'ast-responsive', array( 'callback' => 'Astra_Control_Responsive', 'sanitize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_responsive_typo' ), ) ); Astra_Customizer_Control_Base::add_control( 'ast-responsive-spacing', array( 'callback' => 'Astra_Control_Responsive_Spacing', 'sanitize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_responsive_spacing' ), ) ); Astra_Customizer_Control_Base::add_control( 'ast-divider', array( 'callback' => 'Astra_Control_Divider', 'sanitize_callback' => '', ) ); Astra_Customizer_Control_Base::add_control( 'ast-heading', array( 'callback' => 'Astra_Control_Heading', 'sanitize_callback' => '', ) ); Astra_Customizer_Control_Base::add_control( 'ast-hidden', array( 'callback' => 'Astra_Control_Hidden', 'sanitize_callback' => '', ) ); Astra_Customizer_Control_Base::add_control( 'ast-link', array( 'callback' => 'Astra_Control_Link', 'sanitize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_link' ), ) ); Astra_Customizer_Control_Base::add_control( 'ast-color', array( 'callback' => 'Astra_Control_Color', 'sanitize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_alpha_color' ), ) ); Astra_Customizer_Control_Base::add_control( 'ast-description', array( 'callback' => 'Astra_Control_Description', 'sanitize_callback' => '', ) ); Astra_Customizer_Control_Base::add_control( 'ast-background', array( 'callback' => 'Astra_Control_Background', 'sanitize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_background_obj' ), ) ); Astra_Customizer_Control_Base::add_control( 'image', array( 'callback' => 'WP_Customize_Image_Control', 'sanitize_callback' => 'esc_url_raw', ) ); Astra_Customizer_Control_Base::add_control( 'ast-font', array( 'callback' => 'Astra_Control_Typography', 'sanitize_callback' => 'sanitize_text_field', ) ); Astra_Customizer_Control_Base::add_control( 'number', array( 'sanitize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_number' ), ) ); Astra_Customizer_Control_Base::add_control( 'ast-border', array( 'callback' => 'Astra_Control_Border', 'santize_callback' => 'sanitize_border', ) ); Astra_Customizer_Control_Base::add_control( 'ast-responsive-color', array( 'callback' => 'Astra_Control_Responsive_Color', 'santize_callback' => 'sanitize_responsive_color', ) ); Astra_Customizer_Control_Base::add_control( 'ast-customizer-link', array( 'callback' => 'Astra_Control_Customizer_Link', 'santize_callback' => array( 'Astra_Customizer_Sanitizes', 'sanitize_customizer_links' ), ) ); Astra_Customizer_Control_Base::add_control( 'ast-settings-group', array( 'callback' => 'Astra_Control_Settings_Group', ) ); Astra_Customizer_Control_Base::add_control( 'ast-select', array( 'callback' => 'Astra_Control_Select', 'sanitize_callback' => '', ) ); /** * Helper files */ require ASTRA_THEME_DIR . 'inc/customizer/class-astra-customizer-partials.php'; require ASTRA_THEME_DIR . 'inc/customizer/class-astra-customizer-callback.php'; require ASTRA_THEME_DIR . 'inc/customizer/class-astra-customizer-sanitizes.php'; } /** * Add postMessage support for site title and description for the Theme Customizer. * * @since 1.0.0 * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ public function customize_register( $wp_customize ) { /** * Override Defaults */ require ASTRA_THEME_DIR . 'inc/customizer/override-defaults.php'; } /** * Add upgrade link configurations controls. * * @since 1.0.0 * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ public function astra_pro_upgrade_configurations( $wp_customize ) { if ( ! defined( 'ASTRA_EXT_VER' ) ) { require ASTRA_THEME_DIR . 'inc/customizer/astra-pro/class-astra-pro-customizer.php'; require ASTRA_THEME_DIR . 'inc/customizer/astra-pro/class-astra-pro-upgrade-link-configs.php'; } } /** * Customizer Controls * * @since 1.0.0 * @return void */ public function controls_scripts() { $js_prefix = '.min.js'; $css_prefix = '.min.css'; $dir = 'minified'; if ( SCRIPT_DEBUG ) { $js_prefix = '.js'; $css_prefix = '.css'; $dir = 'unminified'; } if ( is_rtl() ) { $css_prefix = '.min-rtl.css'; if ( SCRIPT_DEBUG ) { $css_prefix = '-rtl.css'; } } wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( 'astra-color-alpha' ); wp_enqueue_script( 'thickbox' ); wp_enqueue_style( 'thickbox' ); // Customizer Core. wp_enqueue_script( 'astra-customizer-controls-toggle-js', ASTRA_THEME_URI . 'assets/js/' . $dir . '/customizer-controls-toggle' . $js_prefix, array(), ASTRA_THEME_VERSION, true ); // Extended Customizer Assets - Panel extended. wp_enqueue_style( 'astra-extend-customizer-css', ASTRA_THEME_URI . 'assets/css/' . $dir . '/extend-customizer' . $css_prefix, null, ASTRA_THEME_VERSION ); wp_enqueue_script( 'astra-extend-customizer-js', ASTRA_THEME_URI . 'assets/js/' . $dir . '/extend-customizer' . $js_prefix, array(), ASTRA_THEME_VERSION, true ); wp_enqueue_script( 'astra-customizer-dependency', ASTRA_THEME_URI . 'assets/js/' . $dir . '/customizer-dependency' . $js_prefix, array( 'astra-customizer-controls-js' ), ASTRA_THEME_VERSION, true ); // Customizer Controls. wp_enqueue_style( 'astra-customizer-controls-css', ASTRA_THEME_URI . 'assets/css/' . $dir . '/customizer-controls' . $css_prefix, null, ASTRA_THEME_VERSION ); wp_enqueue_script( 'astra-customizer-controls-js', ASTRA_THEME_URI . 'assets/js/' . $dir . '/customizer-controls' . $js_prefix, array( 'astra-customizer-controls-toggle-js' ), ASTRA_THEME_VERSION, true ); $google_fonts = Astra_Font_Families::get_google_fonts(); $string = $this->generate_font_dropdown(); $tmpl = '