'; $html .= '' . esc_html( $label ) . ''; return $html; } function r1_chat_button_get_brand_button_style( $key, $button, $options ) { if ( empty( $options['enable_brand_icon_colors'] ) ) { return ''; } if ( empty( $button['enabled'] ) || empty( $button['href'] ) ) { return ''; } $brands = array( 'whatsapp' => array( 'bg' => '#25D366', 'icon' => '#ffffff', 'bg_hover' => '#1ebe5d', ), 'fb_messenger' => array( 'bg' => '#0084FF', 'icon' => '#ffffff', 'bg_hover' => '#006fe0', ), 'viber' => array( 'bg' => '#7360F2', 'icon' => '#ffffff', 'bg_hover' => '#5f4de0', ), 'telegram' => array( 'bg' => '#27A7E7', 'icon' => '#ffffff', 'bg_hover' => '#1d96d6', ), 'wechat' => array( 'bg' => '#07C160', 'icon' => '#ffffff', 'bg_hover' => '#06ad56', ), 'line' => array( 'bg' => '#06C755', 'icon' => '#ffffff', 'bg_hover' => '#05b94f', ), 'signal' => array( 'bg' => '#3A76F0', 'icon' => '#ffffff', 'bg_hover' => '#2f67dc', ), 'vk' => array( 'bg' => '#0077FF', 'icon' => '#ffffff', 'bg_hover' => '#006ae6', ), 'kakaotalk' => array( 'bg' => '#FEE500', 'icon' => '#191919', 'bg_hover' => '#ead400', ), 'max' => array( 'bg' => '#7c4dff', 'icon' => '#ffffff', 'bg_hover' => '#6d3ef2', ), ); if ( empty( $brands[ $key ] ) ) { return ''; } $brand = $brands[ $key ]; $style = '--r1-chat-social-icon-bg-color:' . $brand['bg'] . ';'; $style .= '--r1-chat-social-icon-bg-hover-color:' . $brand['bg_hover'] . ';'; $style .= '--r1-chat-social-icon-color:' . $brand['icon'] . ';'; $style .= '--r1-chat-social-icon-hover-color:' . $brand['icon'] . ';'; return $style; } function r1_chat_button_get_button_items( $options ) { $email_link = ! empty( $options['email_link'] ) ? r1_chat_button_parse_email_link( $options['email_link'] ) : ''; $phone_link = ! empty( $options['phone_link'] ) ? r1_chat_button_parse_phone_link( $options['phone_link'] ) : ''; $whatsapp_link = ! empty( $options['whatsapp_link'] ) ? r1_chat_button_parse_dynamic_link( $options['whatsapp_link'] ) : ''; $fb_messenger_link = ! empty( $options['fb_messenger_link'] ) ? r1_chat_button_parse_dynamic_link( $options['fb_messenger_link'] ) : ''; $viber_link = ! empty( $options['viber_link'] ) ? r1_chat_button_parse_dynamic_link( $options['viber_link'] ) : ''; $telegram_link = ! empty( $options['telegram_link'] ) ? r1_chat_button_parse_dynamic_link( $options['telegram_link'] ) : ''; $wechat_link = ! empty( $options['wechat_link'] ) ? r1_chat_button_parse_dynamic_link( $options['wechat_link'] ) : ''; $line_link = ! empty( $options['line_link'] ) ? r1_chat_button_parse_dynamic_link( $options['line_link'] ) : ''; $signal_link = ! empty( $options['signal_link'] ) ? r1_chat_button_parse_dynamic_link( $options['signal_link'] ) : ''; $vk_link = ! empty( $options['vk_link'] ) ? r1_chat_button_parse_dynamic_link( $options['vk_link'] ) : ''; $kakaotalk_link = ! empty( $options['kakaotalk_link'] ) ? r1_chat_button_parse_dynamic_link( $options['kakaotalk_link'] ) : ''; $max_link = ! empty( $options['max_link'] ) ? r1_chat_button_parse_dynamic_link( $options['max_link'] ) : ''; $buttons = array( 'email' => array( 'key' => 'email', 'enabled' => ! empty( $options['enable_email'] ) && ! empty( $email_link ), 'href' => $email_link, 'class' => 'email-icon', 'icon' => 'assets/img/email.svg', 'label' => esc_html__( 'Email', '1r-chat-button' ), 'blank' => false, ), 'phone' => array( 'key' => 'phone', 'enabled' => ! empty( $options['enable_phone'] ) && ! empty( $phone_link ), 'href' => $phone_link, 'class' => 'phone-icon', 'icon' => 'assets/img/phone.svg', 'label' => esc_html__( 'Phone', '1r-chat-button' ), 'blank' => false, ), 'whatsapp' => array( 'key' => 'whatsapp', 'enabled' => ! empty( $options['enable_whatsapp'] ) && ! empty( $whatsapp_link ), 'href' => $whatsapp_link, 'class' => 'wa-icon', 'icon' => 'assets/img/whatsapp.svg', 'label' => esc_html__( 'WhatsApp', '1r-chat-button' ), 'blank' => true, ), 'fb_messenger' => array( 'key' => 'fb_messenger', 'enabled' => ! empty( $options['enable_fb_messenger'] ) && ! empty( $fb_messenger_link ), 'href' => $fb_messenger_link, 'class' => 'fb-messenger-icon', 'icon' => 'assets/img/fb-messenger.svg', 'label' => esc_html__( 'Facebook Messenger', '1r-chat-button' ), 'blank' => true, ), 'viber' => array( 'key' => 'viber', 'enabled' => ! empty( $options['enable_viber'] ) && ! empty( $viber_link ), 'href' => $viber_link, 'class' => 'viber-icon', 'icon' => 'assets/img/viber.svg', 'label' => esc_html__( 'Viber', '1r-chat-button' ), 'blank' => true, ), 'telegram' => array( 'key' => 'telegram', 'enabled' => ! empty( $options['enable_telegram'] ) && ! empty( $telegram_link ), 'href' => $telegram_link, 'class' => 'tg-icon', 'icon' => 'assets/img/telegram.svg', 'label' => esc_html__( 'Telegram', '1r-chat-button' ), 'blank' => true, ), 'wechat' => array( 'key' => 'wechat', 'enabled' => ! empty( $options['enable_wechat'] ) && ! empty( $wechat_link ), 'href' => $wechat_link, 'class' => 'wechat-icon', 'icon' => 'assets/img/wechat.svg', 'label' => esc_html__( 'WeChat', '1r-chat-button' ), 'blank' => true, ), 'line' => array( 'key' => 'line', 'enabled' => ! empty( $options['enable_line'] ) && ! empty( $line_link ), 'href' => $line_link, 'class' => 'line-icon', 'icon' => 'assets/img/line.svg', 'label' => esc_html__( 'Line', '1r-chat-button' ), 'blank' => true, ), 'signal' => array( 'key' => 'signal', 'enabled' => ! empty( $options['enable_signal'] ) && ! empty( $signal_link ), 'href' => $signal_link, 'class' => 'signal-icon', 'icon' => 'assets/img/signal.svg', 'label' => esc_html__( 'Signal', '1r-chat-button' ), 'blank' => true, ), 'vk' => array( 'key' => 'vk', 'enabled' => ! empty( $options['enable_vk'] ) && ! empty( $vk_link ), 'href' => $vk_link, 'class' => 'vk-icon', 'icon' => 'assets/img/vk.svg', 'label' => esc_html__( 'VK', '1r-chat-button' ), 'blank' => true, ), 'kakaotalk' => array( 'key' => 'kakaotalk', 'enabled' => ! empty( $options['enable_kakaotalk'] ) && ! empty( $kakaotalk_link ), 'href' => $kakaotalk_link, 'class' => 'kakaotalk-icon', 'icon' => 'assets/img/kakaotalk.svg', 'label' => esc_html__( 'KakaoTalk', '1r-chat-button' ), 'blank' => true, ), 'max' => array( 'key' => 'max', 'enabled' => ! empty( $options['enable_max'] ) && ! empty( $max_link ), 'href' => $max_link, 'class' => 'max-icon', 'icon' => 'assets/img/max.svg', 'label' => esc_html__( 'MAX', '1r-chat-button' ), 'blank' => true, ), ); return apply_filters( 'r1_chat_button_front_button_items', $buttons, $options ); } function r1_chat_button_front_has_any_buttons( $options ) { $buttons = r1_chat_button_get_button_items( $options ); foreach ( $buttons as $button ) { if ( ! empty( $button['enabled'] ) && ! empty( $button['href'] ) ) { return true; } } return false; } function r1_chat_button_enqueue_front() { if ( is_admin() ) { return; } $options = r1_chat_button_get_merged_options(); if ( ! r1_chat_button_front_has_any_buttons( $options ) ) { return; } $plugin_file = r1_chat_button_get_plugin_file(); $css_rel = 'assets/css/style.css'; $css_abs = plugin_dir_path( $plugin_file ) . $css_rel; $css_ver = file_exists( $css_abs ) ? filemtime( $css_abs ) : R1_CHAT_BUTTON_VERSION; wp_enqueue_style( 'r1-chat-button-front', plugins_url( $css_rel, $plugin_file ), array(), $css_ver ); $js_rel = 'assets/js/front.js'; $js_abs = plugin_dir_path( $plugin_file ) . $js_rel; $js_ver = file_exists( $js_abs ) ? filemtime( $js_abs ) : R1_CHAT_BUTTON_VERSION; wp_enqueue_script( 'r1-chat-button-front-js', plugins_url( $js_rel, $plugin_file ), array(), $js_ver, true ); } add_action( 'wp_enqueue_scripts', 'r1_chat_button_enqueue_front', 20 ); function r1_chat_button_build_wrapper_style( $options ) { $style = ''; $offset_top = isset( $options['offset_top'] ) ? trim( (string) $options['offset_top'] ) : ''; $offset_right = isset( $options['offset_right'] ) ? trim( (string) $options['offset_right'] ) : ''; $offset_bottom = isset( $options['offset_bottom'] ) ? trim( (string) $options['offset_bottom'] ) : ''; $offset_left = isset( $options['offset_left'] ) ? trim( (string) $options['offset_left'] ) : ''; $use_top = false; if ( '' !== $offset_top ) { $top_check = strtolower( $offset_top ); if ( '0' !== $top_check && '0px' !== $top_check ) { $use_top = true; } } if ( $use_top ) { $style .= 'top:' . $offset_top . ';'; $style .= 'bottom:auto;'; } else { $style .= 'top:auto;'; $style .= 'bottom:' . ( '' !== $offset_bottom ? $offset_bottom : '90px' ) . ';'; } $side = ( ! empty( $options['side'] ) && 'left' === $options['side'] ) ? 'left' : 'right'; if ( 'left' === $side ) { $style .= 'left:' . ( '' !== $offset_left ? $offset_left : '20px' ) . ';'; $style .= 'right:auto;'; } else { $style .= 'right:' . ( '' !== $offset_right ? $offset_right : '20px' ) . ';'; $style .= 'left:auto;'; } $main_button_icon_color = r1_chat_button_get_color_option( $options, 'main_button_icon_color', '#ffffff' ); $main_button_bg_color = r1_chat_button_get_color_option( $options, 'main_button_bg_color', '#0a95ae' ); $main_button_bg_hover_color = r1_chat_button_get_color_option( $options, 'main_button_bg_hover_color', '#177496' ); $social_icon_color = r1_chat_button_get_color_option( $options, 'social_icon_color', '#ffffff' ); $social_icon_bg_color = r1_chat_button_get_color_option( $options, 'social_icon_bg_color', '#a466e2' ); $social_icon_bg_hover_color = r1_chat_button_get_color_option( $options, 'social_icon_bg_hover_color', '#8c3ddb' ); $button_radius = ! empty( $options['button_radius'] ) ? trim( (string) $options['button_radius'] ) : '10px'; $style .= '--r1-chat-main-button-icon-color:' . $main_button_icon_color . ';'; $style .= '--r1-chat-main-button-bg-color:' . $main_button_bg_color . ';'; $style .= '--r1-chat-main-button-bg-hover-color:' . $main_button_bg_hover_color . ';'; $style .= '--r1-chat-social-icon-color:' . $social_icon_color . ';'; $style .= '--r1-chat-social-icon-hover-color:' . $social_icon_color . ';'; $style .= '--r1-chat-social-icon-bg-color:' . $social_icon_bg_color . ';'; $style .= '--r1-chat-social-icon-bg-hover-color:' . $social_icon_bg_hover_color . ';'; $style .= '--r1-chat-button-radius:' . $button_radius . ';'; return $style; } function r1_chat_button_get_button_link_html( $button, $options = array() ) { if ( empty( $button['enabled'] ) || empty( $button['href'] ) ) { return ''; } $attrs = ''; $style = ''; if ( ! empty( $button['blank'] ) ) { $attrs .= ' target="_blank" rel="noopener noreferrer"'; } if ( ! empty( $button['key'] ) ) { $style = r1_chat_button_get_brand_button_style( $button['key'], $button, $options ); } $style_attr = '' !== $style ? ' style="' . esc_attr( $style ) . '"' : ''; $html = ''; $html .= r1_chat_button_get_icon_markup( $button['icon'], $button['label'] ); $html .= ''; return $html; } function r1_chat_button_render_button_link( $button, $options = array() ) { echo wp_kses( r1_chat_button_get_button_link_html( $button, $options ), array( 'a' => array( 'href' => true, 'class' => true, 'target' => true, 'rel' => true, 'style' => true, ), 'span' => array( 'class' => true, 'style' => true, 'aria-hidden' => true, ), ) ); } function r1_chat_button_footer_render() { $options = r1_chat_button_get_merged_options(); if ( ! r1_chat_button_front_has_any_buttons( $options ) ) { return; } $style = r1_chat_button_build_wrapper_style( $options ); $style_attr = '' !== $style ? ' style="' . esc_attr( $style ) . '"' : ''; $side = ( ! empty( $options['side'] ) && 'left' === $options['side'] ) ? 'left' : 'right'; $side_class = ( 'left' === $side ) ? ' is-left' : ' is-right'; $pulse = ! empty( $options['enable_main_button_pulse'] ) ? ' has-pulse' : ''; $order = isset( $options['buttons_order'] ) && '' !== $options['buttons_order'] ? array_map( 'trim', explode( ',', $options['buttons_order'] ) ) : r1_chat_button_get_default_order(); $order = array_map( 'r1_chat_button_normalize_button_key', $order ); $buttons = r1_chat_button_get_button_items( $options ); $html = '