PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.4
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.4
4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 All 202 releases
← All changes | includes/FrontEnd/FrontEnd.php +54 -1 4.5.5 → 4.9.4 View file →
@@ -72,9 +72,13 @@
72 72 $post_type = get_query_var( 'post_type' ) != null ? get_query_var( 'post_type' ) : '';
73 73 $author_id = get_query_var( 'author' ) != null ? get_query_var( 'author' ) : 0;
74 74 $author_docs_count = count_user_posts( $author_id, 'docs' );
75 75
76 - if ( $post_type == 'docs' && $author_docs_count > 0 ) {
76 + // Only override on an actual author archive — otherwise this also fires on
77 + // the main docs archive (where $author_id falls back to 0) whenever any doc
78 + // has post_author 0, hijacking the docs/MKB archive (and its FSE template)
79 + // with the author template.
80 + if ( is_author() && $post_type == 'docs' && $author_docs_count > 0 ) {
77 81 wp_enqueue_style('betterdocs-breadcrumb');
78 82 $template_path = BETTERDOCS_ABSPATH . 'views/templates/authors/author.php';
79 83 }
80 84
@@ -254,8 +258,12 @@
254 258 public function enqueue_scripts() {
255 259 if ( is_singular( 'docs' ) ) {
256 260 wp_enqueue_style( 'betterdocs-single' );
257 261 wp_enqueue_style( 'betterdocs-article-summary' );
262 + wp_enqueue_style( 'betterdocs-ai-actions' );
263 + if ( betterdocs()->listen->is_enabled() ) {
264 + wp_enqueue_style( 'betterdocs-listen' );
265 + }
258 266 wp_enqueue_style( 'betterdocs-encyclopedia' );
259 267 wp_enqueue_style( 'betterdocs-glossaries' );
260 268 wp_enqueue_script( 'clipboard' );
261 269 wp_enqueue_script( 'betterdocs-glossaries' );
@@ -260,8 +268,14 @@
260 268 wp_enqueue_script( 'clipboard' );
261 269 wp_enqueue_script( 'betterdocs-glossaries' );
262 270 }
263 271
272 + // The shortcode / block / widget can place AI Actions and Listen on any page.
273 + // Their own dependency lists run during the_content, i.e. after wp_head has
274 + // already printed, which would leave the controls unstyled until the footer
275 + // stylesheet parsed — so catch those placements here instead.
276 + $this->maybe_enqueue_meta_row();
277 +
264 278 if ( is_post_type_archive( 'docs' ) ) {
265 279 wp_enqueue_style( 'betterdocs-category-grid' ); //category grid shortcode is supposed to enqueue this style, but this is called again to fix flicking of UI on Docs Page
266 280 wp_enqueue_style( 'betterdocs-docs' );
267 281 }
@@ -286,8 +300,46 @@
286 300 wp_enqueue_style( 'betterdocs-glossaries' );
287 301 }
288 302 }
289 303
304 + /**
305 + * Enqueue the meta-row assets in wp_head when the current post embeds one of
306 + * the shortcodes or the block, so an off-doc placement is styled on first
307 + * paint.
308 + *
309 + * @since 4.8.0
310 + * @since 4.9.2 Listen added, and renamed from maybe_enqueue_ai_actions().
311 + */
312 + protected function maybe_enqueue_meta_row() {
313 + if ( is_singular( 'docs' ) ) {
314 + return;
315 + }
316 +
317 + $post = get_post();
318 + if ( ! $post instanceof \WP_Post ) {
319 + return;
320 + }
321 +
322 + // `betterdocs/reading-time` is the merged meta-row block: it carries the AI
323 + // Actions button and the Listen pill, and the `.betterdocs-doc-meta` wrapper
324 + // lives in both stylesheets, so it needs a handle whichever third of it is
325 + // switched on. Which is also why the block counts for both features here.
326 + $block = has_block( 'betterdocs/reading-time', $post );
327 +
328 + if ( betterdocs()->ai_actions->is_enabled()
329 + && ( $block || has_shortcode( $post->post_content, 'betterdocs_ai_actions' ) ) ) {
330 + wp_enqueue_style( 'betterdocs-ai-actions' );
331 + wp_enqueue_script( 'clipboard' );
332 + wp_enqueue_script( 'betterdocs' );
333 + }
334 +
335 + if ( betterdocs()->listen->is_enabled()
336 + && ( $block || has_shortcode( $post->post_content, 'betterdocs_listen' ) ) ) {
337 + wp_enqueue_style( 'betterdocs-listen' );
338 + wp_enqueue_script( 'betterdocs' );
339 + }
340 + }
341 +
290 342 public function layout_filename( $filename, $origin_layout ) {
291 343 $filename = ( $origin_layout === 'layout-2' ) ? 'default' : $filename;
292 344 return $filename;
293 345 }
@@ -318,8 +370,9 @@
318 370 'betterdocs-reactions',
319 371 'betterdocsReactionsConfig',
320 372 [
321 373 'post_id' => get_the_ID(),
374 + 'nonce' => wp_create_nonce( 'wp_rest' ),
322 375 'FEEDBACK' => [
323 376 'DISPLAY' => true,
324 377 'TEXT' => esc_html__( 'How did you feel?', 'betterdocs' ),
325 378 'SUCCESS' => betterdocs()->settings->get( 'reaction_feedback_text', __( 'Thanks for your feedback', 'betterdocs' ) ),