PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 8.0.5
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v8.0.5
8.0.5 8.0.4 8.0.3 8.0.1 8.0.2 8.0.0 7.9.9.7 7.9.9.6 7.9.9.5 7.9.9.4 7.9.9.3 7.9.9.2 7.9.9.1 7.9.9 7.9.8 7.9.7 7.9.6 7.9.5 7.9.4 7.9.3 7.9.2 7.9.1 7.9.0 7.8.9 7.8.8 All 47 releases
gamipress / integrations / buddyboss / buddyboss.php

buddyboss.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 8.0.5, at integrations/buddyboss/buddyboss.php

251 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: GamiPress - BuddyBoss integration
4 * Plugin URI: https://wordpress.org/plugins/gamipress-buddyboss-integration/
5 * Description: Connect GamiPress with BuddyBoss.
6 * Version: 1.3.6
7 * Author: GamiPress
8 * Author URI: https://gamipress.com/
9 * Text Domain: gamipress-buddyboss-integration
10 * Domain Path: /languages/
11 * Requires at least: 4.4
12 * Tested up to: 6.7
13 * License: GNU AGPL v3.0 (http://www.gnu.org/licenses/agpl.txt)
14 *
15 * @package GamiPress\BuddyBoss
16 * @author GamiPress
17 * @copyright Copyright (c) GamiPress
18 */
19
20 final class GamiPress_Integration_BuddyBoss {
21
22 /**
23 * @var GamiPress_Integration_BuddyBoss $instance The one true GamiPress_Integration_BuddyBoss
24 * @since 1.0.0
25 */
26 private static $instance;
27
28 /**
29 * Get active instance
30 *
31 * @access public
32 * @since 1.0.0
33 * @return GamiPress_Integration_BuddyBoss self::$instance The one true GamiPress_Integration_BuddyBoss
34 */
35 public static function instance() {
36 if( !self::$instance ) {
37 self::$instance = new GamiPress_Integration_BuddyBoss();
38 self::$instance->constants();
39 self::$instance->includes();
40 self::$instance->hooks();
41
42 }
43
44 return self::$instance;
45 }
46
47 /**
48 * Setup plugin constants
49 *
50 * @access private
51 * @since 1.0.0
52 * @return void
53 */
54 private function constants() {
55 // Plugin version
56 define( 'GAMIPRESS_BUDDYBOSS_VER', '1.3.6' );
57
58 // Plugin file
59 define( 'GAMIPRESS_BUDDYBOSS_FILE', __FILE__ );
60
61 // Plugin path
62 define( 'GAMIPRESS_BUDDYBOSS_DIR', plugin_dir_path( __FILE__ ) );
63
64 // Plugin URL
65 define( 'GAMIPRESS_BUDDYBOSS_URL', plugin_dir_url( __FILE__ ) );
66 }
67
68 /**
69 * Include plugin files
70 *
71 * @access private
72 * @since 1.0.0
73 * @return void
74 */
75 private function includes() {
76
77 if( $this->meets_requirements() ) {
78
79 require_once GAMIPRESS_BUDDYBOSS_DIR . 'includes/listeners.php';
80 require_once GAMIPRESS_BUDDYBOSS_DIR . 'includes/requirements.php';
81 require_once GAMIPRESS_BUDDYBOSS_DIR . 'includes/rules-engine.php';
82 require_once GAMIPRESS_BUDDYBOSS_DIR . 'includes/scripts.php';
83 require_once GAMIPRESS_BUDDYBOSS_DIR . 'includes/triggers.php';
84
85 if( ! class_exists( 'GamiPress_BuddyPress' ) ) {
86 require_once GAMIPRESS_BUDDYBOSS_DIR . 'includes/community/loader.php';
87 }
88
89 if( ! class_exists( 'GamiPress_bbPress' ) ) {
90 require_once GAMIPRESS_BUDDYBOSS_DIR . 'includes/forums/loader.php';
91 }
92
93 require_once GAMIPRESS_BUDDYBOSS_DIR . 'includes/membership/loader.php';
94
95 }
96
97 }
98
99 /**
100 * Setup plugin hooks
101 *
102 * @access private
103 * @since 1.0.0
104 * @return void
105 */
106 private function hooks() {
107
108 }
109
110
111 /**
112 * Activation hook for the plugin.
113 *
114 * @since 1.0.0
115 */
116 public static function activate() {
117
118 if ( ! class_exists( 'GamiPress' ) )
119 return;
120
121 GamiPress_Integration_BuddyBoss::instance();
122
123 global $wpdb;
124
125 // Get stored version
126 $stored_version = get_option( 'gamipress_buddyboss_integration_version', '1.0.0' );
127
128 if( function_exists('gamipress_is_network_wide_active') && gamipress_is_network_wide_active() ) {
129 $gamipress_settings = get_site_option( 'gamipress_settings', array() );
130 } else {
131 $gamipress_settings = get_option( 'gamipress_settings', array() );
132 }
133
134 // GamiPress BuddyPress 1.1.2 upgrade
135 if ( version_compare( $stored_version, '1.1.2', '<' ) ) {
136
137 // Points tab setting
138 $points_placement = ( isset( $gamipress_settings['bp_points_placement'] ) ? $gamipress_settings['bp_points_placement'] : '' );
139
140 if( in_array( $points_placement, array( 'tab', 'both' ) ) && ! isset( $gamipress_settings['bp_points_tab'] ) ) {
141 $gamipress_settings['bp_points_tab'] = 'on';
142 }
143
144 // Achievements tab setting
145 $achievements_placement = ( isset( $gamipress_settings['bp_achievements_placement'] ) ? $gamipress_settings['bp_achievements_placement'] : '' );
146
147 if( in_array( $achievements_placement, array( 'tab', 'both' ) ) && ! isset( $gamipress_settings['bp_achievements_tab'] ) ) {
148 $gamipress_settings['bp_achievements_tab'] = 'on';
149 }
150
151
152 // Ranks tab setting
153 $ranks_placement = ( isset( $gamipress_settings['bp_ranks_placement'] ) ? $gamipress_settings['bp_ranks_placement'] : '' );
154
155 if( in_array( $ranks_placement, array( 'tab', 'both' ) ) && ! isset( $gamipress_settings['bp_ranks_tab'] ) ) {
156 $gamipress_settings['bp_ranks_tab'] = 'on';
157 }
158
159 // Clone types and order settings
160 foreach( array( 'points', 'achievements', 'ranks' ) as $key ) {
161 if( ! isset( $gamipress_settings["bp_tab_{$key}_types"] ) ) {
162 $gamipress_settings["bp_tab_{$key}_types"] = $gamipress_settings["bp_members_{$key}_types"];
163 $gamipress_settings["bp_tab_{$key}_types_order"] = $gamipress_settings["bp_members_{$key}_types_order"];
164 }
165 }
166
167 // Finally, update placement to the new options
168 if( ! is_array( $gamipress_settings['bp_points_placement'] ) && in_array( $gamipress_settings['bp_points_placement'], array( 'top', 'both' ) ) ) {
169 $gamipress_settings['bp_points_placement'] = array( 'top' );
170 } else {
171 $gamipress_settings['bp_points_placement'] = array();
172 }
173
174 if( ! is_array( $gamipress_settings['bp_achievements_placement'] ) && in_array( $gamipress_settings['bp_achievements_placement'], array( 'top', 'both' ) ) ) {
175 $gamipress_settings['bp_achievements_placement'] = array( 'top' );
176 } else {
177 $gamipress_settings['bp_achievements_placement'] = array();
178 }
179
180 if( ! is_array( $gamipress_settings['bp_ranks_placement'] ) && in_array( $gamipress_settings['bp_ranks_placement'], array( 'top', 'both' ) ) ) {
181 $gamipress_settings['bp_ranks_placement'] = array( 'top' );
182 } else {
183 $gamipress_settings['bp_ranks_placement'] = array();
184 }
185
186 }
187
188 // Update GamiPress options
189 if( function_exists('gamipress_is_network_wide_active') && gamipress_is_network_wide_active() ) {
190 update_site_option( 'gamipress_settings', $gamipress_settings );
191 } else {
192 update_option( 'gamipress_settings', $gamipress_settings );
193 }
194
195 // Updated stored version
196 update_option( 'gamipress_buddyboss_integration_version', GAMIPRESS_BUDDYBOSS_VER );
197
198 }
199
200 /**
201 * Deactivation hook for the plugin.
202 *
203 * @since 1.0.0
204 */
205 public static function deactivate() {
206
207 }
208
209 /**
210 * Check if there are all plugin requirements
211 *
212 * @since 1.0.0
213 *
214 * @return bool True if installation meets all requirements
215 */
216 private function meets_requirements() {
217
218 if ( ! class_exists( 'GamiPress' ) )
219 return false;
220
221 // Requirements on multisite install
222 if( is_multisite() && is_main_site() && function_exists('gamipress_is_network_wide_active') && gamipress_is_network_wide_active() ) {
223 // On main site, need to check if integrated plugin is installed on any sub site to load all configuration files
224 if( gamipress_is_plugin_active_on_network( 'buddyboss-platform/bp-loader.php' ) )
225 return true;
226 }
227
228 if ( ! defined( 'BP_PLATFORM_VERSION' ) )
229 return false;
230
231 return true;
232
233 }
234
235 }
236
237 /**
238 * The main function responsible for returning the one true GamiPress_Integration_BuddyBoss instance to functions everywhere
239 *
240 * @since 1.0.0
241 * @return \GamiPress_Integration_BuddyBoss The one true GamiPress_Integration_BuddyBoss
242 */
243 function GamiPress_Integration_BuddyBoss() {
244 return GamiPress_Integration_BuddyBoss::instance();
245 }
246 add_action( 'gamipress_pre_init', 'GamiPress_Integration_BuddyBoss' );
247
248 // Setup our activation and deactivation hooks
249 register_activation_hook( __FILE__, array( 'GamiPress_Integration_BuddyBoss', 'activate' ) );
250 register_deactivation_hook( __FILE__, array( 'GamiPress_Integration_BuddyBoss', 'deactivate' ) );
251