PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.3
4.9.3 4.9.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 All 201 releases
← All changes | includes/Editors/Elementor/Traits/TemplateQuery.php +208 -206 3.4.2 → 4.9.3 View file →
@@ -1,249 +1,251 @@
1 1 <?php
2 2 namespace WPDeveloper\BetterDocs\Editors\Elementor\Traits;
3 3
4 4 if ( ! defined( 'ABSPATH' ) ) {
5 - exit; // Exit if accessed directly
5 + exit; // Exit if accessed directly
6 6 }
7 7
8 8 trait TemplateQuery {
9 - public $current_widget_name = '';
9 + public $current_widget_name = '';
10 10
11 - public function set_widget_name( $name = '' ) {
12 - $this->current_widget_name = $name;
13 - }
11 + public function set_widget_name( $name = '' ) {
12 + $this->current_widget_name = $name;
13 + }
14 14
15 - /**
16 - * Retrieves Template name from file header.
17 - *
18 - * @array
19 - */
20 - private $template_headers = [
21 - 'Template Name' => 'Template Name'
22 - ];
15 + /**
16 + * Retrieves Template name from file header.
17 + *
18 + * @array
19 + */
20 + private $template_headers = [
21 + 'Template Name' => 'Template Name'
22 + ];
23 23
24 - /**
25 - * Prepare the directory name from the following widget name.
26 - *
27 - * @access private
28 - *
29 - *
30 - * @return string $widget_name
31 - */
32 - private function process_directory_name() {
33 - if ( empty( $this->current_widget_name ) ) {
34 - $this->current_widget_name = $this->get_name();
35 - }
24 + /**
25 + * Prepare the directory name from the following widget name.
26 + *
27 + * @access private
28 + *
29 + *
30 + * @return string $widget_name
31 + */
32 + private function process_directory_name() {
33 + if ( empty( $this->current_widget_name ) ) {
34 + $this->current_widget_name = $this->get_name();
35 + }
36 36
37 - $widget_name = str_replace( 'betterdocs-', '', $this->current_widget_name );
38 - $widget_name = str_replace( '-', ' ', $widget_name );
39 - $widget_name = ucwords( $widget_name );
40 - $widget_name = str_replace( ' ', '-', $widget_name );
37 + $widget_name = str_replace( 'betterdocs-', '', $this->current_widget_name );
38 + $widget_name = str_replace( '-', ' ', $widget_name );
39 + $widget_name = ucwords( $widget_name );
40 + $widget_name = str_replace( ' ', '-', $widget_name );
41 41
42 - return $widget_name;
43 - }
42 + return $widget_name;
43 + }
44 44
45 - /**
46 - * Retrieve `Theme Template Directory`
47 - *
48 - * @return string templates directory from the active theme.
49 - */
50 - private function theme_templates_dir() {
51 - $current_theme = wp_get_theme();
45 + /**
46 + * Retrieve `Theme Template Directory`
47 + *
48 + * @return string templates directory from the active theme.
49 + */
50 + private function theme_templates_dir() {
51 + $current_theme = wp_get_theme();
52 52
53 - $dir = sprintf(
54 - '%s/%s/Template/%s',
55 - $current_theme->theme_root,
56 - $current_theme->stylesheet,
57 - $this->process_directory_name()
58 - );
53 + $dir = sprintf(
54 + '%s/%s/Template/%s',
55 + $current_theme->theme_root,
56 + $current_theme->stylesheet,
57 + $this->process_directory_name()
58 + );
59 59
60 - if ( is_dir( $dir ) ) {
61 - $file = scandir( $dir );
62 - $file = array_pop( $file );
60 + if ( is_dir( $dir ) ) {
61 + $file = scandir( $dir );
62 + $file = array_pop( $file );
63 63
64 - return pathinfo( $file, PATHINFO_EXTENSION ) === 'php' ? $dir : false;
65 - }
64 + return pathinfo( $file, PATHINFO_EXTENSION ) === 'php' ? $dir : false;
65 + }
66 66
67 - return false;
68 - }
67 + return false;
68 + }
69 69
70 - /**
71 - * Retrieves the lite plugin template directory path.
72 - *
73 - * @return string templates directory path of lite version.
74 - */
75 - private function get_template_dir() {
76 - return \sprintf(
77 - '%sincludes/elementor/Template/%s',
78 - BETTERDOCS_ABSPATH, $this->process_directory_name()
79 - );
80 - }
70 + /**
71 + * Retrieves the lite plugin template directory path.
72 + *
73 + * @return string templates directory path of lite version.
74 + */
75 + private function get_template_dir() {
76 + return \sprintf(
77 + '%sincludes/elementor/Template/%s',
78 + BETTERDOCS_ABSPATH,
79 + $this->process_directory_name()
80 + );
81 + }
81 82
82 - /**
83 - * Retrieves the pro plugin template directory path.
84 - *
85 - * @return string templates directory path of pro version.
86 - */
87 - private function get_pro_template_dir() {
88 - include_once ABSPATH . 'wp-admin/includes/plugin.php';
89 - if ( ! is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' ) ) {
90 - return false;
91 - }
83 + /**
84 + * Retrieves the pro plugin template directory path.
85 + *
86 + * @return string templates directory path of pro version.
87 + */
88 + private function get_pro_template_dir() {
89 + include_once ABSPATH . 'wp-admin/includes/plugin.php';
90 + if ( ! is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' ) ) {
91 + return false;
92 + }
92 93
93 - return \sprintf(
94 - '%sincludes/elementor/Template/%s',
95 - BETTERDOCS_PRO_ROOT_DIR_PATH, $this->process_directory_name()
96 - );
97 - }
94 + return \sprintf(
95 + '%sincludes/elementor/Template/%s',
96 + BETTERDOCS_PRO_ROOT_DIR_PATH,
97 + $this->process_directory_name()
98 + );
99 + }
98 100
99 - /**
100 - * Collecting templates from different sources.
101 - *
102 - * @return array
103 - */
104 - private function get_template_files() {
105 - $templates = [];
101 + /**
102 + * Collecting templates from different sources.
103 + *
104 + * @return array
105 + */
106 + private function get_template_files() {
107 + $templates = [];
106 108
107 - if ( is_dir( $this->get_template_dir() ) ) {
108 - $templates['lite'] = scandir( $this->get_template_dir(), 1 );
109 - }
109 + if ( is_dir( $this->get_template_dir() ) ) {
110 + $templates['lite'] = scandir( $this->get_template_dir(), 1 );
111 + }
110 112
111 - if ( is_dir( $this->get_pro_template_dir() ) ) {
112 - $templates['pro'] = scandir( $this->get_pro_template_dir(), 1 );
113 - }
113 + if ( is_dir( $this->get_pro_template_dir() ) ) {
114 + $templates['pro'] = scandir( $this->get_pro_template_dir(), 1 );
115 + }
114 116
115 - if ( $this->theme_templates_dir() ) {
116 - $templates['theme'] = scandir( $this->theme_templates_dir(), 1 );
117 - }
117 + if ( $this->theme_templates_dir() ) {
118 + $templates['theme'] = scandir( $this->theme_templates_dir(), 1 );
119 + }
118 120
119 - return $templates;
120 - }
121 + return $templates;
122 + }
121 123
122 - /**
123 - * Retrieves template list from template directory.
124 - *
125 - * @return array template list.
126 - */
127 - protected function get_template_list() {
128 - $files = [];
124 + /**
125 + * Retrieves template list from template directory.
126 + *
127 + * @return array template list.
128 + */
129 + protected function get_template_list() {
130 + $files = [];
129 131
130 - if ( $this->get_template_files() ) {
131 - foreach ( $this->get_template_files() as $key => $handler ) {
132 - foreach ( $handler as $handle ) {
133 - if ( strpos( $handle, '.php' ) !== false ) {
134 - if ( $key === 'lite' ) {
135 - $path = sprintf( '%s/%s', $this->get_template_dir(), $handle );
136 - } else if ( $key === 'pro' ) {
137 - $path = sprintf( '%s/%s', $this->get_pro_template_dir(), $handle );
138 - } else if ( $key === 'theme' ) {
139 - $path = sprintf( '%s/%s', $this->theme_templates_dir(), $handle );
140 - }
132 + if ( $this->get_template_files() ) {
133 + foreach ( $this->get_template_files() as $key => $handler ) {
134 + foreach ( $handler as $handle ) {
135 + if ( strpos( $handle, '.php' ) !== false ) {
136 + if ( $key === 'lite' ) {
137 + $path = sprintf( '%s/%s', $this->get_template_dir(), $handle );
138 + } elseif ( $key === 'pro' ) {
139 + $path = sprintf( '%s/%s', $this->get_pro_template_dir(), $handle );
140 + } elseif ( $key === 'theme' ) {
141 + $path = sprintf( '%s/%s', $this->theme_templates_dir(), $handle );
142 + }
141 143
142 - $template_info = get_file_data( $path, $this->template_headers );
143 - $template_name = $template_info['Template Name'];
144 + $template_info = get_file_data( $path, $this->template_headers );
145 + $template_name = $template_info['Template Name'];
144 146
145 - if ( $template_name ) {
146 - $files[$template_name] = $path;
147 - }
148 - }
149 - }
150 - }
151 - }
147 + if ( $template_name ) {
148 + $files[ $template_name ] = $path;
149 + }
150 + }
151 + }
152 + }
153 + }
152 154
153 - return $files;
154 - }
155 + return $files;
156 + }
155 157
156 - /**
157 - * Retrieves template list from template directory.
158 - *
159 - * @return array template list.
160 - */
161 - public function get_template_list_for_dropdown() {
162 - $files = [];
163 - if ( $this->get_template_files() ) {
164 - foreach ( $this->get_template_files() as $key => $handler ) {
165 - foreach ( $handler as $handle ) {
166 - if ( strpos( $handle, '.php' ) !== false ) {
167 - $path = $this->_get_path( $key, $handle );
168 - $template_info = get_file_data( $path, $this->template_headers );
169 - $template_name = $template_info['Template Name'];
170 - $template_key = str_replace( ' ', '-', strtolower( $template_name ) );
171 - if ( $template_name ) {
172 - $files[$template_key] = sprintf( "%s (%s)", ucfirst( $template_name ), ucfirst( $key ) );
173 - }
174 - }
175 - }
176 - }
177 - }
178 - return $files;
179 - }
158 + /**
159 + * Retrieves template list from template directory.
160 + *
161 + * @return array template list.
162 + */
163 + public function get_template_list_for_dropdown() {
164 + $files = [];
165 + if ( $this->get_template_files() ) {
166 + foreach ( $this->get_template_files() as $key => $handler ) {
167 + foreach ( $handler as $handle ) {
168 + if ( strpos( $handle, '.php' ) !== false ) {
169 + $path = $this->_get_path( $key, $handle );
170 + $template_info = get_file_data( $path, $this->template_headers );
171 + $template_name = $template_info['Template Name'];
172 + $template_key = str_replace( ' ', '-', strtolower( $template_name ) );
173 + if ( $template_name ) {
174 + $files[ $template_key ] = sprintf( '%s (%s)', ucfirst( $template_name ), ucfirst( $key ) );
175 + }
176 + }
177 + }
178 + }
179 + }
180 + return $files;
181 + }
180 182
181 - public function _get_path( $key, $handle ) {
182 - $path = '';
183 - if ( $key === 'lite' ) {
184 - $path = sprintf( '%s/%s', $this->get_template_dir(), $handle );
185 - } else if ( $key === 'pro' ) {
186 - $path = sprintf( '%s/%s', $this->get_pro_template_dir(), $handle );
187 - } else if ( $key === 'theme' ) {
188 - $path = sprintf( '%s/%s', $this->theme_templates_dir(), $handle );
189 - }
190 - return $path;
191 - }
183 + public function _get_path( $key, $handle ) {
184 + $path = '';
185 + if ( $key === 'lite' ) {
186 + $path = sprintf( '%s/%s', $this->get_template_dir(), $handle );
187 + } elseif ( $key === 'pro' ) {
188 + $path = sprintf( '%s/%s', $this->get_pro_template_dir(), $handle );
189 + } elseif ( $key === 'theme' ) {
190 + $path = sprintf( '%s/%s', $this->theme_templates_dir(), $handle );
191 + }
192 + return $path;
193 + }
192 194
193 - /**
194 - * Preparing template options for frontend select
195 - *
196 - * @return array teplate select options.
197 - */
198 - private function get_template_options() {
199 - $files = [];
195 + /**
196 + * Preparing template options for frontend select
197 + *
198 + * @return array teplate select options.
199 + */
200 + private function get_template_options() {
201 + $files = [];
200 202
201 - if ( $this->get_template_list() ) {
202 - foreach ( $this->get_template_list() as $filename => $path ) {
203 - $filename = \str_replace( ' ', '-', $filename );
203 + if ( $this->get_template_list() ) {
204 + foreach ( $this->get_template_list() as $filename => $path ) {
205 + $filename = \str_replace( ' ', '-', $filename );
204 206
205 - $files[strtolower( $filename )] = $path;
206 - }
207 - }
207 + $files[ strtolower( $filename ) ] = $path;
208 + }
209 + }
208 210
209 - return $files;
210 - }
211 + return $files;
212 + }
211 213
212 - /**
213 - * Adding key value pairs in template options.
214 - *
215 - * @return array
216 - */
217 - private function template_options() {
218 - $keys = array_keys( $this->get_template_options() );
219 - $values = array_keys( $this->get_template_list() );
214 + /**
215 + * Adding key value pairs in template options.
216 + *
217 + * @return array
218 + */
219 + private function template_options() {
220 + $keys = array_keys( $this->get_template_options() );
221 + $values = array_keys( $this->get_template_list() );
220 222
221 - return array_combine( $keys, $values );
222 - }
223 + return array_combine( $keys, $values );
224 + }
223 225
224 - /**
225 - * Retrieve template
226 - *
227 - * @param string $filename
228 - *
229 - * @return string include-able full template path.
230 - */
231 - public function get_template( $filename ) {
232 - if ( in_array( $filename, array_keys( $this->get_template_options() ) ) ) {
233 - return $this->get_template_options()[$filename];
234 - }
226 + /**
227 + * Retrieve template
228 + *
229 + * @param string $filename
230 + *
231 + * @return string include-able full template path.
232 + */
233 + public function get_template( $filename ) {
234 + if ( in_array( $filename, array_keys( $this->get_template_options() ) ) ) {
235 + return $this->get_template_options()[ $filename ];
236 + }
235 237
236 - return false;
237 - }
238 + return false;
239 + }
238 240
239 - /**
240 - * Set default option in frontend select control.
241 - *
242 - * @return string first option.
243 - */
244 - public function get_default() {
245 - $dt = array_reverse( $this->template_options() );
241 + /**
242 + * Set default option in frontend select control.
243 + *
244 + * @return string first option.
245 + */
246 + public function get_default() {
247 + $dt = array_reverse( $this->template_options() );
246 248
247 - return strtolower( array_pop( $dt ) );
248 - }
249 + return strtolower( array_pop( $dt ) );
250 + }
249 251 }