PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 1.7.2
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v1.7.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 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / includes / class-betterdocs-docs-post-type.php

class-betterdocs-docs-post-type.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 1.7.2, at includes/class-betterdocs-docs-post-type.php

638 lines 24.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Register docs post type and taxonomies.
4 *
5 * @link https://wpdeveloper.net
6 * @since 1.0.0
7 *
8 * @package BetterDocs
9 * @subpackage BetterDocs/includes
10 */
11
12 use function YoastSEO_Vendor\GuzzleHttp\json_decode;
13
14 /**
15 * Register docs post type and taxonomies class.
16 *
17 *
18 * Also maintains the unique identifier of this plugin as well as the current
19 * version of the plugin.
20 *
21 * @since 1.0.0
22 * @package BetterDocs
23 * @subpackage BetterDocs/includes
24 * @author WPDeveloper <support@wpdeveloper.net>
25 */
26 class BetterDocs_Docs_Post_Type
27 {
28 public static $post_type = 'docs';
29 public static $menu_position = 5;
30 public static $category = 'doc_category';
31 public static $tag = 'doc_tag';
32 public static $docs_archive;
33 public static $docs_slug;
34 public static $cat_slug;
35
36 /**
37 *
38 * Initialize the class and start calling our hooks and filters
39 *
40 * @since 1.0.0
41 *
42 */
43 public static function init() {
44 self::$docs_archive = self::get_docs_archive();
45 self::$docs_slug = self::get_docs_slug();
46 self::$cat_slug = self::docs_category_slug();
47 add_action('init', array(__CLASS__, 'register_post'));
48 add_filter('betterdocs_docs_rewrite', array(__CLASS__, 'docs_rewrite'), 9);
49 add_filter('post_type_link', array(__CLASS__, 'docs_show_permalinks'), 1, 3);
50 add_filter('rest_api_allowed_post_types', array(__CLASS__, 'rest_api_allowed_post_types'));
51 add_action('admin_head', array(__CLASS__, 'admin_order_terms'));
52 $alphabetically_order_term = BetterDocs_DB::get_settings('alphabetically_order_term');
53 if ( $alphabetically_order_term != 1 ) {
54 add_action('init', array(__CLASS__, 'front_end_order_terms'));
55 }
56 // doc category taxonomy media upload hooks
57 add_action('doc_category_add_form_fields', array(__CLASS__, 'add_doc_category_meta'), 10, 2);
58 add_action('doc_category_edit_form_fields', array(__CLASS__, 'update_doc_category_meta'), 10, 2);
59 add_action('created_doc_category', array(__CLASS__, 'save_doc_category_meta'), 10, 2);
60 add_action('edited_doc_category', array(__CLASS__, 'updated_doc_category_meta'), 10, 2);
61 add_action('admin_enqueue_scripts', array(__CLASS__, 'load_media'));
62 add_action('admin_footer', array(__CLASS__, 'add_script'));
63 }
64
65 public static function get_docs_slug() {
66 $builtin_doc_page = BetterDocs_DB::get_settings('builtin_doc_page');
67 $docs_slug = BetterDocs_DB::get_settings('docs_slug');
68 $docs_page = BetterDocs_DB::get_settings('docs_page');
69
70 if ($builtin_doc_page == 1 && $docs_slug) {
71 $docs_post_slug = $docs_slug;
72 } elseif ($builtin_doc_page != 1 && $docs_page) {
73 $post_info = get_post( $docs_page );
74 $docs_post_slug = $post_info->post_name;
75 } else {
76 $docs_post_slug = 'docs';
77 }
78
79 return $docs_post_slug;
80 }
81
82 public static function get_docs_archive() {
83 $builtin_doc_page = BetterDocs_DB::get_settings('builtin_doc_page');
84 $docs_slug = BetterDocs_DB::get_settings('docs_slug');
85 $docs_page = BetterDocs_DB::get_settings('docs_page');
86
87 if ( $builtin_doc_page == 1 && $docs_slug ) {
88 $docs_post_slug = $docs_slug;
89 } elseif ( $builtin_doc_page != 1 && $docs_page ) {
90 $post_info = get_post( $docs_page );
91 $docs_post_slug = $post_info->post_name;
92 } else {
93 $docs_post_slug = 'docs';
94 }
95
96 return $docs_post_slug;
97 }
98
99 public static function docs_category_slug() {
100 $category_slug = BetterDocs_DB::get_settings('category_slug');
101
102 if (empty($category_slug)) {
103 $category_slug = 'docs-category';
104 }
105
106 return $category_slug;
107 }
108
109 /**
110 *
111 * Register post type and taxonomies
112 *
113 * @since 1.0.0
114 *
115 */
116 public static function register_post() {
117 $singular_name = BetterDocs_DB::get_settings('breadcrumb_doc_title');
118
119 /**
120 * Register category taxonomy
121 */
122 $category_labels = array(
123 'name' => esc_html__('Docs Categories', 'betterdocs'),
124 'singular_name' => esc_html__('Docs Category', 'betterdocs'),
125 'all_items' => esc_html__('Docs Categories', 'betterdocs'),
126 'parent_item' => esc_html__('Parent Docs Category', 'betterdocs'),
127 'parent_item_colon'=> esc_html__('Parent Docs Category:', 'betterdocs'),
128 'edit_item' => esc_html__('Edit Category', 'betterdocs'),
129 'update_item' => esc_html__('Update Category', 'betterdocs'),
130 'add_new_item' => esc_html__('Add New Docs Category', 'betterdocs'),
131 'new_item_name' => esc_html__('New Docs Name', 'betterdocs'),
132 'menu_name' => esc_html__('Categories', 'betterdocs')
133 );
134
135 $category_args = array(
136 'hierarchical' => true,
137 'public' => true,
138 'labels' => $category_labels,
139 'show_ui' => true,
140 'show_admin_column' => true,
141 'query_var' => true,
142 'show_in_rest' => true,
143 'has_archive' => true,
144 );
145
146 $category_args['rewrite'] = apply_filters( 'betterdocs_category_rewrite', array( 'slug' => self::$cat_slug, 'with_front' => false ));
147
148 register_taxonomy( self::$category, array( self::$post_type ), $category_args );
149
150 /**
151 * Register post type
152 */
153 $labels = array(
154 'name' => ($singular_name) ? $singular_name : 'Docs',
155 'singular_name' => ($singular_name) ? $singular_name : 'Docs',
156 'menu_name' => esc_html__('BetterDocs', 'betterdocs'),
157 'name_admin_bar' => esc_html__('Docs', 'betterdocs'),
158 'add_new' => esc_html__('Add New', 'betterdocs'),
159 'add_new_item' => esc_html__('Add New Docs', 'betterdocs'),
160 'new_item' => esc_html__('New Docs', 'betterdocs'),
161 'edit_item' => esc_html__('Edit Docs', 'betterdocs'),
162 'view_item' => esc_html__('View Docs', 'betterdocs'),
163 'all_items' => esc_html__('All Docs', 'betterdocs'),
164 'search_items' => esc_html__('Search Docs', 'betterdocs'),
165 'parent_item_colorn' => null,
166 'not_found' => esc_html__('No docs found', 'betterdocs'),
167 'not_found_in_trash' => esc_html__('No docs found in trash', 'betterdocs')
168 );
169
170 $betterdocs_articles_caps = apply_filters( 'betterdocs_articles_caps', 'edit_posts', 'article_roles' );
171
172 $args = array(
173 'labels' => $labels,
174 'description' => esc_html__('Add new doc from here', 'betterdocs'),
175 'public' => true,
176 'public_queryable' => true,
177 'exclude_from_search' => false,
178 'show_ui' => true,
179 'show_in_menu' => false,
180 'show_in_admin_bar' => $betterdocs_articles_caps,
181 'query_var' => true,
182 'capability_type' => 'post',
183 'hierarchical' => true,
184 'menu_position' => self::$menu_position,
185 'show_in_rest' => true,
186 'menu_icon' => BETTERDOCS_ADMIN_URL . '/assets/img/betterdocs-icon-white.svg', 100,
187 'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'author', 'revisions', 'custom-fields', 'comments')
188 );
189
190 $builtin_doc_page = BetterDocs_DB::get_settings('builtin_doc_page');
191
192 if ($builtin_doc_page == 'off') {
193 $args['has_archive'] = false;
194 } else {
195 $args['has_archive'] = self::$docs_archive;
196 }
197
198 $args['rewrite'] = apply_filters('betterdocs_docs_rewrite', array( 'slug' => self::$docs_archive, 'with_front' => false ));
199
200 register_post_type(self::$post_type, $args);
201
202 /**
203 * Register tag taxonomy
204 */
205 $tags_labels = array(
206 'name' => esc_html__('Docs Tags', 'betterdocs'),
207 'singular_name' => esc_html__('Tag', 'betterdocs'),
208 'search_items' => esc_html__('Search Tags', 'betterdocs'),
209 'popular_items' => esc_html__('Popular Tags', 'betterdocs'),
210 'all_items' => esc_html__('All Tags', 'betterdocs'),
211 'parent_item' => null,
212 'parent_item_colon' => null,
213 'edit_item' => esc_html__('Edit Tag', 'betterdocs'),
214 'update_item' => esc_html__('Update Tag', 'betterdocs'),
215 'add_new_item' => esc_html__('Add New Tag', 'betterdocs'),
216 'new_item_name' => esc_html__('New Tag Name', 'betterdocs'),
217 'separate_items_with_commas' => esc_html__('Separate tags with commas', 'betterdocs'),
218 'add_or_remove_items' => esc_html__('Add or remove tags', 'betterdocs'),
219 'choose_from_most_used' => esc_html__('Choose from the most used tags', 'betterdocs'),
220 'menu_name' => esc_html__('Tags', 'betterdocs'),
221 );
222
223 $tag_args = array(
224 'hierarchical' => true,
225 'labels' => $tags_labels,
226 'show_ui' => true,
227 'update_count_callback' => '_update_post_term_count',
228 'show_admin_column' => true,
229 'query_var' => true,
230 'show_in_rest' => true
231 );
232
233 $tag_slug = BetterDocs_DB::get_settings('tag_slug');
234
235 if ($tag_slug) {
236 $tag_args['rewrite'] = array('slug' => $tag_slug, 'with_front' => false);
237 } else {
238 $tag_args['rewrite'] = array('slug' => 'docs-tag', 'with_front' => false);
239 }
240
241 register_taxonomy(self::$tag, array(self::$post_type), $tag_args);
242
243 flush_rewrite_rules();
244
245 }
246
247 /**
248 * Added post type to allowed for rest api
249 *
250 * @param array $post_types Get the docs post types.
251 * @return array
252 *
253 * @since 1.0.0
254 *
255 */
256 public static function rest_api_allowed_post_types($post_types) {
257 $post_types[] = self::$post_type;
258 return $post_types;
259 }
260
261 /**
262 * load media for taxonomy category image
263 *
264 * @since 1.0.0
265 */
266 public static function load_media() {
267 wp_enqueue_media();
268 }
269
270 /**
271 * Default the taxonomy's terms' order if it's not set.
272 *
273 * @param string $tax_slug The taxonomy's slug.
274 */
275 public static function default_term_order($tax_slug) {
276 $terms = get_terms($tax_slug, array('hide_empty' => false));
277 $order = self::get_max_taxonomy_order($tax_slug);
278
279 foreach ($terms as $term) {
280 if ( !get_term_meta( $term->term_id, 'doc_category_order', true ) ) {
281 update_term_meta($term->term_id, 'doc_category_order', $order);
282 $order++;
283 }
284 }
285 }
286
287 /**
288 * Order the terms on the admin side.
289 */
290 public static function admin_order_terms() {
291 $screen = function_exists('get_current_screen') ? get_current_screen() : '';
292
293 if (in_array($screen->id, array('toplevel_page_betterdocs-admin', 'betterdocs_page_betterdocs-settings'))) {
294 self::default_term_order('doc_category');
295 }
296
297 if (!isset($_GET['orderby']) && !empty($screen) && !empty($screen->base) && $screen->base === 'edit-tags' && $screen->taxonomy === 'doc_category') {
298 self::default_term_order($screen->taxonomy);
299 add_filter('terms_clauses', array(__CLASS__, 'set_tax_order'), 10, 3);
300 }
301 }
302
303 /**
304 * Get the maximum doc_category_order for this taxonomy. This will be applied to terms that don't have a tax position.
305 */
306 private static function get_max_taxonomy_order($tax_slug) {
307 global $wpdb;
308
309 $max_term_order = $wpdb->get_col(
310 $wpdb->prepare(
311 "SELECT MAX( CAST( tm.meta_value AS UNSIGNED ) )
312 FROM $wpdb->terms t
313 JOIN $wpdb->term_taxonomy tt ON t.term_id = tt.term_id AND tt.taxonomy = '%s'
314 JOIN $wpdb->termmeta tm ON tm.term_id = t.term_id WHERE tm.meta_key = 'doc_category_order'",
315 $tax_slug
316 )
317 );
318
319 $max_term_order = is_array($max_term_order) ? current($max_term_order) : 0;
320
321 return (int) $max_term_order === 0 || empty($max_term_order) ? 1 : (int) $max_term_order + 1;
322 }
323
324 /**
325 * Re-Order the taxonomies based on the doc_category_order value.
326 *
327 * @param array $pieces Array of SQL query clauses.
328 * @param array $taxonomies Array of taxonomy names.
329 * @param array $args Array of term query args.
330 */
331 public static function set_tax_order($pieces, $taxonomies, $args) {
332 foreach ( $taxonomies as $taxonomy ) {
333 global $wpdb;
334
335 if ($taxonomy === 'doc_category') {
336 $join_statement = " LEFT JOIN $wpdb->termmeta AS term_meta ON t.term_id = term_meta.term_id AND term_meta.meta_key = 'doc_category_order'";
337
338 if (!self::does_substring_exist($pieces['join'], $join_statement)) {
339 $pieces['join'] .= $join_statement;
340 }
341
342 $pieces['orderby'] = 'ORDER BY CAST( term_meta.meta_value AS UNSIGNED )';
343 }
344 }
345
346 return $pieces;
347 }
348
349 /**
350 * Order the taxonomies on the front end.
351 */
352 public static function front_end_order_terms() {
353 if (!is_admin()) {
354 add_filter('terms_clauses', array(__CLASS__, 'set_tax_order'), 10, 3);
355 }
356
357 }
358
359 /**
360 * Check if a substring exists inside a string.
361 *
362 * @param string $string The main string (haystack) we're searching in.
363 * @param string $substring The substring we're searching for.
364 *
365 * @return bool True if substring exists, else false.
366 */
367 protected static function does_substring_exist( $string, $substring ) {
368 return strstr($string, $substring) !== false;
369 }
370
371 /**
372 * Default the taxonomy's terms' order if it's not set.
373 *
374 * @param string $tax_slug The taxonomy's slug.
375 */
376 public static function get_manage_docs() {
377 $terms = get_terms('knowledge_base', array('hide_empty' => false));
378
379 if($terms) {
380 echo '<select name="term_meta[knowledge_base]" id="knowledge_base">';
381 echo '<option> ' . esc_html__('Select an option') . ' </option>';
382
383 foreach ($terms as $term) {
384 echo '<option value="' . $term->slug . '">' . $term->name . '</option>';
385 }
386
387 echo '</select>';
388 }
389 }
390
391 /**
392 * Add a form field in the new category page
393 *
394 * @since 1.0.0
395 */
396 public static function add_doc_category_meta($taxonomy) {
397 do_action( 'betterdocs_doc_category_add_form_before' );
398
399 echo '<div class="form-field term-group">
400 <label for="doc-category-order">'. esc_html__('Order', 'betterdocs') .'</label>
401 <input type="number" id="doc-category-order" style="width:100px" name="term_meta[order]" value="">
402 </div>
403
404 <div class="form-field term-group">
405 <label for="doc-category-image-id">'. esc_html__('Category Icon', 'betterdocs') .'</label>
406 <input type="hidden" id="doc-category-image-id" name="term_meta[image-id]" class="custom_media_url" value="">
407 <div id="doc-category-image-wrapper">
408 <img src="' . BETTERDOCS_ADMIN_URL . 'assets/img/betterdocs-cat-icon.svg" alt="">
409 </div>
410 <p>
411 <input type="button" class="button button-secondary betterdocs_tax_media_button"
412 id="betterdocs_tax_media_button" name="betterdocs_tax_media_button"
413 value="'. esc_html__('Add Image', 'betterdocs') .'" />
414 <input type="button" class="button button-secondary doc_tax_media_remove" id="doc_tax_media_remove"
415 name="doc_tax_media_remove"
416 value="'. esc_html__('Remove Image', 'betterdocs') .'" />
417 </p>
418 </div>';
419 }
420
421 /**
422 * Save the form field
423 *
424 * @since 1.0.0
425 */
426 public static function save_doc_category_meta($term_id) {
427 if (isset($_POST['term_meta'])) {
428 $term_meta = get_option("doc_category_$term_id");
429 $cat_keys = array_keys($_POST['term_meta']);
430 foreach ($cat_keys as $key) {
431 if (isset($_POST['term_meta'][$key])) {
432 add_term_meta($term_id, "doc_category_$key", $_POST['term_meta'][$key]);
433 $term_meta[$key] = $_POST['term_meta'][$key];
434 }
435 }
436 }
437 if ( isset($_POST['doc_category_kb']) ) {
438 $doc_category_kb = $_POST['doc_category_kb'];
439 update_term_meta($term_id, "doc_category_knowledge_base", $doc_category_kb);
440 }
441 }
442
443 /**
444 * Edit the form field
445 *
446 * @since 1.0.0
447 */
448 public static function update_doc_category_meta($term, $taxonomy) { ?>
449 <?php
450 $term_meta = get_option("doc_category_$term->term_id");
451 $cat_order = get_term_meta($term->term_id, 'doc_category_order', true);
452 $cat_icon_id = get_term_meta($term->term_id, 'doc_category_image-id', true);
453
454 do_action( 'betterdocs_doc_category_update_form_before', $term );
455
456 ?>
457
458 <tr class="form-field term-group-wrap">
459 <th scope="row">
460 <label for="doc-category-id"><?php esc_html_e('Category Id', 'betterdocs'); ?></label>
461 </th>
462 <td>
463 <input type="text" id="doc-category-id" style="width:100px" name="" value="<?php echo $_GET["tag_ID"] ?>" readonly>
464 </td>
465 </tr>
466 <tr class="form-field term-group-wrap">
467 <th scope="row">
468 <label for="doc-category-order"><?php esc_html_e('Order', 'betterdocs'); ?></label>
469 </th>
470 <td>
471 <input type="number" id="doc-category-order" style="width:100px" name="term_meta[order]"
472 value="<?php echo $cat_order ? $cat_order : ''; ?>">
473 </td>
474 </tr>
475 <tr class="form-field term-group-wrap batterdocs-cat-media-upload">
476 <th scope="row">
477 <label for="doc-category-image-id"><?php esc_html_e('Image', 'betterdocs'); ?></label>
478 </th>
479 <td>
480 <input type="hidden" id="doc-category-image-id" name="term_meta[image-id]" value="<?php echo $cat_icon_id; ?>">
481 <div id="doc-category-image-wrapper">
482 <?php
483 if ($cat_icon_id) {
484 echo wp_get_attachment_image( $cat_icon_id, 'thumbnail' );
485 } else {
486 echo '<img src="' . BETTERDOCS_ADMIN_URL . 'assets/img/betterdocs-cat-icon.svg" alt="">';
487 }
488 ?>
489 </div>
490 <p>
491 <input type="button" class="button button-secondary betterdocs_tax_media_button"
492 id="betterdocs_tax_media_button" name="betterdocs_tax_media_button"
493 value="<?php esc_html_e('Add Image', 'betterdocs'); ?>" />
494 <input type="button" class="button button-secondary doc_tax_media_remove" id="doc_tax_media_remove"
495 name="doc_tax_media_remove"
496 value="<?php esc_html_e('Remove Image', 'betterdocs'); ?>" />
497 </p>
498 </td>
499 </tr>
500 <?php
501 }
502
503 /*
504 * Update the form field value
505 *
506 * @since 1.0.0
507 */
508 public static function updated_doc_category_meta( $term_id ) {
509 if ( isset($_POST['term_meta']) ) {
510 $cat_keys = array_keys($_POST['term_meta']);
511 foreach ($cat_keys as $key) {
512 if (isset($_POST['term_meta'][$key])) {
513 update_term_meta($term_id, "doc_category_$key", $_POST['term_meta'][$key]);
514 }
515 }
516 }
517 if ( isset($_POST['doc_category_kb']) ) {
518 $doc_category_kb = $_POST['doc_category_kb'];
519 update_term_meta($term_id, "doc_category_knowledge_base", $doc_category_kb);
520 }
521 }
522
523 /*
524 * Add script
525 *
526 * @since 1.0.0
527 */
528 public static function add_script() {
529
530 global $current_screen;
531 if ( $current_screen->id == 'edit-doc_category' ) {
532
533 ?>
534 <script>
535 jQuery(document).ready(function($) {
536
537 function betterdocs_media_upload(button_class) {
538 var _custom_media = true,
539 _betterdocs_send_attachment = wp.media.editor.send.attachment;
540 $('body').on('click', button_class, function(e) {
541 var button_id = '#' + $(this).attr('id');
542 var send_attachment_bkp = wp.media.editor.send.attachment;
543 var button = $(button_id);
544 _custom_media = true;
545 wp.media.editor.send.attachment = function(props, attachment) {
546 if (_custom_media) {
547 $('#doc-category-image-id').val(attachment.id);
548 $('#doc-category-image-wrapper').html(
549 '<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />'
550 );
551 $('#doc-category-image-wrapper .custom_media_image').attr('src', attachment
552 .url).css('display', 'block');
553 } else {
554 return _betterdocs_send_attachment.apply(button_id, [props, attachment]);
555 }
556 }
557 wp.media.editor.open(button);
558 return false;
559 });
560 }
561
562 betterdocs_media_upload('.betterdocs_tax_media_button.button');
563
564 $('body').on('click', '.doc_tax_media_remove', function() {
565 $('#doc-category-image-id').val('');
566 $('#doc-category-image-wrapper').html(
567 '<img class="custom_media_image" src="" style="margin:0;padding:0;max-height:100px;float:none;" />'
568 );
569 });
570
571 $(document).ajaxComplete(function(event, xhr, settings) {
572 var queryStringArr = settings.data.split('&');
573 if ($.inArray('action=add-tag', queryStringArr) !== -1) {
574 var xml = xhr.responseXML;
575 $response = $(xml).find('term_id').text();
576 if ($response != "") {
577 // Clear the thumb image
578 $('#doc-category-image-wrapper').html('');
579 }
580 }
581 });
582 });
583 </script>
584 <?php }
585
586 }
587
588 /**
589 * Filtering post type rewrite rule.
590 *
591 * @param [type] $rewrite
592 * @return array $rewrite
593 */
594 public static function docs_rewrite($rewrite)
595 {
596 $permalink = BetterDocs_DB::get_settings( 'permalink_structure' );
597 if(!empty($permalink)){
598 if(class_exists('BetterDocs_Multiple_Kb') && BetterDocs_Multiple_Kb::get_multiple_kb() != 1){
599 $permalink = preg_replace('/%knowledge_base%\/?/', '', $permalink);
600 }
601 $rewrite = array('slug' => trim($permalink, '/'), 'with_front' => false);
602 }
603 return $rewrite;
604 }
605
606 /**
607 * Replacing %doc_category% placeholder in permalink.
608 *
609 * @param [type] $url
610 * @param [type] $post
611 * @param boolean $leavename
612 * @return string $url
613 */
614 public static function docs_show_permalinks($url, $post = null, $leavename = false)
615 {
616 if ($post->post_type != 'docs') {
617 return $url;
618 }
619 $doc_category = 'doc_category';
620 $cat_tag = '%' . $doc_category . '%';
621 $cat_terms = wp_get_object_terms($post->ID, $doc_category);
622
623 if (is_array($cat_terms) && sizeof($cat_terms) > 0) {
624 $doccat_terms = $cat_terms[0]->slug;
625 } else {
626 $doccat_terms = 'uncategorized';
627 }
628
629 if(class_exists('BetterDocs_Multiple_Kb') && BetterDocs_Multiple_Kb::get_multiple_kb() != 1){
630 $url = preg_replace('/%knowledge_base%\/?/', '', $url);
631 }
632 return str_replace($cat_tag, $doccat_terms, $url);
633 }
634
635 }
636
637 BetterDocs_Docs_Post_Type::init();
638