PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / trunk
Forumax – AI Powered Advanced Community Forum Plugin vtrunk
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / includes / docy-core-compatibility.php

docy-core-compatibility.php in Forumax – AI Powered Advanced Community Forum Plugin trunk, at includes/docy-core-compatibility.php

85 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Docy Core Compatibility Layer
4 *
5 * Fixes compatibility issues between Forumax and older versions of Docy Core plugin.
6 *
7 * The issue:
8 * - Old Docy Core (v4.3.1 and below) had Forums widget that conflicted with Forumax
9 * - New Docy Core (v4.3.2+) removed Forums widget (now handled by Forumax)
10 * - During update transition, class conflicts can occur
11 *
12 * Solution:
13 * - Detect docy-core version
14 * - Only load Forums_widget.php if it exists in old version
15 * - Prevent duplicate class declarations
16 * - Unregister old widgets and register new Forumax widgets
17 *
18 * @package Forumax
19 * @since 2.1.1
20 */
21
22 defined( 'ABSPATH' ) || exit;
23
24 /**
25 * Handle Docy Core Forums Widget Compatibility
26 *
27 * This function ensures smooth transition from old docy-core to new version
28 * and prevents "class already declared" errors.
29 */
30 function forumax_handle_docy_core_compatibility() {
31 // Only proceed if bbPress is active
32 if ( ! class_exists( 'bbPress' ) ) {
33 return;
34 }
35
36 // Check if docy-core plugin is active
37 if ( ! defined( 'DOCY_CORE_VERSION' ) && ! class_exists( 'Docy_core' ) ) {
38 return;
39 }
40
41 // Path to the Forums_widget.php file in docy-core
42 $forums_widget_file = WP_PLUGIN_DIR . '/docy-core/wp-widgets/Forums_widget.php';
43
44 // Get docy-core version
45 $docy_version = defined( 'DOCY_CORE_VERSION' ) ? DOCY_CORE_VERSION : '0.0.0';
46 if ( class_exists( 'Docy_core' ) && defined( 'Docy_core::VERSION' ) ) {
47 $docy_version = Docy_core::VERSION;
48 }
49
50 // Check if this is old docy-core version (has Forums widget)
51 $is_old_docy = file_exists( $forums_widget_file );
52
53 // If old docy-core and class doesn't exist yet, load it
54 if ( $is_old_docy && ! class_exists( 'DocyCore\WpWidgets\Forums' ) ) {
55 require_once $forums_widget_file;
56 }
57
58 // Unregister old docy-core Forums widget
59 // Priority 15: Standard priority for widget cleanup
60 add_action( 'widgets_init', 'forumax_unregister_old_docy_widgets', 15 );
61 }
62
63 /**
64 * Unregister old Docy Core widgets that are now handled by Forumax/bbPress
65 *
66 * Note: We only unregister docy-core Forums widget.
67 * bbPress widgets (BBP_Forums_Widget, BBP_Topics_Widget, BBP_Replies_Widget)
68 * are kept active as they are the primary widgets for forums functionality.
69 */
70 function forumax_unregister_old_docy_widgets() {
71 // Unregister old docy-core Forums widget if it was registered
72 if ( class_exists( 'DocyCore\WpWidgets\Forums' ) ) {
73 unregister_widget( 'DocyCore\WpWidgets\Forums' );
74 }
75
76 // Note: bbPress widgets are NOT unregistered
77 // They are the primary widgets for:
78 // - Forums List (BBP_Forums_Widget)
79 // - Recent Topics (BBP_Topics_Widget)
80 // - Recent Replies (BBP_Replies_Widget)
81 }
82
83 // Run compatibility handler
84 forumax_handle_docy_core_compatibility();
85