PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.1.0
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.1.0
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 3.1.0, at includes/Utils/Helper.php

169 lines 4.5 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 } elseif ( is_tax( 'doc_tag' ) ) {
37 $tax = 'doc_tag';
38 }
39
40 return $tax;
41 }
42
43 public function is_templates() {
44 $tax = $this->get_tax();
45 if ( is_post_type_archive( 'docs' ) || $tax === 'knowledge_base' || $tax === 'doc_category' || $tax === 'doc_tag' || is_singular( 'docs' ) ) {
46 return true;
47 }
48
49 return false;
50 }
51
52 public function is_el_templates() {
53 $_return_val = betterdocs()->editor->get( 'elementor' )->is_templates();
54
55 if ( $_return_val !== null ) {
56 return $_return_val;
57 }
58
59 $this->is_templates();
60 }
61
62 /**
63 * Which tab to show.
64 *
65 * 1. Drag and Drop UI
66 * 2. Post List UI
67 *
68 * * 1. dnd
69 * * 2. classic
70 *
71 * look into views/admin/docs-ui directory to know more.
72 *
73 * @return string
74 */
75 public static function admin_tab() {
76 $admin_ui = 'grid';
77 if ( isset( $_GET['mode'], $_GET['page'] ) && $_GET['page'] === 'betterdocs-admin' && ! empty( $_GET['mode'] ) ) {
78 $admin_ui = $_GET['mode'] === 'grid' ? 'grid' : 'list';
79 }
80
81 return $admin_ui;
82 }
83
84 public static function is_active( $prev, $current, $class = 'active' ) {
85 if ( $current == $prev ) {
86 return $class;
87 }
88
89 return '';
90 }
91
92 public function get_users( $args ) {
93 $cache_key = 'betterdocs_cache_admin_user_roles';
94 $users = betterdocs()->database->get_cache( $cache_key );
95
96 if ( false === $users ) {
97 $users = get_users( $args );
98 betterdocs()->database->set_cache( $cache_key, $users );
99 }
100
101 return $users;
102 }
103
104 /**
105 * Normalize Menu Array
106 * Menu creator helper
107 *
108 * @since 2.5.0
109 *
110 * @param string $title
111 * @param string $slug
112 * @param string $cap
113 * @param array $callback
114 *
115 * @return array
116 */
117 public static function normalize_menu( $title, $slug, $cap = 'edit_docs', $callback = null ) {
118 $args = [
119 'page_title' => $title,
120 'menu_title' => $title,
121 'capability' => $cap,
122 'menu_slug' => $slug
123 ];
124
125 if ( $callback != null ) {
126 $args['callback'] = $callback;
127 }
128
129 return $args;
130 }
131
132 /**
133 * Check if the current theme is a block theme.
134 *
135 * @since x.x.x
136 * @return bool
137 */
138 public function current_theme_is_fse_theme() {
139 if ( function_exists( 'wp_is_block_theme' ) ) {
140 return (bool) wp_is_block_theme();
141 }
142 if ( function_exists( 'gutenberg_is_fse_theme' ) ) {
143 return (bool) gutenberg_is_fse_theme();
144 }
145
146 return false;
147 }
148
149 protected static function is_assoc_array( $array ) {
150 return array_keys( $array ) !== range( 0, count( $array ) - 1 );
151 }
152
153 public static function merge( &$array1, &$array2 ) {
154 $merged = $array1;
155
156 foreach ( $array2 as $key => &$value ) {
157 if ( is_array( $value ) && self::is_assoc_array( $value ) && isset( $merged[$key] ) && is_array( $merged[$key] ) ) {
158 $merged[$key] = self::merge( $merged[$key], $value );
159 } elseif ( is_array( $value ) && isset( $merged[$key] ) && is_array( $merged[$key] ) ) {
160 $merged[$key] = array_merge( $merged[$key], $value );
161 } else {
162 $merged[$key] = $value;
163 }
164 }
165
166 return $merged;
167 }
168 }
169