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