get_option('agent700_agent_id', ''), 'hideOverlay' => get_option('agent700_hide_overlay', false), 'layout_type' => get_option('agent700_layout_type', false), )); } } add_action('wp_enqueue_scripts', 'agent700_localize_script'); // Add custom CSS function agent700_custom_css() { // Recuperar opciones con valores predeterminados $primary_color = get_option('agent700_primary_color', '#000000'); $message_title_color = get_option('agent700_message_title_color', '#000000'); $bot_name = get_option('agent700_bot_name', 'Expert'); // Validar y asegurar valores $primary_color = !empty($primary_color) ? esc_attr($primary_color) : '#000000'; $message_title_color = !empty($message_title_color) ? esc_attr($message_title_color) : '#000000'; $bot_name = !empty($bot_name) ? esc_attr($bot_name) : 'Expert'; // Generar CSS dinámico $custom_css = ":root { --primaryColor: {$primary_color}; --messageTitleColor: {$message_title_color}; --botName: \"{$bot_name}\"; }"; // Añadir estilos en línea wp_add_inline_style('agent700-styles', $custom_css); } add_action('wp_enqueue_scripts', 'agent700_custom_css', 20); // Media uploader function agent700_enqueue_admin_scripts($hook_suffix) { if ($hook_suffix === 'settings_page_agent700_chat_settings') { wp_enqueue_media(); wp_enqueue_script('agent700-admin-scripts', plugins_url('scripts/agent-admin.js', __FILE__), array('jquery'), '1.5.0', true); } } add_action('admin_enqueue_scripts', 'agent700_enqueue_admin_scripts'); // Add chat template to the end of the body function agent700_add_chat_to_body() { // Include the chat template (this will always be added) include plugin_dir_path(__FILE__) . 'agent700-chat-template.php'; // Retrieve the value of the checkbox from the settings $use_shortcode = get_option('agent700_use_shortcode', '0'); // Normalize the value: treat an empty string as '0' if ($use_shortcode === '0' || $use_shortcode === '') { // Add the icon when the checkbox is not checked $icon_url = get_option('agent700_chat_icon'); $icon_url = $icon_url ? esc_url($icon_url) : esc_url(plugins_url('assets/chat-agent-icon.png', __FILE__)); echo '
Chat agent icon
'; } } add_action('wp_footer', 'agent700_add_chat_to_body'); // Add admin menu for settings function agent700_add_admin_menu() { add_options_page( 'Agent700 Chat Settings', 'Agent700 Chat', 'manage_options', 'agent700_chat_settings', 'agent700_chat_settings_page' ); } add_action('admin_menu', 'agent700_add_admin_menu'); // Settings page content function agent700_chat_settings_page() { // Process the form submission for the checkbox if (isset($_POST['agent700_settings_submit'])) { check_admin_referer('agent700_settings'); $use_shortcode = isset($_POST['agent700_use_shortcode']) ? '1' : '0'; update_option('agent700_use_shortcode', $use_shortcode); echo '

Settings saved.

'; } // Get the saved checkbox value $use_shortcode = get_option('agent700_use_shortcode', '0'); ?>

Agent700 Chat Settings

Notice: The field "Agent ID" are required. Without valid entries in this field, the plugin will not function.
'string', 'sanitize_callback' => 'sanitize_text_field', )); register_setting('agent700_chat_settings', 'agent700_chat_avatar', array( 'type' => 'string', 'sanitize_callback' => 'esc_url_raw', )); register_setting('agent700_chat_settings', 'agent700_bot_name', array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', )); register_setting('agent700_chat_settings', 'agent700_primary_color', array( 'type' => 'string', 'sanitize_callback' => 'sanitize_hex_color', )); register_setting('agent700_chat_settings', 'agent700_message_title_color', array( 'type' => 'string', 'sanitize_callback' => 'sanitize_hex_color', )); register_setting('agent700_chat_settings', 'agent700_agent_id', array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', )); register_setting('agent700_chat_settings', 'agent700_use_shortcode', array( 'type' => 'boolean', 'sanitize_callback' => 'rest_sanitize_boolean', )); register_setting('agent700_chat_settings', 'agent700_chat_icon', array( 'type' => 'string', 'sanitize_callback' => 'esc_url_raw', )); register_setting('agent700_chat_settings', 'agent700_chat_shortcode', array( 'type' => 'string', 'sanitize_callback' => 'esc_url_raw', )); register_setting('agent700_chat_settings', 'agent700_layout_type', array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'default' => 'popup', )); register_setting('agent700_chat_settings', 'agent700_hide_overlay', array( 'type' => 'boolean', 'sanitize_callback' => 'rest_sanitize_boolean', 'default' => false, )); add_settings_section( 'agent700_chat_section', 'Chat Settings', null, 'agent700_chat_settings' ); add_settings_field('agent700_chat_title', 'Chat Title', 'agent700_chat_title_field_render', 'agent700_chat_settings', 'agent700_chat_section'); add_settings_field('agent700_chat_avatar', 'Chat Avatar', 'agent700_chat_avatar_field_render', 'agent700_chat_settings', 'agent700_chat_section'); add_settings_field('agent700_bot_name', 'Chat Name', 'agent700_bot_name_field_render', 'agent700_chat_settings', 'agent700_chat_section'); add_settings_field('agent700_primary_color', 'Primary Color', 'agent700_primary_color_field_render', 'agent700_chat_settings', 'agent700_chat_section'); add_settings_field('agent700_message_title_color', 'Message Title Color', 'agent700_message_title_color_field_render', 'agent700_chat_settings', 'agent700_chat_section'); add_settings_field('agent700_agent_id', 'Agent ID', 'agent700_agent_id_field_render', 'agent700_chat_settings', 'agent700_chat_section'); add_settings_field('agent700_chat_icon', 'Chat Icon', 'agent700_chat_icon_field_render', 'agent700_chat_settings', 'agent700_chat_section'); add_settings_field('agent700_chat_shortcode', 'Shortcode', 'agent700_chat_shortcode', 'agent700_chat_settings', 'agent700_chat_section'); add_settings_field('agent700_layout_type', 'Layout Type', 'agent700_chat_layout_field_render', 'agent700_chat_settings', 'agent700_chat_section'); add_settings_field('agent700_hide_overlay', 'Hide Overlay', 'agent700_chat_hide_overlay_render', 'agent700_chat_settings', 'agent700_chat_section'); // Only one shortcode checkbox add_settings_field('agent700_use_shortcode', 'Hide chat icon', 'agent700_chat_shortcode_checkbox_render', 'agent700_chat_settings', 'agent700_chat_section'); } add_action('admin_init', 'agent700_register_settings'); // Render the shortcode checkbox field function agent700_chat_shortcode_checkbox_render() { $use_shortcode = get_option('agent700_use_shortcode', '0'); echo ''; } // Register the shortcode add_shortcode('agent700_chat', 'agent700_render_chat_shortcode'); function agent700_render_chat_shortcode() { return '
'; } function agent700_chat_title_field_render() { $value = get_option('agent700_chat_title', 'Agent 700'); echo ""; } function agent700_chat_avatar_field_render() { $avatar_url = get_option('agent700_chat_avatar'); echo ""; echo ""; } function agent700_bot_name_field_render() { $bot_name = get_option('agent700_bot_name', 'Expert'); echo ""; } function agent700_primary_color_field_render() { $color = get_option('agent700_primary_color', '#000000'); echo ''; echo ''; } function agent700_message_title_color_field_render() { $color = get_option('agent700_message_title_color', '#000000'); echo ''; } function agent700_agent_id_field_render() { $agent_id = get_option('agent700_agent_id', ''); echo ""; } function agent700_chat_shortcode() { echo ""; } function agent700_chat_icon_field_render() { $chat_icon = get_option('agent700_chat_icon'); echo ""; echo ""; } function agent700_chat_layout_field_render() { $layout_type = get_option('agent700_layout_type', 'popup'); ?>

Settings'; array_unshift($links, $settings_link); return $links; } add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'agent700_chat_add_link_settings');