init_hooks(); } /** * Inizializza gli hook di WordPress */ private function init_hooks() { // Hook per l'admin add_action('admin_menu', array($this, 'add_admin_menu')); add_action('admin_init', array($this, 'register_settings')); add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts')); // Hook per il frontend add_action('wp_enqueue_scripts', array($this, 'enqueue_chatbot_script')); // Hook per i link del plugin add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'add_plugin_action_links')); } /** * Aggiunge il menu di amministrazione */ public function add_admin_menu() { add_options_page( __('AgentoWine Chatbot', 'agentowine-chatbot'), __('AgentoWine Chatbot', 'agentowine-chatbot'), 'manage_options', 'agentowine-chatbot', array($this, 'render_settings_page') ); } /** * Registra le impostazioni */ public function register_settings() { // Registra Client ID register_setting( 'agentowine_chatbot_settings', 'agentowine_chatbot_client_id', array( 'type' => 'string', 'sanitize_callback' => 'sanitize_text_field', 'default' => '' ) ); // Registra Posizione register_setting( 'agentowine_chatbot_settings', 'agentowine_chatbot_position', array( 'type' => 'string', 'sanitize_callback' => array($this, 'sanitize_position'), 'default' => 'bottom-right' ) ); // Registra Posizione Personalizzata (abilitata/disabilitata) register_setting( 'agentowine_chatbot_settings', 'agentowine_chatbot_custom_position', array( 'type' => 'boolean', 'sanitize_callback' => array($this, 'sanitize_custom_position_enabled'), 'default' => false ) ); // Registra coordinate Desktop register_setting( 'agentowine_chatbot_settings', 'agentowine_chatbot_custom_position_desktop', array( 'type' => 'array', 'sanitize_callback' => array($this, 'sanitize_position_coords'), 'default' => array('top' => '', 'bottom' => '24', 'left' => '', 'right' => '24') ) ); // Registra coordinate Mobile register_setting( 'agentowine_chatbot_settings', 'agentowine_chatbot_custom_position_mobile', array( 'type' => 'array', 'sanitize_callback' => array($this, 'sanitize_position_coords'), 'default' => array('top' => '', 'bottom' => '16', 'left' => '', 'right' => '16') ) ); add_settings_section( 'agentowine_chatbot_main_section', __('Configurazione Chatbot', 'agentowine-chatbot'), array($this, 'render_section_description'), 'agentowine-chatbot' ); add_settings_field( 'agentowine_chatbot_client_id', __('Client ID', 'agentowine-chatbot'), array($this, 'render_client_id_field'), 'agentowine-chatbot', 'agentowine_chatbot_main_section' ); add_settings_field( 'agentowine_chatbot_position', __('Posizione', 'agentowine-chatbot'), array($this, 'render_position_field'), 'agentowine-chatbot', 'agentowine_chatbot_main_section' ); } /** * Sanitizza il valore della posizione */ public function sanitize_position($value) { $valid_positions = array('bottom-right', 'bottom-left', 'top-right', 'top-left', 'custom'); return in_array($value, $valid_positions) ? $value : 'bottom-right'; } /** * Sanitizza il flag posizione personalizzata */ public function sanitize_custom_position_enabled($value) { return (bool) $value; } /** * Sanitizza le coordinate di posizione (desktop o mobile) */ public function sanitize_position_coords($value) { if (!is_array($value)) { return array('top' => '', 'bottom' => '24', 'left' => '', 'right' => '24'); } $sanitized = array(); foreach (array('top', 'bottom', 'left', 'right') as $key) { $val = isset($value[$key]) ? trim($value[$key]) : ''; if ($val === '') { $sanitized[$key] = ''; } else { $num = intval($val); $sanitized[$key] = $num >= 0 ? (string) $num : ''; } } return $sanitized; } /** * Descrizione della sezione */ public function render_section_description() { echo '
' . esc_html__('Inserisci il tuo Client ID per attivare il chatbot AgentoWine sul tuo sito.', 'agentowine-chatbot') . '
'; } /** * Campo Client ID */ public function render_client_id_field() { $client_id = get_option('agentowine_chatbot_client_id', ''); ?>'', 'bottom' => '24', 'left' => '', 'right' => '24')); $mobile = get_option('agentowine_chatbot_custom_position_mobile', array('top' => '', 'bottom' => '16', 'left' => '', 'right' => '16')); $positions = array( 'bottom-right' => __('In basso a destra', 'agentowine-chatbot'), 'bottom-left' => __('In basso a sinistra', 'agentowine-chatbot'), 'top-right' => __('In alto a destra', 'agentowine-chatbot'), 'top-left' => __('In alto a sinistra', 'agentowine-chatbot'), ); ?> />
Desktop: $v) { if ($v !== '') $parts[] = "$k: {$v}px"; }
echo esc_html(implode(', ', $parts) ?: '—');
?>
Mobile: $v) { if ($v !== '') $parts[] = "$k: {$v}px"; }
echo esc_html(implode(', ', $parts) ?: '—');
?>