load_classes(); add_action( 'customize_controls_print_scripts', array( $this, 'controls_enqueue_scripts' ) ); add_action( 'customize_save_after', function() { if ( ! isset( $_POST['nonce'] ) ) { return; } if ( ! wp_verify_nonce( sanitize_text_field( $_POST['nonce'] ), 'save-customize_' . wp_get_theme()->get_stylesheet() ) ) { return; } if ( isset( $_POST['header_settings'] ) ) { brandy_save_header_settings( json_decode( wp_unslash( $_POST['header_settings'] ), true ) ); } if ( isset( $_POST['footer_settings'] ) ) { brandy_save_footer_settings( json_decode( wp_unslash( $_POST['footer_settings'] ), true ) ); } } ); add_filter( 'gettext', function( $translation, $text ) { if ( 'Shift-click to edit this element.' === $text ) { return ''; } return $translation; }, PHP_INT_MAX, 2 ); add_action( 'customize_register', array( $this, 'remove_unused_customizer_panel' ) ); } private function load_classes() { /** * Require partials process */ PartialsLoader::get_instance(); /** * Register panels. */ HeaderPanel::get_instance(); FooterPanel::get_instance(); GeneralPanel::get_instance(); WooCommercePanel::get_instance(); do_action( 'brandy_register_customizer_panels' ); do_action( 'brandy_after_register_customizer_panels' ); /** * Require element process class */ ElementsLoader::get_instance(); /** * Require loading settings */ HeaderSettings::get_instance(); HeaderRowSettings::get_instance(); FooterSettings::get_instance(); FooterRowSettings::get_instance(); ToggleOffCanvasSettings::get_instance(); } private function get_localize_data() { $exclude_pages = function_exists( 'wc_get_page_id' ) ? array( \wc_get_page_id( 'cart' ), \wc_get_page_id( 'checkout' ), \wc_get_page_id( 'myaccount' ), ) : array(); $pages = get_pages( array( 'post_type' => 'page', 'post_status' => 'publish,private,draft', 'child_of' => 0, 'parent' => -1, 'exclude' => $exclude_pages, 'sort_order' => 'asc', 'sort_column' => 'post_title', ) ); $page_choices = array( '' => array( 'title' => __( 'No page set', 'brandy' ),//phpcs:ignore 'link' => '#', ), ) + array_combine( array_map( 'strval', wp_list_pluck( $pages, 'ID' ) ), array_map( function( $p ) { return array( 'title' => $p->post_title, 'link' => get_page_link( $p->ID ), ); }, $pages ) ); if ( function_exists( 'wc_get_products' ) ) { $sample_products = \wc_get_products( array( 'limit' => 1 ) ); } $data = array( 'ajax' => array( 'path' => admin_url( 'admin-ajax.php' ), 'nonces' => array( 'override_elementor_settings' => wp_create_nonce( 'override_elementor_settings' ), ), ), 'rtl' => is_rtl(), 'paths' => array( 'nav_menu' => admin_url( 'nav-menus.php' ), 'wc_checkout_page' => brandy_get_checkout_page_url(), 'wc_cart_page' => brandy_get_cart_page_url(), 'wc_shop_page' => brandy_get_shop_page_url(), 'wc_single_product_page' => empty( $sample_products ) ? '#' : $sample_products[0]->get_permalink(), ), 'colors' => array( 'icon' => array( 'normal' => BRANDY_ICON_COLOR_NORMAL, ), ), 'content_variables' => StringVariablesService::get_data(), 'pages' => $page_choices, 'i18n' => I18n::get_translations(), 'theme_settings' => wp_get_global_settings(), 'extra_panels' => apply_filters( 'brandy_customizer_extra_panels', array() ), 'defaults' => array( 'header' => apply_filters( 'brandy_default_header_settings', HeaderPanel::get_default_template() ), 'footer' => apply_filters( 'brandy_default_footer_settings', FooterPanel::get_default_template() ), ), // 'header_settings' => $header_settings, // 'footer_settings' => $footer_settings, // 'presets' => array( // 'header' => HeaderPanel::get_preset_settings(), // 'footer' => FooterPanel::get_preset_settings(), // ), ); return apply_filters( 'brandy_extra_localize', $data ); } /** * Enqueue scripts/styles for controller in customize page */ public function controls_enqueue_scripts() { wp_enqueue_style( 'dashicons' ); wp_enqueue_media(); wp_enqueue_editor(); if ( is_admin() ) { \_WP_Editors::print_default_editor_scripts(); } wp_add_inline_script( 'wp-customize-widgets', 'var customizeWidgetInitialize = wp.customizeWidgets.initialize;' . 'wp.customizeWidgets = {initialize: function (a, b) { window.brandyWidgetsEditorName = a window.brandyWidgetsBlockEditorSettings = b customizeWidgetInitialize(a, b) }}' ); CustomizerVite::enqueue_vite( 'main.tsx', '3003' ); wp_localize_script( 'module/brandy/main.tsx', 'brandyCustomizerData', $this->get_localize_data() ); wp_localize_script( 'module/brandy/main.tsx', 'brandyHeaderPresets', HeaderPanel::get_preset_settings() ); wp_localize_script( 'module/brandy/main.tsx', 'brandyFooterPresets', FooterPanel::get_preset_settings() ); $header_settings = brandy_get_header_settings(); $footer_settings = brandy_get_footer_settings(); wp_localize_script( 'module/brandy/main.tsx', 'brandyHeaderSettings', $header_settings ); wp_localize_script( 'module/brandy/main.tsx', 'brandyFooterSettings', $footer_settings ); wp_localize_script( 'module/brandy/main.tsx', 'brandySettingsLayouts', BuilderService::get_settings_layouts() ); wp_localize_script( 'module/brandy/main.tsx', 'brandyDefaultHeaderStyles', $this->get_default_header_menu_styles() ); brandy_update_unsaved_header_settings( $header_settings ); brandy_update_unsaved_footer_settings( $footer_settings ); } private function get_default_header_menu_styles() { $default_styles = array(); $path_to_menu_styles = BRANDY_TEMPLATE_DIR . '/inc/Niches/WooCommerce/sample-data/sample-header-menu-styles.json'; if ( file_exists( $path_to_menu_styles ) ) { $default_styles = file_get_contents( $path_to_menu_styles ); $default_styles = json_decode( $default_styles, true ); } return apply_filters( 'brandy_default_header_menu_styles', $default_styles ); } public function remove_unused_customizer_panel( $manager ) { $remove_sections = array( 'colors', 'header_image', 'background_image' ); foreach ( $remove_sections as $section_id ) { $manager->remove_section( $section_id ); } } } CustomizerLoader::get_instance();