PluginProbe
Knowledge Base documentation & wiki plugin – BasePress Docs / trunk
Knowledge Base documentation & wiki plugin – BasePress Docs vtrunk
basepress / basepress.php

basepress.php in Knowledge Base documentation & wiki plugin – BasePress Docs trunk, at basepress.php

516 lines 21.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Plugin Name: BasePress
5 * Plug URI: https://basepresskb.com/
6 * Description: The perfect Knowledge Base plugin for WordPress
7 * Version: 2.17.0.3
8 * Author: codeSavory
9 * Author URI: https://basepresskb.com/
10 * Text Domain: basepress
11 * Domain Path: /languages
12 * License: GPLv3 or later
13 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
14 *
15 */
16 // Exit if called directly.
17 if ( !defined( 'ABSPATH' ) ) {
18 exit;
19 }
20 if ( function_exists( 'base_fs' ) ) {
21 base_fs()->set_basename( false, __FILE__ );
22 return;
23 }
24 if ( !function_exists( 'base_fs' ) ) {
25 // Create a helper function for easy SDK access.
26 function base_fs() {
27 global $base_fs;
28 if ( !isset( $base_fs ) ) {
29 // Activate multisite network integration.
30 if ( !defined( 'WP_FS__PRODUCT_1252_MULTISITE' ) ) {
31 define( 'WP_FS__PRODUCT_1252_MULTISITE', true );
32 }
33 // Include Freemius SDK.
34 require_once dirname( __FILE__ ) . '/freemius/start.php';
35 $base_fs = fs_dynamic_init( array(
36 'id' => '1252',
37 'slug' => 'basepress',
38 'type' => 'plugin',
39 'public_key' => 'pk_4f447df1ddff73b6182b7022a1e7d',
40 'is_premium' => false,
41 'premium_suffix' => '',
42 'has_addons' => false,
43 'has_paid_plans' => true,
44 'menu' => array(
45 'slug' => 'basepress',
46 'first-path' => 'admin.php?page=basepress_wizard',
47 'support' => false,
48 ),
49 'is_live' => true,
50 ) );
51 }
52 // free code users if they ever had a licence show only the support menu which is the free forum
53 $base_fs->add_filter(
54 'is_submenu_visible',
55 function ( $is_visible, $menu_id ) {
56 if ( 'contact' === $menu_id ) {
57 return false;
58 }
59 if ( 'support' === $menu_id ) {
60 return true;
61 }
62 return $is_visible;
63 },
64 10,
65 2
66 );
67 return $base_fs;
68 }
69
70 // Init Freemius.
71 base_fs();
72 // Signal that SDK was initiated.
73 do_action( 'base_fs_loaded' );
74 //Add logo image on freemius optin screen
75 function my_fs_custom_icon() {
76 return dirname( __FILE__ ) . '/assets/img/logo.png';
77 }
78
79 //Freemius GDPR Admin notice
80 base_fs()->add_filter( 'handle_gdpr_admin_notice', '__return_true' );
81 base_fs()->add_filter( 'plugin_icon', 'my_fs_custom_icon' );
82 //Freemius unistall
83 base_fs()->add_action( 'after_uninstall', 'base_fs_uninstall_cleanup' );
84 define( 'BASEPRESS_DIR', plugin_dir_path( __FILE__ ) );
85 define( 'BASEPRESS_URI', plugin_dir_url( __FILE__ ) );
86 if ( !class_exists( 'Basepress' ) ) {
87 class Basepress {
88 /**
89 * Plugin version
90 *
91 * @var string
92 */
93 public $ver = '2.15.9';
94
95 /**
96 * Database version
97 *
98 * @var int
99 */
100 public $db_ver = 2.1;
101
102 /**
103 * Boot strap the plugin
104 *
105 * @since 1.0.0
106 * @updated 1.4.0, 1.5.0, 1.7.10
107 */
108 public function bootstrap() {
109 $this->define_constants();
110 //Add plugin icon on admin menu
111 add_action( 'admin_head', array($this, 'add_plugin_icon') );
112 //Load text domain
113 add_action( 'plugins_loaded', array($this, 'load_plugin_textdomain'), 10 );
114 //Register the function to run on activation
115 register_activation_hook( __FILE__, array($this, 'activate') );
116 //Register the function to run on deactivation
117 register_deactivation_hook( __FILE__, array($this, 'deactivate') );
118 //Add knowledge base post type
119 add_action( 'init', array($this, 'register_post_type') );
120 //Adds correct links on front-end admin bar to edit KBs and Sections
121 add_action( 'admin_bar_menu', array($this, 'basepress_admin_bar_edit'), 81 );
122 //Add basepress_variables class
123 require_once BASEPRESS_DIR . 'includes/class-basepress-variables.php';
124 //Add basepress_utils class
125 require_once BASEPRESS_DIR . 'includes/class-basepress-utils.php';
126 if ( is_admin() ) {
127 //Check if settings needs updating
128 add_action( 'init', array($this, 'init_options') );
129 //Add Help screen
130 require_once 'admin/class-basepress-manual.php';
131 //Add basepress template metabox for posts
132 require_once 'admin/class-basepress-template-metabox.php';
133 //Add basepress product metabox for posts
134 require_once 'admin/class-basepress-product-metabox.php';
135 //Add basepress section metabox for posts
136 require_once 'admin/class-basepress-section-metabox.php';
137 //Add basepress icon metabox for posts
138 require_once 'admin/class-basepress-post-icon-metabox.php';
139 //Add admin options page
140 require_once 'admin/class-basepress-settings.php';
141 //Add admin products page
142 require_once 'admin/class-basepress-products-page.php';
143 //Add admin sections page
144 require_once 'admin/class-basepress-sections-page.php';
145 //Manage the default terms edit screen for our taxonomy
146 require_once 'admin/class-basepress-terms-edit.php';
147 //Add icon manager page
148 require_once 'admin/icons-manager.php';
149 //Enqueue admin scripts and styles
150 add_action( 'admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 99 );
151 }
152 //Add Ajax Search
153 require_once BASEPRESS_DIR . 'includes/class-basepress-search.php';
154 //Add Views count
155 require_once BASEPRESS_DIR . 'includes/class-basepress-post-views.php';
156 //Add widgets
157 require_once 'includes/class-basepress-widgets.php';
158 //Add BasePress shortcodes
159 require_once 'includes/class-basepress-shortcodes.php';
160 //Add Public functions
161 require_once BASEPRESS_DIR . 'public/public-functions.php';
162 //Gutenberg blocks
163 require_once 'blocks/gb-blocks.php';
164 //BasePress Wizard
165 require_once 'admin/wizard.php';
166 //BasePress Debug
167 require_once 'includes/class-basepress-debug-output.php';
168 }
169
170 /**
171 * Define BasePress constants
172 *
173 * @since 1.7.10
174 */
175 private function define_constants() {
176 $this->define( 'BASEPRESS_DIR', plugin_dir_path( __FILE__ ) );
177 $this->define( 'BASEPRESS_URI', plugin_dir_url( __FILE__ ) );
178 $this->define( 'BASEPRESS_VER', $this->ver );
179 $this->define( 'BASEPRESS_DB_VER', $this->db_ver );
180 $this->define( 'BASEPRESS_PLAN', 'lite' );
181 }
182
183 /**
184 * Define constant if not already defined
185 *
186 * @since 1.7.10
187 *
188 * @param $name
189 * @param $value
190 */
191 private function define( $name, $value ) {
192 if ( !defined( $name ) ) {
193 define( $name, $value );
194 }
195 }
196
197 /**
198 * Adds plugin icon on Admin screen menu
199 *
200 * @since 1.7.0
201 *
202 * @return mixed
203 */
204 public function add_plugin_icon() {
205 echo '<style type="text/css">';
206 echo '#toplevel_page_basepress .wp-menu-image{background-repeat:no-repeat;background-position:center;background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAABHFJREFUeNq0VktsVGUU/u575t559jEdph1oGexYcTAUbHFhBA0sWLgybAxocMcCF6gxcWvcuiBxUcUHEhdKYmKjMRGJggtCrE1KKLS1LcNAp89poZ12nvd6/v/ezkxxWlzIzT1z507Of77z+M45I+DMxR4A50ni+P+vEZITIn2ce0IAcOyeZyC78WSvuEwfgv3dopvELJOYVRWB/BBF+8k1hZrzFr9hmbbUnmNnRInUBci1+q/sasSb+7ZjYWUV6cUVTC1lMTrzAOMLWcznyICk2EIHmUONLhE7gy50NhuI+NxoC+jY5tfR98cILo1MA6oOyEotiIlEyINjPTGoG7wFhlKz+LD/T1wZncJMNotQ0IuXOyM4ffBpdLeHoEkiSqaFEkyoFPHQeBKXBjKAR+DRbABZXVvjHl6bTGNw+G+EG/1oC4XwfGwbvj11FMP35tF3+S+cPLQXe6LN/NiDXAG/DU1gNDWN/c/E8MKuKDIL80B2CXB5yJ5eC2JxIObJ2Z+u45sLX0PTvWhqCSPeHsHR3j14+9WX8PHxIzxbp/u+R29XOxLREI69+xEerhVw7oNTOEAgEqtrIQeUS9yuWI8OLT7KpaYj7w7gflHB5bF5vPdFP7785RoH+KT/d5z9/ALuJlNoDfrwME9GjQAMr+GQRagSiS65HkiD4Yao+2B6GgBfE+VVhplbodSUeO4Xl5eJADJF2AqPYUANNKMguyEomkNAcQML64IUGRWZIh2CRt6pbtJUoZJBC6zAEmfODwNj+Pn2DKXdT46osESxJhJsDVKp0foBdpg8Z8AivVuSxB346soN2wnNy1lkPcLKx4PUwyWRCERab07FzWvBI6YiC0J9kLqFFzbxaP1ifWGDqHbDaURVWds0krogq4UCTQizDng1Iv4iOGlkQukql83/AOKMonjYD79bhWIVie/UoMVChfN2ucxq3eh3xSzCJ5bh1SSnr83Na6LJItasMt442I1EpAFXx2dwZ3ENg/eWMDCZwVg6w/VmM8vQRAHdHU14Lt6BznAQCXLsxXgbd1KVBHtg1gORZJl3vCVY2BffiZ6uWCU9fb8Owq8ryJfL1Okd2L3jdZw8cqCSQpOiYj3E3jVFcSa34KT5zEU7B+UidugmDkcNzM3NoTVA0zXSjGg4hEN7uxDUXVxthdLjkWzfCvT9x+s3cSc9i8n0HCbSC2jxaLg6ksLYMuvqCKAHayKhCJJLOXw2NUuWFoF8lgPrioRokx+J2Ha889ph9D7Vhlt3p/H+p99hdCKJFKUuWyI/JWIa6x+2CmgkwRO0KU4RVSNxiogiDbZingPALDm/5Tlo2FCwn0BuDN9GcpomrZua0O2zG5ImAtsdbARxINY7ioszrwoC52E6W86yKpOZAzKgXLYSYcVjl2EbE+XKJrTF2ahO4S2b9U4JmSKkR3jtsucX2w+lvO0IHzU13v9rNW+k8E2SZzfvbwefr17ZTkvt/t/C+PrfIhbPWw6Q9fjpZa/TinCKCluNOmb3xD8CDAAY1Iv4LsN16QAAAABJRU5ErkJggg==");}';
207 echo '</style>';
208 }
209
210 /**
211 * Load text domain
212 *
213 * @since 1.0.0
214 */
215 public function load_plugin_textdomain() {
216 load_plugin_textdomain( 'basepress', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
217 }
218
219 /**
220 * Functions to run only upon activation of the plugin
221 *
222 * @since 1.0.0
223 */
224 public function activate() {
225 $this->init_options();
226 $this->register_post_type();
227 add_action( 'shutdown', array($this, 'flush_rewrite_rules') );
228 }
229
230 /**
231 * Functions to run only upon deactivation of the plugin
232 *
233 * @since 1.0.0
234 */
235 public function deactivate() {
236 flush_rewrite_rules();
237 }
238
239 /**
240 * Flushes rewrite rules. Called during activation from add_action
241 *
242 * @since 1.0.0
243 */
244 public function flush_rewrite_rules() {
245 flush_rewrite_rules();
246 }
247
248 /**
249 * Registers the knowledge base post type
250 *
251 * @since 1.0.0
252 */
253 public function register_post_type() {
254 include_once 'includes/class-basepress-cpt.php';
255 }
256
257 /**
258 * Saves the plugin version on WP options table on activation
259 *
260 * @since 1.0.0
261 * @updated 1.4.0
262 */
263 public function init_options() {
264 //Initialize default option values
265 $options = get_option( 'basepress_settings' );
266 if ( empty( $options ) ) {
267 $options = (include_once BASEPRESS_DIR . 'options.php');
268 update_option( 'basepress_settings', $options );
269 update_option( 'basepress_ver', BASEPRESS_VER, true );
270 update_option( 'basepress_db_ver', BASEPRESS_DB_VER, true );
271 update_option( 'basepress_plan', BASEPRESS_PLAN, true );
272 update_option( 'basepress_run_wizard', 1, true );
273 }
274 $this->maybe_update();
275 }
276
277 /**
278 * Function to run on plugin update
279 *
280 * @since 1.7.10
281 */
282 public function maybe_update() {
283 //Load the update file
284 require_once __DIR__ . '/update.php';
285 //If this is not an ajax call trigger the update function in the included file
286 if ( !wp_doing_ajax() ) {
287 $old_ver = get_option( 'basepress_ver' );
288 $old_db_ver = get_option( 'basepress_db_ver' );
289 $old_plan = get_option( 'basepress_plan' );
290 if ( empty( $old_ver ) || $old_ver != BASEPRESS_VER || $old_db_ver != BASEPRESS_DB_VER || $old_plan != BASEPRESS_PLAN ) {
291 if ( current_user_can( 'update_plugins' ) ) {
292 basepress_update(
293 $old_ver,
294 $old_db_ver,
295 $old_plan,
296 BASEPRESS_VER,
297 BASEPRESS_DB_VER,
298 BASEPRESS_PLAN
299 );
300 }
301 }
302 }
303 }
304
305 /**
306 * Enqueue scripts for back end
307 *
308 * @since 1.0.0
309 *
310 * @param $screen
311 */
312 public function enqueue_admin_scripts( $screen ) {
313 global $basepress_utils;
314 $post_screens = array('edit.php', 'post.php', 'post-new.php');
315 $style_screens = array(
316 'knowledgebase_page_basepress_manage_kbs',
317 'knowledgebase_page_basepress_sections',
318 'knowledgebase_page_basepress_postorder',
319 'knowledgebase_page_basepress_feedback',
320 'settings_page_basepress',
321 'settings_page_basepress_network',
322 'toplevel_page_basepress',
323 'basepress_page_basepress_icons_manager',
324 'basepress_page_basepress_shortcode_editor'
325 );
326 $icons_screens = array(
327 'post.php',
328 'post-new.php',
329 'knowledgebase_page_basepress_sections',
330 'settings_page_basepress',
331 'settings_page_basepress_network',
332 'toplevel_page_basepress',
333 'basepress_page_basepress_icons_manager'
334 );
335 if ( 'knowledgebase' == get_post_type() && in_array( $screen, $post_screens ) ) {
336 wp_enqueue_style(
337 'basepress-post-editor',
338 plugins_url( 'admin/css/post-editor.css', __FILE__ ),
339 array(),
340 BASEPRESS_VER
341 );
342 }
343 if ( in_array( $screen, $icons_screens ) ) {
344 //Get icons url from active theme
345 $theme_icons = $basepress_utils->get_icons_uri();
346 wp_enqueue_style(
347 'basepress-icons',
348 $theme_icons,
349 array(),
350 BASEPRESS_VER
351 );
352 }
353 if ( in_array( $screen, $style_screens ) ) {
354 wp_enqueue_style(
355 'basepress-admin',
356 plugins_url( 'style.css', __FILE__ ),
357 array(),
358 BASEPRESS_VER
359 );
360 }
361 }
362
363 /**
364 * Modifies the edit links on front-end admin bar to point to BasePress custom pages to edit KBs and Sections
365 *
366 * @since 1.0.0
367 *
368 * @param $wp_admin_bar
369 */
370 public function basepress_admin_bar_edit( $wp_admin_bar ) {
371 if ( is_tax( 'knowledgebase_cat' ) ) {
372 //If there is no edit button on the admin bar return
373 if ( !$wp_admin_bar->get_node( 'edit' ) ) {
374 return;
375 }
376 $queried_object = get_queried_object();
377 //Edit menu for products
378 if ( 0 == $queried_object->parent ) {
379 $href = get_admin_url() . 'edit.php?post_type=knowledgebase&page=basepress_manage_kbs&product=' . $queried_object->term_id;
380 $title = esc_html__( 'Edit Knowledge Base', 'basepress' );
381 } else {
382 //Edit menu for sections
383 $href = get_admin_url() . 'edit.php?post_type=knowledgebase&page=basepress_sections&section=' . $queried_object->term_id;
384 $title = esc_html__( 'Edit Section', 'basepress' );
385 }
386 //Modify the admin menu
387 $wp_admin_bar->add_node( array(
388 'id' => 'edit',
389 'title' => $title,
390 'href' => $href,
391 ) );
392 }
393 }
394
395 /**
396 * Add WPML support
397 *
398 * @since 1.5.0
399 */
400 public function load_wpml_support() {
401 require_once BASEPRESS_DIR . 'includes/premium/class-basepress-wpml-support.php';
402 }
403
404 }
405
406 //Class end
407 global $basepress;
408 $basepress = new Basepress();
409 $basepress->bootstrap();
410 }
411 }
412 /**
413 * Unistallation function. Must be outside of class
414 *
415 * @since 1.6.0
416 *
417 * @return mixed
418 */
419 if ( !function_exists( 'base_fs_uninstall_cleanup' ) ) {
420 function base_fs_uninstall_cleanup() {
421 global $wpdb;
422 $options = get_site_option( 'basepress_settings' );
423 $remove_all = ( isset( $options['remove_all_uninstall'] ) ? true : false );
424 if ( !$remove_all ) {
425 return;
426 }
427 if ( !is_multisite() ) {
428 /*
429 * Delete all Articles from database
430 */
431 $args = array(
432 'post_type' => 'knowledgebase',
433 'post_status' => array(
434 'publish',
435 'pending',
436 'draft',
437 'auto-draft',
438 'future',
439 'private',
440 'inherit',
441 'trash'
442 ),
443 'suppress_filters' => true,
444 'cache_results' => false,
445 'update_post_meta_cache' => false,
446 'update_post_term_cache' => false,
447 'no_found_rows' => true,
448 'fields' => 'ids',
449 );
450 $wp_query = new WP_Query();
451 $bp_posts = $wp_query->query( $args );
452 foreach ( $bp_posts as $post ) {
453 wp_delete_post( $post, true );
454 }
455 /*
456 * Remove all Products and Sections
457 */
458 foreach ( array('knowledgebase_cat') as $taxonomy ) {
459 // Prepare & excecute SQL
460 $terms = $wpdb->get_results( $wpdb->prepare( "SELECT t.*, tt.* FROM {$wpdb->terms} AS t INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('%s') ORDER BY t.name ASC", $taxonomy ) );
461 // Delete Terms
462 if ( $terms ) {
463 foreach ( $terms as $term ) {
464 $wpdb->delete( $wpdb->term_taxonomy, array(
465 'term_taxonomy_id' => $term->term_taxonomy_id,
466 ) );
467 $wpdb->delete( $wpdb->term_relationships, array(
468 'term_taxonomy_id' => $term->term_taxonomy_id,
469 ) );
470 $wpdb->delete( $wpdb->termmeta, array(
471 'term_id' => $term->term_id,
472 ) );
473 $wpdb->delete( $wpdb->terms, array(
474 'term_id' => $term->term_id,
475 ) );
476 }
477 }
478 // Delete Taxonomy
479 $wpdb->delete( $wpdb->term_taxonomy, array(
480 'taxonomy' => $taxonomy,
481 ), array('%s') );
482 }
483 /*
484 * Remove single site options
485 */
486 delete_option( 'widget_basepress_products_widget' );
487 delete_option( 'widget_basepress_sections_widget' );
488 delete_option( 'widget_basepress_related_articles_widget' );
489 delete_option( 'widget_basepress_popular_articles_widget' );
490 delete_option( 'widget_basepress_toc_widget' );
491 delete_option( 'widget_basepress_tag_cloud' );
492 delete_option( 'widget_basepress_nav_widget' );
493 delete_option( 'knowledgebase_cat_children' );
494 delete_option( 'basepress_modern_theme' );
495 delete_option( 'basepress_default_theme' );
496 delete_option( 'basepress_zen_theme' );
497 delete_option( 'basepress_restriction_presets' );
498 delete_option( 'basepress_run_wizard' );
499 //Remove sidebars widgets
500 $sidebars = get_option( 'sidebars_widgets' );
501 if ( isset( $sidebars['basepress-sidebar'] ) ) {
502 unset($sidebars['basepress-sidebar']);
503 }
504 update_option( 'sidebars_widgets', $sidebars );
505 }
506 /*
507 * Remove single and multisite options
508 */
509 delete_site_option( 'basepress_settings' );
510 delete_site_option( 'basepress_ver' );
511 delete_site_option( 'basepress_db_ver' );
512 delete_site_option( 'basepress_plan' );
513 delete_site_option( 'basepress_run_wizard' );
514 }
515
516 }