PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 2.0.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v2.0.3
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 / class-betterdocs.php

class-betterdocs.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 2.0.3, at includes/class-betterdocs.php

354 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The file that defines the core plugin class
5 *
6 * A class definition that includes attributes and functions used across both the
7 * public-facing side of the site and the admin area.
8 *
9 * @link https://wpdeveloper.com
10 * @since 1.0.0
11 *
12 * @package BetterDocs
13 * @subpackage BetterDocs/includes
14 */
15
16 /**
17 * The core plugin class.
18 *
19 * This is used to define internationalization, admin-specific hooks, and
20 * public-facing site hooks.
21 *
22 * Also maintains the unique identifier of this plugin as well as the current
23 * version of the plugin.
24 *
25 * @since 1.0.0
26 * @package BetterDocs
27 * @subpackage BetterDocs/includes
28 * @author WPDeveloper <support@wpdeveloper.com>
29 */
30 class BetterDocs
31 {
32
33 /**
34 * The loader that's responsible for maintaining and registering all hooks that power
35 * the plugin.
36 *
37 * @since 1.0.0
38 * @access protected
39 * @var BetterDocs_Loader $loader Maintains and registers all hooks for the plugin.
40 */
41 protected $loader;
42
43 /**
44 * The unique identifier of this plugin.
45 *
46 * @since 1.0.0
47 * @access protected
48 * @var string $plugin_name The string used to uniquely identify this plugin.
49 */
50 protected $plugin_name;
51
52 /**
53 * The current version of the plugin.
54 *
55 * @since 1.0.0
56 * @access protected
57 * @var string $version The current version of the plugin.
58 */
59 protected $version;
60
61 /**
62 * Define the core functionality of the plugin.
63 *
64 * Set the plugin name and the plugin version that can be used throughout the plugin.
65 * Load the dependencies, define the locale, and set the hooks for the admin area and
66 * the public-facing side of the site.
67 *
68 * @since 1.0.0
69 */
70 public function __construct()
71 {
72 if (defined('BETTER_DOCUMENTATION_VERSION')) {
73 $this->version = BETTER_DOCUMENTATION_VERSION;
74 } else {
75 $this->version = '1.0.0';
76 }
77 $this->plugin_name = 'betterdocs';
78
79 $this->load_dependencies();
80 $this->set_locale();
81 $this->start_plugin_tracking();
82 $this->define_admin_hooks();
83 $this->define_public_hooks();
84 add_action('admin_init', array($this, 'redirect'));
85 add_action('wp_ajax_optin_wizard_action_betterdocs', array($this, 'wizard_action'));
86 }
87
88 /**
89 * Load the required dependencies for this plugin.
90 *
91 * Include the following files that make up the plugin:
92 *
93 * - BetterDocs_Loader. Orchestrates the hooks of the plugin.
94 * - BetterDocs_i18n. Defines internationalization functionality.
95 * - BetterDocs_Admin. Defines all hooks for the admin area.
96 * - BetterDocs_Public. Defines all hooks for the public side of the site.
97 *
98 * Create an instance of the loader which will be used to register the hooks
99 * with WordPress.
100 *
101 * @since 1.0.0
102 * @access private
103 */
104 private function load_dependencies()
105 {
106 /**
107 * Quick Setup Wizard
108 */
109 require_once plugin_dir_path(dirname(__FILE__)) . 'admin/setup-wizard/betterdocs-setup-wizard-config.php';
110 /**
111 * The class responsible for orchestrating the actions and filters of the
112 * core plugin.
113 */
114 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-betterdocs-loader.php';
115
116 /**
117 * The class responsible for defining internationalization functionality
118 * of the plugin.
119 */
120 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-betterdocs-i18n.php';
121 require_once BETTERDOCS_DIR_PATH . 'includes/class-betterdocs-usage-tracker.php';
122 /**
123 * The class responsible for defining all actions that occur in the admin area.
124 */
125 require_once BETTERDOCS_ADMIN_DIR_PATH . 'class-betterdocs-admin.php';
126 require_once BETTERDOCS_ADMIN_DIR_PATH . 'class-betterdocs-admin-screen.php';
127 require_once BETTERDOCS_ADMIN_DIR_PATH . 'partials/class-betterdocs-list-table.php';
128 require_once BETTERDOCS_ADMIN_DIR_PATH . 'includes/class-betterdocs-db.php';
129 require_once BETTERDOCS_ADMIN_DIR_PATH . 'includes/class-betterdocs-metabox.php';
130 require_once BETTERDOCS_ADMIN_DIR_PATH . 'includes/class-betterdocs-settings.php';
131
132 /**
133 * Notice Messages
134 */
135 require_once BETTERDOCS_ADMIN_DIR_PATH . 'includes/class-betterdocs-notice.php';
136
137 /**
138 * The class responsible for defining all actions that occur in the public-facing
139 * side of the site.
140 */
141 require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-betterdocs-public.php';
142
143 /**
144 * The functions responsible for betterdocs helpers
145 */
146 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-betterdocs-helpers.php';
147
148 /**
149 * The class responsible for registering docs post type and it's category and tags taxonomy
150 */
151 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-betterdocs-docs-post-type.php';
152
153 /**
154 * The functions responsible for betterdocs shortcodes
155 */
156 require_once plugin_dir_path(dirname(__FILE__)) . 'public/betterdocs-shortcodes.php';
157
158 /**
159 * The functions responsible for betterdocs breadcrumbs
160 */
161 require_once plugin_dir_path(dirname(__FILE__)) . 'public/betterdocs-breadcrumbs.php';
162
163 /**
164 * The functions responsible for betterdocs customizer
165 */
166 require_once plugin_dir_path(dirname(__FILE__)) . 'admin/customizer/customizer.php';
167 require_once plugin_dir_path(dirname(__FILE__)) . 'admin/customizer/defaults.php';
168
169 /**
170 * The class responsible for registering widget in elementor and extend single page functionality
171 */
172 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/elementor/class-betterdocs-elementor.php';
173
174 /**
175 * The class responsible for registering widget in elementor and extend single page functionality
176 */
177 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/gutenberg/class-betterdocs-gutenberg.php';
178 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/gutenberg/class-style-handler.php';
179
180 $this->loader = new BetterDocs_Loader();
181 }
182
183 /**
184 * Optional usage tracker
185 *
186 * @since v1.0.0
187 */
188 public function start_plugin_tracking()
189 {
190 $tracker = BetterDocs_Plugin_Usage_Tracker::get_instance(BETTERDOCS_FILE, [
191 'opt_in' => true,
192 'goodbye_form' => true,
193 'item_id' => 'c7b16777b4f1b83f6083'
194 ]);
195 $tracker->set_notice_options(array(
196 'notice' => __('Want to help make <strong>BetterDocs</strong> even more awesome? You can get a <strong>10% discount coupon</strong> for Premium extensions if you allow us to track the usage.', 'betterdocs'),
197 'extra_notice' => __('We collect non-sensitive diagnostic data and plugin usage information.
198 Your site URL, WordPress & PHP version, plugins & themes and email address to send you the
199 discount coupon. This data lets us make sure this plugin always stays compatible with the most
200 popular plugins and themes. No spam, I promise.', 'betterdocs'),
201 ));
202 $tracker->init();
203 }
204
205 public function wizard_action()
206 {
207 if (!check_ajax_referer('betterdocsqswnonce', 'nonce')) {
208 return;
209 }
210 if ($this->do_wizard_tracking(true, $_POST)) {
211 wp_send_json_success('done');
212 }
213 wp_send_json_error('Something went wrong.');
214 }
215
216 public function do_wizard_tracking($force = false, $data = [])
217 {
218 if (!class_exists('BetterDocs_Plugin_Usage_Tracker')) {
219 require_once BETTERDOCS_DIR_PATH . 'includes/class-betterdocs-usage-tracker.php';
220 }
221 $tracker = BetterDocs_Plugin_Usage_Tracker::get_instance(BETTERDOCS_FILE, [
222 'opt_in' => true,
223 'goodbye_form' => true,
224 'item_id' => 'c7b16777b4f1b83f6083'
225 ]);
226 // If the home site hasn't been defined, we just drop out. Nothing much we can do.
227 if (empty($tracker::API_URL)) {
228 return false;
229 }
230 // Get our data
231 $body = $tracker->get_data();
232 if (isset($data['admin_email']) && !empty($data['admin_email'])) {
233 $body['email'] = $data['admin_email'];
234 }
235 // Send the data
236 return $tracker->send_data($body);
237 }
238
239 /**
240 * Define the locale for this plugin for internationalization.
241 *
242 * Uses the BetterDocs_i18n class in order to set the domain and to register the hook
243 * with WordPress.
244 *
245 * @since 1.0.0
246 * @access private
247 */
248 private function set_locale()
249 {
250 $plugin_i18n = new BetterDocs_i18n();
251 $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
252 }
253
254 /**
255 * Register all of the hooks related to the admin area functionality
256 * of the plugin.
257 *
258 * @since 1.0.0
259 * @access private
260 */
261 private function define_admin_hooks()
262 {
263 $plugin_admin = new BetterDocs_Admin($this->get_plugin_name(), $this->get_version());
264 add_action('admin_enqueue_scripts', array($plugin_admin, 'enqueue_styles'));
265 add_action('admin_enqueue_scripts', array($plugin_admin, 'enqueue_scripts'));
266 add_action('admin_bar_menu', array($plugin_admin, 'toolbar_menu'), 32);
267
268 $this->loader->add_filter('admin_body_class', $plugin_admin, 'body_classes');
269 $admin_screen = new Betterdocs_Admin_Screen();
270 $this->loader->add_action('betterdocs_listing_header', $admin_screen, 'header_template');
271
272 BetterDocs_Settings::init();
273 }
274
275 /**
276 * Register all of the hooks related to the public-facing functionality
277 * of the plugin.
278 *
279 * @since 1.0.0
280 * @access private
281 */
282 private function define_public_hooks()
283 {
284 $plugin_public = new BetterDocs_Public($this->get_plugin_name(), $this->get_version());
285 $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'load_assets');
286 }
287
288 /**
289 * Run the loader to execute all of the hooks with WordPress.
290 *
291 * @since 1.0.0
292 */
293 public function run()
294 {
295 $this->loader->run();
296 }
297
298 /**
299 * The name of the plugin used to uniquely identify it within the context of
300 * WordPress and to define internationalization functionality.
301 *
302 * @since 1.0.0
303 * @return string The name of the plugin.
304 */
305 public function get_plugin_name()
306 {
307 return $this->plugin_name;
308 }
309
310 /**
311 * The reference to the class that orchestrates the hooks with the plugin.
312 *
313 * @since 1.0.0
314 * @return BetterDocs_Loader Orchestrates the hooks of the plugin.
315 */
316 public function get_loader()
317 {
318 return $this->loader;
319 }
320
321 /**
322 * Retrieve the version number of the plugin.
323 *
324 * @since 1.0.0
325 * @return string The version number of the plugin.
326 */
327 public function get_version()
328 {
329 return $this->version;
330 }
331
332 public function is_pro_active()
333 {
334 return defined('BETTERDOCS_PRO_VERSION');
335 }
336
337 public function redirect()
338 {
339 // Bail if no activation transient is set.
340 if (!get_transient('_betterdocs_meta_activation_notice')) {
341 return;
342 }
343 // Delete the activation transient.
344 delete_transient('_betterdocs_meta_activation_notice');
345
346 if (!is_multisite()) {
347 // Redirect to the welcome page.
348 wp_safe_redirect(add_query_arg(array(
349 'page' => 'betterdocs-setup'
350 ), admin_url('admin.php?page=betterdocs-setup')));
351 }
352 }
353 }
354