button_service = ButtonService::get_instance(); $this->color_service = ColorService::get_instance(); } public function register_global_colors() { if ( ! is_elementor_installed() ) { return; } $kit_settings = $this->get_settings(); if ( empty( $kit_settings ) ) { return; } $system_colors = $kit_settings['system_colors']; if ( empty( $system_colors ) ) { return; } foreach ( $this->get_external_colors_definition() as $color_definition ) { $search_position = array_search( $color_definition['_id'], array_column( $system_colors, '_id' ), true ); if ( false === $search_position ) { $system_colors[] = $color_definition; } else { $system_colors[ $search_position ] = $color_definition; } } $kit_settings['system_colors'] = $system_colors; $this->save_settings( $kit_settings ); } public function get_current_kit() { return \Elementor\Plugin::$instance->kits_manager->get_active_kit_for_frontend(); } public function get_settings() { $kit = $this->get_current_kit(); if ( empty( $kit ) ) { return null; } return $kit->get_settings(); } public function save_settings( $settings ) { $kit = $this->get_current_kit(); if ( empty( $kit ) ) { return; } $kit->save( array( 'settings' => $settings, ) ); } private function get_external_colors_definition() { $brandy_colors = brandy_get_theme_palette(); $button_settings = brandy_get_button_settings(); return array_merge( array_map( function( $n ) use ( $brandy_colors ) { return array( '_id' => "brandy_palette_$n", // Translators: %s Palette number. 'title' => sprintf( __( 'Brandy Palette %s', 'brandy' ), $n ), 'color' => $brandy_colors[ "palette_$n" ], ); }, array( 1, 2, 3, 4, 5, 6, 7, 8 ) ), array( array( '_id' => 'brandy_accent', 'title' => __( 'Brandy Accent', 'brandy' ), 'color' => brandy_get_reality_color( $brandy_colors['accent'] ), ), array( '_id' => 'brandy_body_primary', 'title' => __( 'Brandy Body Text Primary', 'brandy' ), 'color' => brandy_get_reality_color( $brandy_colors['body_text']['primary'] ), ), array( '_id' => 'brandy_body_secondary', 'title' => __( 'Brandy Body Text Secondary', 'brandy' ), 'color' => brandy_get_reality_color( $brandy_colors['body_text']['secondary'] ), ), array( '_id' => 'brandy_link_normal', 'title' => __( 'Brandy Link Normal', 'brandy' ), 'color' => brandy_get_reality_color( $brandy_colors['links']['normal'] ), ), array( '_id' => 'brandy_link_hover', 'title' => __( 'Brandy Link Hover', 'brandy' ), 'color' => brandy_get_reality_color( $brandy_colors['links']['hover'] ), ), array( '_id' => 'brandy_heading', 'title' => __( 'Brandy Heading', 'brandy' ), 'color' => brandy_get_reality_color( $brandy_colors['heading'] ), ), array( '_id' => 'brandy_button_color_normal', 'title' => __( 'Brandy Button Color Normal', 'brandy' ), 'color' => brandy_get_reality_color( $button_settings['primary']['color']['normal'] ), ), array( '_id' => 'brandy_button_color_hover', 'title' => __( 'Brandy Button Color Hover', 'brandy' ), 'color' => brandy_get_reality_color( $button_settings['primary']['color']['hover'] ), ), array( '_id' => 'brandy_button_background_normal', 'title' => __( 'Brandy Button Background Normal', 'brandy' ), 'color' => brandy_get_reality_color( $button_settings['primary']['background']['normal'] ), ), array( '_id' => 'brandy_button_background_hover', 'title' => __( 'Brandy Button Background Hover', 'brandy' ), 'color' => brandy_get_reality_color( $button_settings['primary']['background']['hover'] ), ), ), array_map( function( $n ) use ( $brandy_colors ) { return array( '_id' => "brandy_heading_$n", // Translators: %s Heading number. 'title' => sprintf( __( 'Brandy Heading %s', 'brandy' ), $n ), 'color' => empty( $brandy_colors[ "heading_$n" ] ) ? $brandy_colors['heading'] : $brandy_colors[ "heading_$n" ], ); }, array( 1, 2, 3, 4, 5, 6 ) ) ); } public function override_button_settings( &$kit_settings ) { $brandy_border_radius = brandy_get_primary_button_border_radius(); $padding = brandy_get_primary_button_padding(); $border_radius = array( 'unit' => $brandy_border_radius['unit'], 'top' => $brandy_border_radius['value'], 'left' => $brandy_border_radius['value'], 'right' => $brandy_border_radius['value'], 'bottom' => $brandy_border_radius['value'], ); $kit_settings['button_border_radius'] = $border_radius; $kit_settings['button_hover_border_radius'] = $border_radius; $kit_settings['button_padding'] = $padding; $kit_settings['__globals__']['button_text_color'] = 'globals/colors?id=brandy_button_color_normal'; $kit_settings['__globals__']['button_hover_text_color'] = 'globals/colors?id=brandy_button_color_hover'; $kit_settings['__globals__']['button_background_color'] = 'globals/colors?id=brandy_button_background_normal'; $kit_settings['__globals__']['button_hover_background_color'] = 'globals/colors?id=brandy_button_background_hover'; } public function override_kit_settings( $sync_items = array( 'button' ) ) { if ( ! is_elementor_installed() ) { return; } $kit_settings = $this->get_settings(); if ( in_array( 'button', $sync_items, true ) ) { $this->override_button_settings( $kit_settings ); } $this->save_settings( $kit_settings ); } }