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

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