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 +59 -2 4.5.2 → 4.9.4 View file →
@@ -1,8 +1,12 @@
1 1 <?php
2 +namespace WPDeveloper\BetterDocs\FrontEnd;
2 3
3 -namespace WPDeveloper\BetterDocs\FrontEnd;
4 +if ( ! defined( 'ABSPATH' ) ) {
5 + exit;
6 +}
4 7
8 +
5 9 use WPDeveloper\BetterDocs\Utils\Base;
6 10 use WPDeveloper\BetterDocs\Utils\Helper;
7 11 use WPDeveloper\BetterDocs\Core\Settings;
8 12 use WPDeveloper\BetterDocs\Utils\Enqueue;
@@ -68,9 +72,13 @@
68 72 $post_type = get_query_var( 'post_type' ) != null ? get_query_var( 'post_type' ) : '';
69 73 $author_id = get_query_var( 'author' ) != null ? get_query_var( 'author' ) : 0;
70 74 $author_docs_count = count_user_posts( $author_id, 'docs' );
71 75
72 - 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 ) {
73 81 wp_enqueue_style('betterdocs-breadcrumb');
74 82 $template_path = BETTERDOCS_ABSPATH . 'views/templates/authors/author.php';
75 83 }
76 84
@@ -250,8 +258,12 @@
250 258 public function enqueue_scripts() {
251 259 if ( is_singular( 'docs' ) ) {
252 260 wp_enqueue_style( 'betterdocs-single' );
253 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 + }
254 266 wp_enqueue_style( 'betterdocs-encyclopedia' );
255 267 wp_enqueue_style( 'betterdocs-glossaries' );
256 268 wp_enqueue_script( 'clipboard' );
257 269 wp_enqueue_script( 'betterdocs-glossaries' );
@@ -256,8 +268,14 @@
256 268 wp_enqueue_script( 'clipboard' );
257 269 wp_enqueue_script( 'betterdocs-glossaries' );
258 270 }
259 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 +
260 278 if ( is_post_type_archive( 'docs' ) ) {
261 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
262 280 wp_enqueue_style( 'betterdocs-docs' );
263 281 }
@@ -282,8 +300,46 @@
282 300 wp_enqueue_style( 'betterdocs-glossaries' );
283 301 }
284 302 }
285 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 +
286 342 public function layout_filename( $filename, $origin_layout ) {
287 343 $filename = ( $origin_layout === 'layout-2' ) ? 'default' : $filename;
288 344 return $filename;
289 345 }
@@ -314,8 +370,9 @@
314 370 'betterdocs-reactions',
315 371 'betterdocsReactionsConfig',
316 372 [
317 373 'post_id' => get_the_ID(),
374 + 'nonce' => wp_create_nonce( 'wp_rest' ),
318 375 'FEEDBACK' => [
319 376 'DISPLAY' => true,
320 377 'TEXT' => esc_html__( 'How did you feel?', 'betterdocs' ),
321 378 'SUCCESS' => betterdocs()->settings->get( 'reaction_feedback_text', __( 'Thanks for your feedback', 'betterdocs' ) ),