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/Core/Scripts.php +53 -3 4.8.2 → 4.9.4 View file →
@@ -7,8 +7,9 @@
7 7
8 8
9 9 use WPDeveloper\BetterDocs\Utils\Base;
10 10 use WPDeveloper\BetterDocs\Utils\Helper;
11 +use WPDeveloper\BetterDocs\FrontEnd\PrintTemplate;
11 12
12 13 class Scripts extends Base {
13 14 protected $settings;
14 15
@@ -52,8 +53,10 @@
52 53 $assets->register( 'betterdocs-category-archive-header', 'public/css/archive-header.css' );
53 54 $assets->register( 'betterdocs-category-archive-doc-list', 'public/css/archive-doc-list.css' );
54 55 $assets->register( 'betterdocs-article-summary', 'public/css/article-summary.css' );
55 56 $assets->register( 'betterdocs-author', 'public/css/author.css' );
57 + $assets->register( 'betterdocs-ai-actions', 'public/css/ai-actions.css' );
58 + $assets->register( 'betterdocs-listen', 'public/css/listen.css' );
56 59
57 60 $assets->register( 'betterdocs-category-grid', 'public/css/category-grid.css', [ 'simplebar' ] );
58 61 $assets->register( 'betterdocs-category-box', 'public/css/category-box.css' );
59 62 $assets->register( 'betterdocs-category-grid-list', 'public/css/category-grid-list.css' );
@@ -76,8 +79,25 @@
76 79 $assets->register( 'betterdocs-reactions', 'shortcodes/js/reactions.js', [ 'jquery' ] );
77 80 $assets->register( 'betterdocs-search', 'shortcodes/js/search.js', [ 'jquery' ] );
78 81 $assets->register( 'betterdocs-search-modal', 'shortcodes/js/search-modal.js', [ 'jquery' ] );
79 82
83 + /**
84 + * Print template config for the single-doc Print / Save-as-PDF button.
85 + *
86 + * These values feed the print *popup* opened by the BetterDocs print
87 + * icon. The browser's own Ctrl/Cmd+P route is handled separately by
88 + * {@see PrintTemplate}, which resolves the same two values — see that
89 + * class for why the two routes use different layout mechanisms.
90 + *
91 + * Both toggles live in `betterdocs_settings` (BetterDocs → Settings →
92 + * Layout → Single Doc → General) rather than theme mods, so they stay
93 + * reachable on block/FSE themes, which have no Customizer. Both default
94 + * to OFF; while a toggle is off the value resolves empty and the print
95 + * script renders nothing for it.
96 + */
97 + $print_logo = PrintTemplate::get_logo();
98 + $print_footer = PrintTemplate::get_footer();
99 +
80 100 $assets->localize(
81 101 'betterdocs',
82 102 'betterdocsConfig',
83 103 [
@@ -84,9 +104,35 @@
84 104 'ajax_url' => admin_url( 'admin-ajax.php' ),
85 105 'copy_text' => __( 'Copied', 'betterdocs' ),
86 106 'sticky_toc_offset' => $this->settings->get( 'sticky_toc_offset' ),
87 107 'summary_nonce' => wp_create_nonce( 'betterdocs_article_summary_nonce' ),
88 - 'summary_error' => __( 'Failed to generate doc summary. Please try again.', 'betterdocs' )
108 + 'summary_error' => __( 'Failed to generate doc summary. Please try again.', 'betterdocs' ),
109 + // Namespaced so the AI Actions strings do not collide as the feature
110 + // grows. Nothing URL-shaped belongs here: init() runs with no $post,
111 + // so every per-doc URL lives on the rendered data-bd-* attributes.
112 + 'ai_actions' => [
113 + 'i18n' => [
114 + 'copy' => __( 'Copy page', 'betterdocs' ),
115 + 'copying' => __( 'Copying…', 'betterdocs' ),
116 + 'copied' => __( 'Copied', 'betterdocs' ),
117 + 'copy_failed' => __( 'Copy failed', 'betterdocs' ),
118 + 'copy_error' => __( 'Could not copy this page. Please try again.', 'betterdocs' )
119 + ]
120 + ],
121 + // Same shape and the same reasoning: namespaced, and with nothing
122 + // per-doc in it. Core\Listen owns the contents, because the rates and
123 + // the two content selectors are filterable and the filters have to
124 + // reach the script.
125 + //
126 + // Guarded: this runs on `init` at 1 and Plugin::initialize() — which
127 + // builds the property — is the `init` callback at 0, so the ordering
128 + // holds today. It is one priority of slack, and a fatal if it ever
129 + // changes.
130 + 'listen' => isset( betterdocs()->listen ) ? betterdocs()->listen->localize() : [],
131 + 'print' => [
132 + 'logo' => $print_logo ? esc_url( $print_logo ) : '',
133 + 'footer' => $print_footer ? wp_kses_post( $print_footer ) : ''
134 + ]
89 135 ]
90 136 );
91 137
92 138 $assets->localize(
@@ -92,9 +138,12 @@
92 138 $assets->localize(
93 139 'betterdocs-search',
94 140 'betterdocsSearchConfig',
95 141 [
96 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
142 + // Root-relative so live search stays same-origin when the KB is
143 + // served on a different host than the Site Address (subdomain /
144 + // domain alias / reverse proxy). See Helper::frontend_ajax_url().
145 + 'ajax_url' => Helper::frontend_ajax_url(),
97 146 'search_letter_limit' => $this->settings->get( 'search_letter_limit' )
98 147 ]
99 148 );
100 149
@@ -101,9 +150,10 @@
101 150 $assets->localize(
102 151 'betterdocs-search-modal',
103 152 'betterdocsSearchModalConfig',
104 153 [
105 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
154 + // Same-origin (see betterdocsSearchConfig above).
155 + 'ajax_url' => Helper::frontend_ajax_url(),
106 156 'rest_url' => esc_url_raw(rest_url()),
107 157 'advance_search' => $this->settings->get( 'advance_search' ),
108 158 'child_category_exclude' => $this->settings->get( 'child_category_exclude' ),
109 159 'popular_keyword_limit' => $this->settings->get( 'popular_keyword_limit' ),