0, ), $atts, 'arwp' ); $agent_id = intval( $atts['id'] ); if ( ! $agent_id ) { return '

' . esc_html__( 'Error: Agent ID is missing in the shortcode.', 'arwp-agents' ) . '

'; } $agent_post = get_post( $agent_id ); if ( ! $agent_post || 'arwp_agent' !== $agent_post->post_type ) { return '

' . esc_html__( 'Error: That agent could not be found.', 'arwp-agents' ) . '

'; } if ( 'publish' !== $agent_post->post_status && ! current_user_can( 'edit_post', $agent_id ) ) { return '

' . esc_html__( 'This chat is not available.', 'arwp-agents' ) . '

'; } $ui = $this->chat_ui( $agent_id, $agent_post ); wp_enqueue_style( 'arwp-chat-css' ); if ( ! arwp_visitor_can_use_agent( $agent_id ) ) { return $this->render_unavailable( $agent_id, $ui ); } wp_enqueue_script( 'arwp-marked-js' ); wp_enqueue_script( 'arwp-chat-js' ); static $localized = false; if ( ! $localized ) { wp_localize_script( 'arwp-chat-js', 'arwp_globals', array( 'api_url' => esc_url_raw( rest_url( 'arwp/v1/' ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'chat_nonce' => wp_create_nonce( 'arwp_chat_nonce' ), 'i18n' => array( 'copy' => __( 'Copy', 'arwp-agents' ), 'copied' => __( 'Copied', 'arwp-agents' ), 'copy_failed' => __( 'Copy failed', 'arwp-agents' ), 'send' => __( 'Send message', 'arwp-agents' ), 'stop' => __( 'Stop generating', 'arwp-agents' ), 'fullscreen' => __( 'Enter fullscreen', 'arwp-agents' ), 'exit_fullscreen' => __( 'Exit fullscreen', 'arwp-agents' ), 'message' => __( 'Message', 'arwp-agents' ), /* translators: %d: seconds remaining before the visitor can send again. */ 'please_wait' => __( 'Please wait %d seconds…', 'arwp-agents' ), ), ) ); $localized = true; } $cooldown = arwp_meta_int( get_post_meta( $agent_id, '_arwp_cooldown', true ), arwp_default_cooldown() ); ob_start(); ?>
render_chat_header( $agent_id, $ui ); ?>
post_title; } if ( ! is_string( $greeting ) ) { $greeting = ''; } if ( ! is_string( $placeholder ) || '' === $placeholder ) { $placeholder = __( 'Type your message here...', 'arwp-agents' ); } if ( empty( $color ) ) { $color = '#3b82f6'; } if ( ! is_string( $description ) ) { $description = ''; } if ( ! is_string( $disclaimer ) ) { $disclaimer = ''; } if ( ! is_string( $logo_url ) ) { $logo_url = ''; } if ( ! is_array( $suggestions ) ) { $suggestions = array(); } return array( 'theme' => $theme, 'title' => $title, 'greeting' => $greeting, 'placeholder' => $placeholder, 'color' => $color, 'description' => $description, 'disclaimer' => $disclaimer, 'logo_url' => $logo_url, 'suggestions' => array_values( array_filter( $suggestions, 'is_string' ) ), ); } /** * Header shared by the open chat and the denied state. * * @param int $agent_id Agent post ID. * @param array $ui Appearance values from chat_ui(). */ private function render_chat_header( $agent_id, $ui ) { ?>
<?php echo esc_attr( $ui['title'] ); ?>

render_chat_header( $agent_id, $ui ); ?>