1, 'time_trigger' => 12, 'scroll_trigger' => 35, 'reshow_hours' => 24, 'position' => 'bottom-right', 'headline' => __( 'What would you like to do next?', 'adaptive-intent-path' ), 'subtext' => __( 'Choose your intent and we will guide you to the right next step.', 'adaptive-intent-path' ), 'primary_color' => '#2563eb', 'background_color' => '#ffffff', 'text_color' => '#111827', 'buy_label' => __( 'Buy', 'adaptive-intent-path' ), 'buy_url' => '/shop/', 'learn_label' => __( 'Learn more', 'adaptive-intent-path' ), 'learn_url' => '/blog/', 'expert_label' => __( 'Talk to expert', 'adaptive-intent-path' ), 'expert_url' => '/contact/', 'quote_label' => __( 'Get quote', 'adaptive-intent-path' ), 'quote_url' => '/request-a-quote/', ); } public function get_settings() { $saved = get_option( self::OPTION, array() ); return wp_parse_args( is_array( $saved ) ? $saved : array(), self::defaults() ); } public function admin_menu() { add_options_page( __( 'Adaptive Intent Path', 'adaptive-intent-path' ), __( 'Adaptive Intent Path', 'adaptive-intent-path' ), 'manage_options', 'adaptive-intent-path', array( $this, 'settings_page' ) ); } public function register_settings() { register_setting( 'adapinpa_settings_group', self::OPTION, array( 'type' => 'array', 'sanitize_callback' => array( $this, 'sanitize_settings' ), 'default' => self::defaults(), ) ); } public function sanitize_settings( $input ) { $defaults = self::defaults(); $input = is_array( $input ) ? $input : array(); $output = array(); $output['enabled'] = empty( $input['enabled'] ) ? 0 : 1; $output['time_trigger'] = isset( $input['time_trigger'] ) ? max( 1, absint( $input['time_trigger'] ) ) : $defaults['time_trigger']; $output['scroll_trigger'] = isset( $input['scroll_trigger'] ) ? min( 100, max( 1, absint( $input['scroll_trigger'] ) ) ) : $defaults['scroll_trigger']; $output['reshow_hours'] = isset( $input['reshow_hours'] ) ? max( 1, absint( $input['reshow_hours'] ) ) : $defaults['reshow_hours']; $output['position'] = isset( $input['position'] ) && in_array( $input['position'], array( 'bottom-right', 'bottom-left', 'center' ), true ) ? $input['position'] : $defaults['position']; $output['headline'] = isset( $input['headline'] ) ? sanitize_text_field( wp_unslash( $input['headline'] ) ) : $defaults['headline']; $output['subtext'] = isset( $input['subtext'] ) ? sanitize_textarea_field( wp_unslash( $input['subtext'] ) ) : $defaults['subtext']; $output['primary_color'] = isset( $input['primary_color'] ) ? sanitize_hex_color( wp_unslash( $input['primary_color'] ) ) : $defaults['primary_color']; $output['background_color'] = isset( $input['background_color'] ) ? sanitize_hex_color( wp_unslash( $input['background_color'] ) ) : $defaults['background_color']; $output['text_color'] = isset( $input['text_color'] ) ? sanitize_hex_color( wp_unslash( $input['text_color'] ) ) : $defaults['text_color']; $output['primary_color'] = $output['primary_color'] ? $output['primary_color'] : $defaults['primary_color']; $output['background_color'] = $output['background_color'] ? $output['background_color'] : $defaults['background_color']; $output['text_color'] = $output['text_color'] ? $output['text_color'] : $defaults['text_color']; foreach ( array( 'buy', 'learn', 'expert', 'quote' ) as $intent ) { $label_key = $intent . '_label'; $url_key = $intent . '_url'; $output[ $label_key ] = isset( $input[ $label_key ] ) ? sanitize_text_field( wp_unslash( $input[ $label_key ] ) ) : $defaults[ $label_key ]; $output[ $url_key ] = isset( $input[ $url_key ] ) ? esc_url_raw( wp_unslash( $input[ $url_key ] ) ) : $defaults[ $url_key ]; } return $output; } public function admin_assets( $hook ) { if ( 'settings_page_adaptive-intent-path' !== $hook ) { return; } wp_enqueue_style( 'adapinpa-admin', plugin_dir_url( __FILE__ ) . 'assets/css/adapinpa-admin.css', array(), self::VERSION ); } public function frontend_assets() { $settings = $this->get_settings(); if ( empty( $settings['enabled'] ) ) { return; } wp_enqueue_style( 'adapinpa-frontend', plugin_dir_url( __FILE__ ) . 'assets/css/adapinpa-frontend.css', array(), self::VERSION ); wp_enqueue_script( 'adapinpa-frontend', plugin_dir_url( __FILE__ ) . 'assets/js/adapinpa-frontend.js', array(), self::VERSION, true ); wp_localize_script( 'adapinpa-frontend', 'adapinpaConfig', array( 'timeTrigger' => absint( $settings['time_trigger'] ), 'scrollTrigger' => absint( $settings['scroll_trigger'] ), 'reshowHours' => absint( $settings['reshow_hours'] ), 'position' => sanitize_key( $settings['position'] ), 'intents' => array( 'buy' => esc_url( $settings['buy_url'] ), 'learn' => esc_url( $settings['learn_url'] ), 'expert' => esc_url( $settings['expert_url'] ), 'quote' => esc_url( $settings['quote_url'] ), ), ) ); } public function render_prompt() { $settings = $this->get_settings(); if ( empty( $settings['enabled'] ) ) { return; } $style = sprintf( '--adapinpa-primary:%1$s;--adapinpa-bg:%2$s;--adapinpa-text:%3$s;', esc_attr( $settings['primary_color'] ), esc_attr( $settings['background_color'] ), esc_attr( $settings['text_color'] ) ); ?>