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' ) . '