array( 'Agentix_Chat_Options', 'sanitize' ) ) ); } public static function action_links( array $links ): array { array_unshift( $links, sprintf( '%s', esc_url( admin_url( 'admin.php?page=' . self::SLUG ) ), esc_html__( 'Settings', 'agentixhub-chat' ) ) ); return $links; } public static function assets( string $hook ): void { if ( $hook !== self::$hook ) { return; } wp_enqueue_media(); wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_style( 'agentixhub-chat-admin', AGENTIX_CHAT_URL . 'assets/admin.css', array(), Agentix_Chat_Frontend::asset_version( 'assets/admin.css' ) ); Agentix_Chat_Frontend::register_assets( true ); wp_enqueue_script( 'agentixhub-chat-admin', AGENTIX_CHAT_URL . 'assets/admin.js', array( 'jquery', 'wp-color-picker', Agentix_Chat_Frontend::HANDLE ), Agentix_Chat_Frontend::asset_version( 'assets/admin.js' ), true ); wp_localize_script( 'agentixhub-chat-admin', 'AgentixChatAdmin', array( 'option' => Agentix_Chat_Options::OPTION, 'choose' => __( 'Choose image', 'agentixhub-chat' ), ) ); } public static function render(): void { if ( ! current_user_can( 'manage_options' ) ) { return; } $tabs = Agentix_Chat_Options::tabs(); $tab = sanitize_key( wp_unslash( is_string( $_GET['tab'] ?? null ) ? $_GET['tab'] : '' ) ); // phpcs:ignore WordPress.Security.NonceVerification $tab = isset( $tabs[ $tab ] ) ? $tab : (string) array_key_first( $tabs ); ?>

array( 'success', __( 'Settings imported.', 'agentixhub-chat' ) ), 'import_failed' => array( 'error', __( 'That file is not a valid AgentixHub Chat settings export.', 'agentixhub-chat' ) ), 'reset' => array( 'success', __( 'Settings reset to defaults.', 'agentixhub-chat' ) ), ); $notice = sanitize_key( $_GET['ax_notice'] ?? '' ); // phpcs:ignore WordPress.Security.NonceVerification if ( isset( $notices[ $notice ] ) ) { printf( '

%s

', esc_attr( $notices[ $notice ][0] ), esc_html( $notices[ $notice ][1] ) ); } ?>
$label ) : ?>
>
'; foreach ( array_keys( Agentix_Chat_Options::schema() ) as $key ) { $f = Agentix_Chat_Options::field( $key ); if ( $f['tab'] !== $tab || in_array( $key, Agentix_Chat_Options::HIDDEN, true ) ) { continue; } printf( '', esc_attr( $f['type'] ), $f['show_if'] ? 'data-show-if="' . esc_attr( wp_json_encode( $f['show_if'] ) ) . '"' : '', esc_attr( $key ), esc_html( $f['label'] ) ); self::render_field( $f, $values[ $key ] ); if ( $f['desc'] ) { echo '

' . esc_html( $f['desc'] ) . '

'; } echo ''; } echo ''; if ( 'connection' === $tab ) { self::render_connection_status(); } } private static function render_field( array $f, $value ): void { $name = Agentix_Chat_Options::OPTION . '[' . $f['key'] . ']'; $id = 'ax-' . $f['key']; switch ( $f['type'] ) { case 'toggle': printf( '', esc_attr( $name ), esc_attr( $id ), esc_attr( $f['key'] ), checked( $value, 1, false ) ); break; case 'select': printf( ''; break; case 'checklist': printf( '', esc_attr( $name ) ); echo '
'; foreach ( $f['choices'] as $k => $label ) { printf( '', esc_attr( $name ), esc_attr( $k ), checked( in_array( (string) $k, (array) $value, true ), true, false ), esc_html( $label ) ); } echo '
'; break; case 'number': printf( '', esc_attr( $id ), esc_attr( $name ), esc_attr( $f['key'] ), esc_attr( $value ), esc_attr( $f['range'][0] ?? '' ), esc_attr( $f['range'][1] ?? '' ) ); break; case 'color': printf( '', esc_attr( $id ), esc_attr( $name ), esc_attr( $f['key'] ), esc_attr( $value ), esc_attr( $f['default'] ) ); break; case 'media': printf( '
', esc_attr( $id ), esc_attr( $name ), esc_attr( $f['key'] ), esc_url( $value ), esc_html__( 'Choose image', 'agentixhub-chat' ) ); break; case 'textarea': case 'lines': printf( '', 'lines' === $f['type'] ? 4 : 3, esc_attr( $id ), esc_attr( $name ), esc_attr( $f['key'] ), esc_textarea( $value ) ); break; case 'hours': $days = array( 'mon' => __( 'Monday', 'agentixhub-chat' ), 'tue' => __( 'Tuesday', 'agentixhub-chat' ), 'wed' => __( 'Wednesday', 'agentixhub-chat' ), 'thu' => __( 'Thursday', 'agentixhub-chat' ), 'fri' => __( 'Friday', 'agentixhub-chat' ), 'sat' => __( 'Saturday', 'agentixhub-chat' ), 'sun' => __( 'Sunday', 'agentixhub-chat' ), ); echo ''; foreach ( $days as $d => $label ) { $row = $value[ $d ] ?? array( 'on' => 0, 'open' => '09:00', 'close' => '18:00' ); printf( '', esc_attr( $name ), esc_attr( $d ), checked( $row['on'], 1, false ), esc_html( $label ), esc_attr( $row['open'] ), esc_attr( $row['close'] ) ); } /* translators: %s: timezone */ echo '
–

' . esc_html( sprintf( __( 'Timezone: %s', 'agentixhub-chat' ), wp_timezone_string() ) ) . '

'; break; case 'workflow_url': $locked = defined( 'AGENTIX_CHAT_WORKFLOW_URL' ) && AGENTIX_CHAT_WORKFLOW_URL; if ( $locked ) { echo '

AGENTIX_CHAT_WORKFLOW_URL ' . esc_html__( 'is set in wp-config.php and takes precedence.', 'agentixhub-chat' ) . '

'; break; } printf( '', esc_attr( $id ), esc_attr( $name ), esc_attr( $value ) ); break; default: printf( '', esc_attr( $id ), esc_attr( $name ), esc_attr( $f['key'] ), esc_attr( $value ) ); } } private static function render_connection_status(): void { $wf = Agentix_Chat_Workflow_Url::current(); echo '
'; echo '

' . esc_html__( 'Connection', 'agentixhub-chat' ) . '

'; if ( is_wp_error( $wf ) ) { echo '

' . esc_html( $wf->get_error_message() ) . ' ' . esc_html__( 'The chat stays hidden until a workflow URL is saved.', 'agentixhub-chat' ) . '

'; } else { echo '
'; printf( '
%s
%s
', esc_html__( 'AgentixHub host', 'agentixhub-chat' ), esc_html( wp_parse_url( $wf['origin'], PHP_URL_HOST ) ) ); printf( '
%s
#%s
', esc_html__( 'Workflow', 'agentixhub-chat' ), esc_html( $wf['workflow_id'] ) ); printf( '
%s
%s
', esc_html__( 'Organization', 'agentixhub-chat' ), esc_html( $wf['org_id'] ?: '—' ) ); echo '
'; } echo '
'; } private static function render_embed_tab(): void { ?>

[agentix_chat]   [agentix_chat mode="button" label="Ask us"]   [agentix_chat height="640"]
AgentixChat.open() AgentixChat.close() AgentixChat.toggle() — agentix:open agentix:close
agentix_chat_should_display agentix_chat_client_config

agentixhub.ai support@agentixhub.ai


true ) ); echo wp_json_encode( array( 'plugin' => 'agentixhub-chat', 'version' => AGENTIX_CHAT_VERSION, 'settings' => $settings ), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE ); exit; } public static function import(): void { check_admin_referer( 'agentix_chat_import' ); if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Not allowed.', 'agentixhub-chat' ), 403 ); } $upload = $_FILES['settings'] ?? array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput $file = (string) ( $upload['tmp_name'] ?? '' ); $valid = UPLOAD_ERR_OK === ( $upload['error'] ?? -1 ) && (int) ( $upload['size'] ?? 0 ) <= 64 * KB_IN_BYTES && '.json' === strtolower( substr( (string) ( $upload['name'] ?? '' ), -5 ) ) && is_uploaded_file( $file ); $data = $valid ? json_decode( (string) file_get_contents( $file ), true, 8 ) : null; // phpcs:ignore WordPress.WP.AlternativeFunctions $ok = is_array( $data ) && in_array( $data['plugin'] ?? '', array( 'agentixhub-chat', 'agentix-chat' ), true ) && is_array( $data['settings'] ?? null ); if ( $ok ) { $settings = $data['settings']; // Exports leave out the workflow URL, so the current one is kept. if ( empty( $settings['workflow_url'] ) ) { unset( $settings['workflow_url'] ); } update_option( Agentix_Chat_Options::OPTION, Agentix_Chat_Options::sanitize( $settings ) ); } wp_safe_redirect( add_query_arg( array( 'page' => self::SLUG, 'ax_notice' => $ok ? 'imported' : 'import_failed' ), admin_url( 'admin.php' ) ) ); exit; } public static function reset(): void { check_admin_referer( 'agentix_chat_reset' ); if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Not allowed.', 'agentixhub-chat' ), 403 ); } $keep = get_option( Agentix_Chat_Options::OPTION, array() )['workflow_url'] ?? ''; update_option( Agentix_Chat_Options::OPTION, array( 'workflow_url' => $keep ) + Agentix_Chat_Options::defaults() ); wp_safe_redirect( add_query_arg( array( 'page' => self::SLUG, 'ax_notice' => 'reset' ), admin_url( 'admin.php' ) ) ); exit; } public static function privacy_policy(): void { if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) { return; } $loads = 'idle' === Agentix_Chat_Options::get( 'iframe_preload' ) ? __( 'The chat assistant on this site is provided by AgentixHub and loads from their servers in the background after the page loads, so it is ready when you open it.', 'agentixhub-chat' ) : __( 'The chat assistant on this site is provided by AgentixHub and loads from their servers only when you first open it.', 'agentixhub-chat' ); wp_add_privacy_policy_content( __( 'AgentixHub Chat', 'agentixhub-chat' ), '

' . esc_html( $loads ) . ' ' . esc_html__( 'What you type or say in it, and any details you enter in its forms, are processed by AgentixHub to answer you, according to our agreement with the provider.', 'agentixhub-chat' ) . '

' ); } }