PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 2.5.2
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v2.5.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 / Utils / Helper.php

Helper.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 2.5.2, at includes/Utils/Helper.php

163 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDeveloper\BetterDocs\Utils;
4
5 class Helper extends Base {
6
7 public static function get_plugins( $plugin_basename = null ) {
8 if ( ! function_exists( 'get_plugins' ) ) {
9 include_once ABSPATH . 'wp-admin/includes/plugin.php';
10 }
11
12 $plugins = get_plugins();
13 return $plugin_basename == null ? $plugins : isset( $plugins[$plugin_basename] );
14 }
15
16 public static function is_plugin_active( $plugin_basename ) {
17 if ( ! function_exists( 'is_plugin_active' ) ) {
18 include_once ABSPATH . 'wp-admin/includes/plugin.php';
19 }
20
21 return is_plugin_active( $plugin_basename );
22 }
23
24 public static function get_tax( $tax = '' ) {
25 global $wp_query;
26
27 if ( is_tax( 'knowledge_base' ) ) {
28 $_taxes = $wp_query->tax_query->queried_terms;
29 if ( array_key_exists( "doc_category", $_taxes ) ) {
30 $tax = 'doc_category';
31 } else {
32 $tax = 'knowledge_base';
33 }
34 } elseif ( is_tax( 'doc_category' ) ) {
35 $tax = 'doc_category';
36 }
37
38 return $tax;
39 }
40
41 public function is_templates() {
42 $_return_val = betterdocs()->editor->get( 'elementor' )->is_templates();
43
44 if ( $_return_val !== null ) {
45 return $_return_val;
46 }
47
48 $tax = $this->get_tax();
49 if ( is_post_type_archive( 'docs' ) || $tax === 'knowledge_base' || $tax === 'doc_category' || is_singular( 'docs' ) ) {
50 return true;
51 }
52
53 return false;
54 }
55
56 /**
57 * Which tab to show.
58 *
59 * 1. Drag and Drop UI
60 * 2. Post List UI
61 *
62 * * 1. dnd
63 * * 2. classic
64 *
65 * look into views/admin/docs-ui directory to know more.
66 *
67 * @return string
68 */
69 public static function admin_tab() {
70 $admin_ui = 'grid';
71 if ( isset( $_GET['mode'], $_GET['page'] ) && $_GET['page'] === 'betterdocs-admin' && ! empty( $_GET['mode'] ) ) {
72 $admin_ui = $_GET['mode'] === 'grid' ? 'grid' : 'list';
73 }
74
75 return $admin_ui;
76 }
77
78 public static function is_active( $prev, $current, $class = 'active' ) {
79 if ( $current == $prev ) {
80 return $class;
81 }
82
83 return '';
84 }
85
86 public function get_users( $args ) {
87 $cache_key = 'betterdocs_cache_admin_user_roles';
88 $users = betterdocs()->database->get_cache( $cache_key );
89
90 if ( false === $users ) {
91 $users = get_users( $args );
92 betterdocs()->database->set_cache( $cache_key, $users );
93 }
94
95 return $users;
96 }
97
98 /**
99 * Normalize Menu Array
100 * Menu creator helper
101 *
102 * @since 2.5.0
103 *
104 * @param string $title
105 * @param string $slug
106 * @param string $cap
107 * @param array $callback
108 *
109 * @return array
110 */
111 public static function normalize_menu( $title, $slug, $cap = 'edit_docs', $callback = null ) {
112 $args = [
113 'page_title' => $title,
114 'menu_title' => $title,
115 'capability' => $cap,
116 'menu_slug' => $slug
117 ];
118
119 if ( $callback != null ) {
120 $args['callback'] = $callback;
121 }
122
123 return $args;
124 }
125
126 /**
127 * Check if the current theme is a block theme.
128 *
129 * @since x.x.x
130 * @return bool
131 */
132 public function current_theme_is_fse_theme() {
133 if ( function_exists( 'wp_is_block_theme' ) ) {
134 return (bool) wp_is_block_theme();
135 }
136 if ( function_exists( 'gutenberg_is_fse_theme' ) ) {
137 return (bool) gutenberg_is_fse_theme();
138 }
139
140 return false;
141 }
142
143 protected static function is_assoc_array( $array ) {
144 return array_keys( $array ) !== range( 0, count( $array ) - 1 );
145 }
146
147 public static function merge( &$array1, &$array2 ) {
148 $merged = $array1;
149
150 foreach ( $array2 as $key => &$value ) {
151 if ( is_array( $value ) && self::is_assoc_array( $value ) && isset( $merged[$key] ) && is_array( $merged[$key] ) ) {
152 $merged[$key] = self::merge( $merged[$key], $value );
153 } elseif ( is_array( $value ) && isset( $merged[$key] ) && is_array( $merged[$key] ) ) {
154 $merged[$key] = array_merge( $merged[$key], $value );
155 } else {
156 $merged[$key] = $value;
157 }
158 }
159
160 return $merged;
161 }
162 }
163