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(); ?>