Skip to content

Commit 2f4fdfc

Browse files
committed
Remove nopriv AJAX handler and relocate taxonomy_search_tom_select method
- Remove wp_ajax_nopriv registration for taxonomy search (requires authentication) - Move taxonomy_search_tom_select method from Settings_Wizard to Settings class - Bump package.json version to 3.0.0 - Update readme.txt formatting from emoji bullets to plain markdown lists
1 parent 24a2e6e commit 2f4fdfc

4 files changed

Lines changed: 113 additions & 22 deletions

File tree

‎includes/admin/class-settings-wizard.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ protected function additional_hooks() {
7474
Hook_Registry::add_action( 'wp_ajax_wzkb_flush_permalinks', array( $this, 'flush_permalinks' ) );
7575

7676
// Register Tom Select AJAX handlers for wizard taxonomy fields.
77-
Hook_Registry::add_action( 'wp_ajax_nopriv_' . $this->prefix . '_taxonomy_search_tom_select', array( Settings::class, 'taxonomy_search_tom_select' ) );
7877
Hook_Registry::add_action( 'wp_ajax_' . $this->prefix . '_taxonomy_search_tom_select', array( Settings::class, 'taxonomy_search_tom_select' ) );
7978
}
8079

‎includes/admin/class-settings.php‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,98 @@ public function __construct() {
152152
Hook_Registry::add_action( self::$prefix . '_settings_form_buttons', array( $this, 'render_wizard_button' ), 20 );
153153
}
154154

155+
/**
156+
* AJAX handler for Tom Select taxonomy searches.
157+
*
158+
* Used by Settings API and Setup Wizard taxonomy autocomplete fields.
159+
*
160+
* @since 3.0.0
161+
*
162+
* @return void
163+
*/
164+
public static function taxonomy_search_tom_select(): void {
165+
// Verify nonce.
166+
if ( ! isset( $_REQUEST['nonce'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
167+
wp_send_json_error();
168+
}
169+
170+
$nonce_valid = wp_verify_nonce( sanitize_key( $_REQUEST['nonce'] ), self::$prefix . '_taxonomy_search_tom_select' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
171+
if ( ! $nonce_valid ) {
172+
wp_send_json_error();
173+
}
174+
175+
if ( ! isset( $_REQUEST['endpoint'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
176+
wp_send_json_error();
177+
}
178+
179+
$endpoint = sanitize_key( $_REQUEST['endpoint'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
180+
$term = isset( $_REQUEST['q'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['q'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
181+
182+
$comma = _x( ',', 'tag delimiter', 'knowledgebase' );
183+
if ( ',' !== $comma ) {
184+
$term = str_replace( $comma, ',', $term );
185+
}
186+
if ( false !== strpos( $term, ',' ) ) {
187+
$term_parts = explode( ',', $term );
188+
$term = $term_parts[ count( $term_parts ) - 1 ];
189+
}
190+
$term = trim( $term );
191+
192+
$allowed_endpoints = array(
193+
'category' => 'wzkb_category',
194+
'product' => 'wzkb_product',
195+
'tag' => 'wzkb_tag',
196+
'post_tag' => 'wzkb_tag',
197+
);
198+
199+
$allowed_taxonomies = array_values( $allowed_endpoints );
200+
if ( isset( $allowed_endpoints[ $endpoint ] ) ) {
201+
$taxonomy = $allowed_endpoints[ $endpoint ];
202+
} elseif ( in_array( $endpoint, $allowed_taxonomies, true ) ) {
203+
$taxonomy = $endpoint;
204+
} else {
205+
wp_send_json_success( array() );
206+
}
207+
208+
$tax = get_taxonomy( $taxonomy );
209+
if ( ! $tax ) {
210+
wp_send_json_success( array() );
211+
}
212+
213+
if ( empty( $tax->cap->assign_terms ) || ! current_user_can( $tax->cap->assign_terms ) ) {
214+
wp_send_json_error();
215+
}
216+
217+
/** This filter has been defined in /wp-admin/includes/ajax-actions.php */
218+
$term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $term );
219+
if ( ( 0 === $term_search_min_chars ) || ( strlen( $term ) < $term_search_min_chars ) ) {
220+
wp_send_json_success( array() );
221+
}
222+
223+
$terms = get_terms(
224+
array(
225+
'taxonomy' => $taxonomy,
226+
'name__like' => $term,
227+
'hide_empty' => false,
228+
'number' => 20,
229+
)
230+
);
231+
232+
$results = array();
233+
foreach ( (array) $terms as $found_term ) {
234+
if ( ! ( $found_term instanceof \WP_Term ) ) {
235+
continue;
236+
}
237+
238+
$results[] = array(
239+
'value' => sprintf( '%1$s (%2$s:%3$d)', $found_term->name, $found_term->taxonomy, (int) $found_term->term_taxonomy_id ),
240+
'text' => $found_term->name,
241+
);
242+
}
243+
244+
wp_send_json_success( $results );
245+
}
246+
155247
/**
156248
* Initialise the settings API.
157249
*

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@webberzone/knowledgebase",
3-
"version": "2.3.0",
3+
"version": "3.0.0",
44
"description": "Fastest way to create a highly-flexible multi-product knowledge base.",
55
"author": "WebberZone",
66
"license": "GPL-2.0-or-later",
@@ -60,4 +60,4 @@
6060
"clsx": "^2.1.1",
6161
"uuid": "^13.0.0"
6262
}
63-
}
63+
}

‎readme.txt‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,34 @@ Effortlessly create a powerful, multi-product knowledge base. Boost your support
1515

1616
[Knowledge Base](https://webberzone.com/plugins/knowledgebase/) makes building a knowledge base or FAQ for your WordPress site easy, fast, and scalable.
1717

18-
🎯 Perfect for:
19-
✅ Multi-product companies
20-
✅ SaaS platforms
21-
✅ Ecommerce support centres
22-
✅ Documentation hubs
18+
Perfect for:
19+
- Multi-product companies
20+
- SaaS platforms
21+
- Ecommerce support centres
22+
- Documentation hubs
2323

24-
🔎 [Live Demo](https://webberzone.com/support/knowledgebase/).
24+
[Live Demo](https://webberzone.com/support/knowledgebase/).
2525

2626
### Main features
2727

28-
🚀 Unlimited Knowledge Bases — Support as many products as you like, with unlimited sections and sub-sections.
29-
🎨 Beautiful, Responsive Layouts — Ships with clean templates powered by the Responsive Grid System.
30-
🔗 Customisable Permalinks — View your KB at /knowledgebase/ by default or change it easily.
31-
✨ Shortcodes + Gutenberg Blocks — Add KB listings anywhere using [knowledgebase] or use the Knowledge Base block.
32-
🧭 Built-in Breadcrumbs — Improve UX and SEO with breadcrumb navigation.
33-
🧩 Widgets Included — WZKB Articles, WZKB Sections, and WZKB Breadcrumbs widgets.
34-
⚡ Built-in Caching — Speed up your Knowledge Base without extra plugins.
28+
Unlimited Knowledge Bases — Support as many products as you like, with unlimited sections and sub-sections.
29+
Beautiful, Responsive Layouts — Ships with clean templates powered by the Responsive Grid System.
30+
Customisable Permalinks — View your KB at /knowledgebase/ by default or change it easily.
31+
Shortcodes + Gutenberg Blocks — Add KB listings anywhere using [knowledgebase] or use the Knowledge Base block.
32+
Built-in Breadcrumbs — Improve UX and SEO with breadcrumb navigation.
33+
Widgets Included — WZKB Articles, WZKB Sections, and WZKB Breadcrumbs widgets.
34+
Built-in Caching — Speed up your Knowledge Base without extra plugins.
3535

3636
### Pro features
3737

3838
[Knowledge Base Pro](https://webberzone.com/plugins/knowledgebase/#pro) enhances the plugin with advanced features for larger documentation sites, including ratings and feedback, a help widget, a powerful custom permalinks engine, premium layouts, and additional admin tools.
3939

40-
- ⭐ __Article Rating & Feedback System__ — Collect binary or 5-star feedback with optional follow-up questions, admin alerts, Bayesian sorting, and GDPR-friendly tracking modes.
41-
- 💬 __Help Widget__ — Offer an in-app support hub with live search, suggested articles, and a contact form inside a floating assistant.
42-
- 🧭 __Custom Permalinks Engine__ — Craft advanced URL structures for articles, sections, tags, and products using dynamic placeholders.
43-
- 🏠 __Knowledge Base Homepage Mode__ — Display the Knowledge Base on your site homepage. The Knowledge Base URL becomes the homepage and the Knowledge Base archive URL redirects to the homepage.
44-
- 🎨 __Premium Layout Pack__ — Unlock seven additional frontend styles (Card, Minimal, Boxed, Gradient, Compact, Magazine, Professional).
45-
- 🛠️ __Advanced Admin Tools__ — Control knowledge base caching with expiry settings, on-demand cache clearing, and other productivity enhancements.
40+
- __Article Rating & Feedback System__ — Collect binary or 5-star feedback with optional follow-up questions, admin alerts, Bayesian sorting, and GDPR-friendly tracking modes.
41+
- __Help Widget__ — Offer an in-app support hub with live search, suggested articles, and a contact form inside a floating assistant.
42+
- __Custom Permalinks Engine__ — Craft advanced URL structures for articles, sections, tags, and products using dynamic placeholders.
43+
- __Knowledge Base Homepage Mode__ — Display the Knowledge Base on your site homepage. The Knowledge Base URL becomes the homepage and the Knowledge Base archive URL redirects to the homepage.
44+
- __Premium Layout Pack__ — Unlock seven additional frontend styles (Card, Minimal, Boxed, Gradient, Compact, Magazine, Professional).
45+
- __Advanced Admin Tools__ — Control knowledge base caching with expiry settings, on-demand cache clearing, and other productivity enhancements.
4646

4747
### Key Concepts
4848

0 commit comments

Comments
 (0)