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

358 lines 10.7 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 if (is_admin()) {
85 new Betterdocs_Role_Management_Lite();
86 }
87 add_action('admin_init', array($this, 'redirect'));
88 add_action('wp_ajax_optin_wizard_action_betterdocs', array($this, 'wizard_action'));
89 }
90
91 /**
92 * Load the required dependencies for this plugin.
93 *
94 * Include the following files that make up the plugin:
95 *
96 * - BetterDocs_Loader. Orchestrates the hooks of the plugin.
97 * - BetterDocs_i18n. Defines internationalization functionality.
98 * - BetterDocs_Admin. Defines all hooks for the admin area.
99 * - BetterDocs_Public. Defines all hooks for the public side of the site.
100 *
101 * Create an instance of the loader which will be used to register the hooks
102 * with WordPress.
103 *
104 * @since 1.0.0
105 * @access private
106 */
107 private function load_dependencies()
108 {
109 /**
110 * Quick Setup Wizard
111 */
112 require_once plugin_dir_path(dirname(__FILE__)) . 'admin/setup-wizard/betterdocs-setup-wizard-config.php';
113 /**
114 * The class responsible for orchestrating the actions and filters of the
115 * core plugin.
116 */
117 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-betterdocs-loader.php';
118
119 /**
120 * The class responsible for defining internationalization functionality
121 * of the plugin.
122 */
123 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-betterdocs-i18n.php';
124 require_once BETTERDOCS_DIR_PATH . 'includes/class-betterdocs-usage-tracker.php';
125 /**
126 * The class responsible for defining all actions that occur in the admin area.
127 */
128 require_once BETTERDOCS_ADMIN_DIR_PATH . 'class-betterdocs-admin.php';
129 require_once BETTERDOCS_ADMIN_DIR_PATH . 'class-betterdocs-admin-screen.php';
130 require_once BETTERDOCS_ADMIN_DIR_PATH . 'partials/class-betterdocs-list-table.php';
131 require_once BETTERDOCS_ADMIN_DIR_PATH . 'includes/class-betterdocs-db.php';
132 require_once BETTERDOCS_ADMIN_DIR_PATH . 'includes/class-betterdocs-metabox.php';
133 require_once BETTERDOCS_ADMIN_DIR_PATH . 'includes/class-betterdocs-settings.php';
134 require_once BETTERDOCS_ADMIN_DIR_PATH . 'includes/class-betterdocs-role-management-lite.php';
135
136 /**
137 * Notice Messages
138 */
139 require_once BETTERDOCS_ADMIN_DIR_PATH . 'includes/class-betterdocs-notice.php';
140
141 /**
142 * The class responsible for defining all actions that occur in the public-facing
143 * side of the site.
144 */
145 require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-betterdocs-public.php';
146
147 /**
148 * The functions responsible for betterdocs helpers
149 */
150 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-betterdocs-helpers.php';
151
152 /**
153 * The class responsible for registering docs post type and it's category and tags taxonomy
154 */
155 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-betterdocs-docs-post-type.php';
156
157 /**
158 * The functions responsible for betterdocs shortcodes
159 */
160 require_once plugin_dir_path(dirname(__FILE__)) . 'public/betterdocs-shortcodes.php';
161
162 /**
163 * The functions responsible for betterdocs breadcrumbs
164 */
165 require_once plugin_dir_path(dirname(__FILE__)) . 'public/betterdocs-breadcrumbs.php';
166
167 /**
168 * The functions responsible for betterdocs customizer
169 */
170 require_once plugin_dir_path(dirname(__FILE__)) . 'admin/customizer/customizer.php';
171 require_once plugin_dir_path(dirname(__FILE__)) . 'admin/customizer/defaults.php';
172
173 /**
174 * The class responsible for registering widget in elementor and extend single page functionality
175 */
176 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/elementor/class-betterdocs-elementor.php';
177
178 /**
179 * The class responsible for registering widget in elementor and extend single page functionality
180 */
181 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/gutenberg/class-betterdocs-gutenberg.php';
182 require_once plugin_dir_path(dirname(__FILE__)) . 'includes/gutenberg/class-style-handler.php';
183
184 $this->loader = new BetterDocs_Loader();
185 }
186
187 /**
188 * Optional usage tracker
189 *
190 * @since v1.0.0
191 */
192 public function start_plugin_tracking()
193 {
194 $tracker = BetterDocs_Plugin_Usage_Tracker::get_instance(BETTERDOCS_FILE, [
195 'opt_in' => true,
196 'goodbye_form' => true,
197 'item_id' => 'c7b16777b4f1b83f6083'
198 ]);
199 $tracker->set_notice_options(array(
200 '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'),
201 'extra_notice' => __('We collect non-sensitive diagnostic data and plugin usage information.
202 Your site URL, WordPress & PHP version, plugins & themes and email address to send you the
203 discount coupon. This data lets us make sure this plugin always stays compatible with the most
204 popular plugins and themes. No spam, I promise.', 'betterdocs'),
205 ));
206 $tracker->init();
207 }
208
209 public function wizard_action()
210 {
211 if (!check_ajax_referer('betterdocsqswnonce', 'nonce')) {
212 return;
213 }
214 if ($this->do_wizard_tracking(true, $_POST)) {
215 wp_send_json_success('done');
216 }
217 wp_send_json_error('Something went wrong.');
218 }
219
220 public function do_wizard_tracking($force = false, $data = [])
221 {
222 if (!class_exists('BetterDocs_Plugin_Usage_Tracker')) {
223 require_once BETTERDOCS_DIR_PATH . 'includes/class-betterdocs-usage-tracker.php';
224 }
225 $tracker = BetterDocs_Plugin_Usage_Tracker::get_instance(BETTERDOCS_FILE, [
226 'opt_in' => true,
227 'goodbye_form' => true,
228 'item_id' => 'c7b16777b4f1b83f6083'
229 ]);
230 // If the home site hasn't been defined, we just drop out. Nothing much we can do.
231 if (empty($tracker::API_URL)) {
232 return false;
233 }
234 // Get our data
235 $body = $tracker->get_data();
236 if (isset($data['admin_email']) && !empty($data['admin_email'])) {
237 $body['email'] = $data['admin_email'];
238 }
239 // Send the data
240 return $tracker->send_data($body);
241 }
242
243 /**
244 * Define the locale for this plugin for internationalization.
245 *
246 * Uses the BetterDocs_i18n class in order to set the domain and to register the hook
247 * with WordPress.
248 *
249 * @since 1.0.0
250 * @access private
251 */
252 private function set_locale()
253 {
254 $plugin_i18n = new BetterDocs_i18n();
255 $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
256 }
257
258 /**
259 * Register all of the hooks related to the admin area functionality
260 * of the plugin.
261 *
262 * @since 1.0.0
263 * @access private
264 */
265 private function define_admin_hooks()
266 {
267 $plugin_admin = new BetterDocs_Admin($this->get_plugin_name(), $this->get_version());
268 add_action('admin_enqueue_scripts', array($plugin_admin, 'enqueue_styles'));
269 add_action('admin_enqueue_scripts', array($plugin_admin, 'enqueue_scripts'));
270 add_action('admin_bar_menu', array($plugin_admin, 'toolbar_menu'), 32);
271
272 $this->loader->add_filter('admin_body_class', $plugin_admin, 'body_classes');
273 $admin_screen = new Betterdocs_Admin_Screen();
274 $this->loader->add_action('betterdocs_listing_header', $admin_screen, 'header_template');
275
276 BetterDocs_Settings::init();
277 }
278
279 /**
280 * Register all of the hooks related to the public-facing functionality
281 * of the plugin.
282 *
283 * @since 1.0.0
284 * @access private
285 */
286 private function define_public_hooks()
287 {
288 $plugin_public = new BetterDocs_Public($this->get_plugin_name(), $this->get_version());
289 $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'load_assets');
290 }
291
292 /**
293 * Run the loader to execute all of the hooks with WordPress.
294 *
295 * @since 1.0.0
296 */
297 public function run()
298 {
299 $this->loader->run();
300 }
301
302 /**
303 * The name of the plugin used to uniquely identify it within the context of
304 * WordPress and to define internationalization functionality.
305 *
306 * @since 1.0.0
307 * @return string The name of the plugin.
308 */
309 public function get_plugin_name()
310 {
311 return $this->plugin_name;
312 }
313
314 /**
315 * The reference to the class that orchestrates the hooks with the plugin.
316 *
317 * @since 1.0.0
318 * @return BetterDocs_Loader Orchestrates the hooks of the plugin.
319 */
320 public function get_loader()
321 {
322 return $this->loader;
323 }
324
325 /**
326 * Retrieve the version number of the plugin.
327 *
328 * @since 1.0.0
329 * @return string The version number of the plugin.
330 */
331 public function get_version()
332 {
333 return $this->version;
334 }
335
336 public function is_pro_active()
337 {
338 return defined('BETTERDOCS_PRO_VERSION');
339 }
340
341 public function redirect()
342 {
343 // Bail if no activation transient is set.
344 if (!get_transient('_betterdocs_meta_activation_notice')) {
345 return;
346 }
347 // Delete the activation transient.
348 delete_transient('_betterdocs_meta_activation_notice');
349
350 if (!is_multisite()) {
351 // Redirect to the welcome page.
352 wp_safe_redirect(add_query_arg(array(
353 'page' => 'betterdocs-setup'
354 ), admin_url('admin.php?page=betterdocs-setup')));
355 }
356 }
357 }
358