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

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