| 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 |
} |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Setup plugin hooks |
| 99 |
* |
| 100 |
* @access private |
| 101 |
* @since 1.0.0 |
| 102 |
* @return void |
| 103 |
*/ |
| 104 |
private function hooks() { |
| 105 |
|
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
/** |
| 110 |
* Activation hook for the plugin. |
| 111 |
* |
| 112 |
* @since 1.0.0 |
| 113 |
*/ |
| 114 |
public static function activate() { |
| 115 |
|
| 116 |
if ( ! class_exists( 'GamiPress' ) ) |
| 117 |
return; |
| 118 |
|
| 119 |
GamiPress_Integration_BuddyBoss::instance(); |
| 120 |
|
| 121 |
global $wpdb; |
| 122 |
|
| 123 |
// Get stored version |
| 124 |
$stored_version = get_option( 'gamipress_buddyboss_integration_version', '1.0.0' ); |
| 125 |
|
| 126 |
if( function_exists('gamipress_is_network_wide_active') && gamipress_is_network_wide_active() ) { |
| 127 |
$gamipress_settings = get_site_option( 'gamipress_settings', array() ); |
| 128 |
} else { |
| 129 |
$gamipress_settings = get_option( 'gamipress_settings', array() ); |
| 130 |
} |
| 131 |
|
| 132 |
// GamiPress BuddyPress 1.1.2 upgrade |
| 133 |
if ( version_compare( $stored_version, '1.1.2', '<' ) ) { |
| 134 |
|
| 135 |
// Points tab setting |
| 136 |
$points_placement = ( isset( $gamipress_settings['bp_points_placement'] ) ? $gamipress_settings['bp_points_placement'] : '' ); |
| 137 |
|
| 138 |
if( in_array( $points_placement, array( 'tab', 'both' ) ) && ! isset( $gamipress_settings['bp_points_tab'] ) ) { |
| 139 |
$gamipress_settings['bp_points_tab'] = 'on'; |
| 140 |
} |
| 141 |
|
| 142 |
// Achievements tab setting |
| 143 |
$achievements_placement = ( isset( $gamipress_settings['bp_achievements_placement'] ) ? $gamipress_settings['bp_achievements_placement'] : '' ); |
| 144 |
|
| 145 |
if( in_array( $achievements_placement, array( 'tab', 'both' ) ) && ! isset( $gamipress_settings['bp_achievements_tab'] ) ) { |
| 146 |
$gamipress_settings['bp_achievements_tab'] = 'on'; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
// Ranks tab setting |
| 151 |
$ranks_placement = ( isset( $gamipress_settings['bp_ranks_placement'] ) ? $gamipress_settings['bp_ranks_placement'] : '' ); |
| 152 |
|
| 153 |
if( in_array( $ranks_placement, array( 'tab', 'both' ) ) && ! isset( $gamipress_settings['bp_ranks_tab'] ) ) { |
| 154 |
$gamipress_settings['bp_ranks_tab'] = 'on'; |
| 155 |
} |
| 156 |
|
| 157 |
// Clone types and order settings |
| 158 |
foreach( array( 'points', 'achievements', 'ranks' ) as $key ) { |
| 159 |
if( ! isset( $gamipress_settings["bp_tab_{$key}_types"] ) ) { |
| 160 |
$gamipress_settings["bp_tab_{$key}_types"] = $gamipress_settings["bp_members_{$key}_types"]; |
| 161 |
$gamipress_settings["bp_tab_{$key}_types_order"] = $gamipress_settings["bp_members_{$key}_types_order"]; |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
// Finally, update placement to the new options |
| 166 |
if( ! is_array( $gamipress_settings['bp_points_placement'] ) && in_array( $gamipress_settings['bp_points_placement'], array( 'top', 'both' ) ) ) { |
| 167 |
$gamipress_settings['bp_points_placement'] = array( 'top' ); |
| 168 |
} else { |
| 169 |
$gamipress_settings['bp_points_placement'] = array(); |
| 170 |
} |
| 171 |
|
| 172 |
if( ! is_array( $gamipress_settings['bp_achievements_placement'] ) && in_array( $gamipress_settings['bp_achievements_placement'], array( 'top', 'both' ) ) ) { |
| 173 |
$gamipress_settings['bp_achievements_placement'] = array( 'top' ); |
| 174 |
} else { |
| 175 |
$gamipress_settings['bp_achievements_placement'] = array(); |
| 176 |
} |
| 177 |
|
| 178 |
if( ! is_array( $gamipress_settings['bp_ranks_placement'] ) && in_array( $gamipress_settings['bp_ranks_placement'], array( 'top', 'both' ) ) ) { |
| 179 |
$gamipress_settings['bp_ranks_placement'] = array( 'top' ); |
| 180 |
} else { |
| 181 |
$gamipress_settings['bp_ranks_placement'] = array(); |
| 182 |
} |
| 183 |
|
| 184 |
} |
| 185 |
|
| 186 |
// Update GamiPress options |
| 187 |
if( function_exists('gamipress_is_network_wide_active') && gamipress_is_network_wide_active() ) { |
| 188 |
update_site_option( 'gamipress_settings', $gamipress_settings ); |
| 189 |
} else { |
| 190 |
update_option( 'gamipress_settings', $gamipress_settings ); |
| 191 |
} |
| 192 |
|
| 193 |
// Updated stored version |
| 194 |
update_option( 'gamipress_buddyboss_integration_version', GAMIPRESS_BUDDYBOSS_VER ); |
| 195 |
|
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* Deactivation hook for the plugin. |
| 200 |
* |
| 201 |
* @since 1.0.0 |
| 202 |
*/ |
| 203 |
public static function deactivate() { |
| 204 |
|
| 205 |
} |
| 206 |
|
| 207 |
/** |
| 208 |
* Check if there are all plugin requirements |
| 209 |
* |
| 210 |
* @since 1.0.0 |
| 211 |
* |
| 212 |
* @return bool True if installation meets all requirements |
| 213 |
*/ |
| 214 |
private function meets_requirements() { |
| 215 |
|
| 216 |
if ( ! class_exists( 'GamiPress' ) ) |
| 217 |
return false; |
| 218 |
|
| 219 |
// Requirements on multisite install |
| 220 |
if( is_multisite() && is_main_site() && function_exists('gamipress_is_network_wide_active') && gamipress_is_network_wide_active() ) { |
| 221 |
// On main site, need to check if integrated plugin is installed on any sub site to load all configuration files |
| 222 |
if( gamipress_is_plugin_active_on_network( 'buddyboss-platform/bp-loader.php' ) ) |
| 223 |
return true; |
| 224 |
} |
| 225 |
|
| 226 |
if ( ! defined( 'BP_PLATFORM_VERSION' ) ) |
| 227 |
return false; |
| 228 |
|
| 229 |
return true; |
| 230 |
|
| 231 |
} |
| 232 |
|
| 233 |
} |
| 234 |
|
| 235 |
/** |
| 236 |
* The main function responsible for returning the one true GamiPress_Integration_BuddyBoss instance to functions everywhere |
| 237 |
* |
| 238 |
* @since 1.0.0 |
| 239 |
* @return \GamiPress_Integration_BuddyBoss The one true GamiPress_Integration_BuddyBoss |
| 240 |
*/ |
| 241 |
function GamiPress_Integration_BuddyBoss() { |
| 242 |
return GamiPress_Integration_BuddyBoss::instance(); |
| 243 |
} |
| 244 |
add_action( 'gamipress_pre_init', 'GamiPress_Integration_BuddyBoss' ); |
| 245 |
|
| 246 |
// Setup our activation and deactivation hooks |
| 247 |
register_activation_hook( __FILE__, array( 'GamiPress_Integration_BuddyBoss', 'activate' ) ); |
| 248 |
register_deactivation_hook( __FILE__, array( 'GamiPress_Integration_BuddyBoss', 'deactivate' ) ); |
| 249 |
|