| @@ -1,0 +1,527 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Plugin Name: GamiPress | |
| 4 | + * Plugin URI: https://gamipress.com | |
| 5 | + * Description: The most flexible and powerful gamification system for WordPress. | |
| 6 | + * Version: 8.0.5 | |
| 7 | + * Author: GamiPress | |
| 8 | + * Author URI: https://gamipress.com/ | |
| 9 | + * Text Domain: gamipress | |
| 10 | + * Domain Path: /languages/ | |
| 11 | + * Requires PHP: 7.0 | |
| 12 | + * Requires at least: 4.4 | |
| 13 | + * Tested up to: 7.1 | |
| 14 | + * License: GPLv3 | |
| 15 | + * | |
| 16 | + * @package GamiPress | |
| 17 | + * @author GamiPress <[email protected]>, Ruben Garcia <[email protected]> | |
| 18 | + * @copyright Copyright (c) GamiPress | |
| 19 | +*/ | |
| 20 | + | |
| 21 | +final class GamiPress { | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * @var GamiPress $instance The one true GamiPress | |
| 25 | + * @since 1.0.0 | |
| 26 | + */ | |
| 27 | + private static $instance; | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * @var array $settings GamiPress stored settings | |
| 31 | + * @since 1.0.2 | |
| 32 | + */ | |
| 33 | + public $settings = null; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * @var array $points_types GamiPress registered points types | |
| 37 | + * @since 1.0.0 | |
| 38 | + */ | |
| 39 | + public $points_types = array(); | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * @var array $achievement_types GamiPress registered achievement types | |
| 43 | + * @since 1.0.0 | |
| 44 | + */ | |
| 45 | + public $achievement_types = array(); | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * @var array $achievement_types GamiPress registered rank types | |
| 49 | + * @since 1.3.1 | |
| 50 | + */ | |
| 51 | + public $rank_types = array(); | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * @var array $requirement_types GamiPress registered requirement types | |
| 55 | + * @since 1.0.5 | |
| 56 | + */ | |
| 57 | + public $requirement_types = array(); | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * @var array $activity_triggers GamiPress registered activity triggers | |
| 61 | + * @since 1.0.0 | |
| 62 | + */ | |
| 63 | + public $activity_triggers = array(); | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * @var array $shortcodes GamiPress registered shortcodes | |
| 67 | + * @since 1.0.0 | |
| 68 | + */ | |
| 69 | + public $shortcodes = array(); | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * @var GamiPress_Database $db GamiPress database object | |
| 73 | + * @since 1.4.0 | |
| 74 | + */ | |
| 75 | + public $db; | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * @var bool $db GamiPress network wide active mark | |
| 79 | + * @since 1.4.0 | |
| 80 | + */ | |
| 81 | + public $network_wide_active = null; | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * @var array $cache GamiPress cache class | |
| 85 | + * @since 1.4.0 | |
| 86 | + */ | |
| 87 | + public $cache = array(); | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * Get active instance | |
| 91 | + * | |
| 92 | + * @access public | |
| 93 | + * @since 1.0.0 | |
| 94 | + * @return GamiPress self::$instance The one true GamiPress | |
| 95 | + */ | |
| 96 | + public static function instance() { | |
| 97 | + | |
| 98 | + if( ! self::$instance ) { | |
| 99 | + | |
| 100 | + self::$instance = new GamiPress(); | |
| 101 | + self::$instance->constants(); | |
| 102 | + self::$instance->libraries(); | |
| 103 | + self::$instance->classes(); | |
| 104 | + self::$instance->compatibility(); | |
| 105 | + self::$instance->includes(); | |
| 106 | + self::$instance->modules(); | |
| 107 | + self::$instance->hooks(); | |
| 108 | + | |
| 109 | + } | |
| 110 | + | |
| 111 | + return self::$instance; | |
| 112 | + | |
| 113 | + } | |
| 114 | + | |
| 115 | + /** | |
| 116 | + * Setup plugin constants | |
| 117 | + * | |
| 118 | + * @access private | |
| 119 | + * @since 1.0.0 | |
| 120 | + * @return void | |
| 121 | + */ | |
| 122 | + private function constants() { | |
| 123 | + | |
| 124 | + // Plugin version | |
| 125 | + define( 'GAMIPRESS_VER', '8.0.5' ); | |
| 126 | + | |
| 127 | + // Plugin file | |
| 128 | + define( 'GAMIPRESS_FILE', __FILE__ ); | |
| 129 | + | |
| 130 | + // Plugin path | |
| 131 | + define( 'GAMIPRESS_DIR', plugin_dir_path( __FILE__ ) ); | |
| 132 | + | |
| 133 | + // Plugin URL | |
| 134 | + define( 'GAMIPRESS_URL', plugin_dir_url( __FILE__ ) ); | |
| 135 | + | |
| 136 | + // Credentials vars | |
| 137 | + define( 'GAMIPRESS_CRED_VAR', 'c' ); | |
| 138 | + define( 'GAMIPRESS_CRED_KEY', '1991092202300020110720144557' ); | |
| 139 | + define( 'GAMIPRESS_CRED_SALT', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' ); | |
| 140 | + | |
| 141 | + } | |
| 142 | + | |
| 143 | + /** | |
| 144 | + * Include plugin libraries | |
| 145 | + * | |
| 146 | + * @access private | |
| 147 | + * @since 1.0.0 | |
| 148 | + * @return void | |
| 149 | + */ | |
| 150 | + private function libraries() { | |
| 151 | + | |
| 152 | + // Custom Tables | |
| 153 | + require_once GAMIPRESS_DIR . 'libraries/ct/init.php'; | |
| 154 | + require_once GAMIPRESS_DIR . 'libraries/ct-ajax-list-table/ct-ajax-list-table.php'; | |
| 155 | + | |
| 156 | + // CMB2 | |
| 157 | + require_once GAMIPRESS_DIR . 'libraries/cmb2/init.php'; | |
| 158 | + require_once GAMIPRESS_DIR . 'libraries/cmb2-metatabs-options/cmb2_metatabs_options.php'; | |
| 159 | + require_once GAMIPRESS_DIR . 'libraries/cmb2-tabs/cmb2-tabs.php'; | |
| 160 | + require_once GAMIPRESS_DIR . 'libraries/cmb2-field-tooltip/cmb2-field-tooltip.php'; | |
| 161 | + require_once GAMIPRESS_DIR . 'libraries/cmb2-field-edd-license/cmb2-field-edd-license.php'; | |
| 162 | + require_once GAMIPRESS_DIR . 'libraries/cmb2-conditional-fields/cmb2-conditional-fields.php'; | |
| 163 | + | |
| 164 | + // GamiPress CMB2 fields | |
| 165 | + require_once GAMIPRESS_DIR . 'libraries/advanced-select-field-type.php'; | |
| 166 | + require_once GAMIPRESS_DIR . 'libraries/size-field-type.php'; | |
| 167 | + require_once GAMIPRESS_DIR . 'libraries/display-field-type.php'; | |
| 168 | + require_once GAMIPRESS_DIR . 'libraries/button-field-type.php'; | |
| 169 | + require_once GAMIPRESS_DIR . 'libraries/html-field-type.php'; | |
| 170 | + require_once GAMIPRESS_DIR . 'libraries/points-field-type.php'; | |
| 171 | + | |
| 172 | + } | |
| 173 | + | |
| 174 | + /** | |
| 175 | + * Include plugin classes | |
| 176 | + * | |
| 177 | + * @access private | |
| 178 | + * @since 1.0.0 | |
| 179 | + * @return void | |
| 180 | + */ | |
| 181 | + private function classes() { | |
| 182 | + | |
| 183 | + require_once GAMIPRESS_DIR . 'classes/database.php'; | |
| 184 | + require_once GAMIPRESS_DIR . 'classes/badge-builder-icons.php'; | |
| 185 | + | |
| 186 | + } | |
| 187 | + | |
| 188 | + /** | |
| 189 | + * Include compatibility files | |
| 190 | + * | |
| 191 | + * @access private | |
| 192 | + * @since 1.2.8 | |
| 193 | + * @return void | |
| 194 | + */ | |
| 195 | + private function compatibility() { | |
| 196 | + | |
| 197 | + // WordPress backward compatibility | |
| 198 | + require_once GAMIPRESS_DIR . 'includes/compatibility/wordpress.php'; | |
| 199 | + | |
| 200 | + } | |
| 201 | + | |
| 202 | + /** | |
| 203 | + * Include plugin files | |
| 204 | + * | |
| 205 | + * @access private | |
| 206 | + * @since 1.0.0 | |
| 207 | + * @return void | |
| 208 | + */ | |
| 209 | + private function includes() { | |
| 210 | + | |
| 211 | + require_once GAMIPRESS_DIR . 'includes/admin.php'; | |
| 212 | + require_once GAMIPRESS_DIR . 'includes/custom-tables.php'; | |
| 213 | + require_once GAMIPRESS_DIR . 'includes/post-types.php'; | |
| 214 | + require_once GAMIPRESS_DIR . 'includes/privacy.php'; | |
| 215 | + require_once GAMIPRESS_DIR . 'includes/emails.php'; | |
| 216 | + require_once GAMIPRESS_DIR . 'includes/credentials.php'; | |
| 217 | + require_once GAMIPRESS_DIR . 'includes/activity-functions.php'; | |
| 218 | + require_once GAMIPRESS_DIR . 'includes/ajax-functions.php'; | |
| 219 | + require_once GAMIPRESS_DIR . 'includes/api.php'; | |
| 220 | + require_once GAMIPRESS_DIR . 'includes/blocks.php'; | |
| 221 | + require_once GAMIPRESS_DIR . 'includes/cache.php'; | |
| 222 | + require_once GAMIPRESS_DIR . 'includes/functions.php'; | |
| 223 | + require_once GAMIPRESS_DIR . 'includes/listeners.php'; | |
| 224 | + require_once GAMIPRESS_DIR . 'includes/network.php'; | |
| 225 | + require_once GAMIPRESS_DIR . 'includes/scripts.php'; | |
| 226 | + require_once GAMIPRESS_DIR . 'includes/shortcodes.php'; | |
| 227 | + require_once GAMIPRESS_DIR . 'includes/filters.php'; | |
| 228 | + require_once GAMIPRESS_DIR . 'includes/rules-engine.php'; | |
| 229 | + require_once GAMIPRESS_DIR . 'includes/tags.php'; | |
| 230 | + require_once GAMIPRESS_DIR . 'includes/template-functions.php'; | |
| 231 | + require_once GAMIPRESS_DIR . 'includes/triggers.php'; | |
| 232 | + require_once GAMIPRESS_DIR . 'includes/users.php'; | |
| 233 | + require_once GAMIPRESS_DIR . 'includes/widgets.php'; | |
| 234 | + | |
| 235 | + } | |
| 236 | + | |
| 237 | + /** | |
| 238 | + * Include modules files | |
| 239 | + * | |
| 240 | + * @access private | |
| 241 | + * @since 1.0.0 | |
| 242 | + * @return void | |
| 243 | + */ | |
| 244 | + private function modules() { | |
| 245 | + | |
| 246 | + require_once GAMIPRESS_DIR . 'modules/ai-assistant/gamipress-ai-assistant.php'; | |
| 247 | + | |
| 248 | + } | |
| 249 | + | |
| 250 | + /** | |
| 251 | + * Include integrations files | |
| 252 | + * | |
| 253 | + * @access private | |
| 254 | + * @since 1.0.0 | |
| 255 | + * @return void | |
| 256 | + */ | |
| 257 | + private function integrations() { | |
| 258 | + | |
| 259 | + $integrations_dir = GAMIPRESS_DIR . 'integrations'; | |
| 260 | + | |
| 261 | + // Setup active plugins | |
| 262 | + $active_plugins = array(); | |
| 263 | + | |
| 264 | + if( function_exists( 'get_option' ) ) { | |
| 265 | + $active_plugins = (array) get_option( 'active_plugins', array() ); | |
| 266 | + } | |
| 267 | + | |
| 268 | + // Setup active sitewide plugins | |
| 269 | + $active_sitewide_plugins = array(); | |
| 270 | + | |
| 271 | + if ( is_multisite() && function_exists( 'get_site_option' ) ) { | |
| 272 | + $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' ); | |
| 273 | + | |
| 274 | + if( ! is_array( $active_sitewide_plugins ) ) { | |
| 275 | + $active_sitewide_plugins = array(); | |
| 276 | + } | |
| 277 | + } | |
| 278 | + | |
| 279 | + $integrations = @opendir( $integrations_dir ); | |
| 280 | + | |
| 281 | + while ( ( $integration = @readdir( $integrations ) ) !== false ) { | |
| 282 | + | |
| 283 | + if ( $integration === '.' || $integration === '..' || $integration === 'index.php' ) { | |
| 284 | + continue; | |
| 285 | + } | |
| 286 | + | |
| 287 | + /** | |
| 288 | + * Filter to allow third party plugins skip any integration | |
| 289 | + * | |
| 290 | + * @since 1.0.0 | |
| 291 | + * | |
| 292 | + * @param bool $skip | |
| 293 | + * @param string $integration The integration slug as named in gamipress/includes/integrations | |
| 294 | + * @param array $active_plugins | |
| 295 | + * @param array $active_sitewide_plugins | |
| 296 | + * | |
| 297 | + * @return bool | |
| 298 | + */ | |
| 299 | + if( apply_filters( 'gamipress_skip_integration', false, $integration, $active_plugins, $active_sitewide_plugins ) ) { | |
| 300 | + continue; | |
| 301 | + } | |
| 302 | + | |
| 303 | + // Skip if integration is already active | |
| 304 | + if( $this->is_integration_active( $integration, $active_plugins, $active_sitewide_plugins ) ) { | |
| 305 | + continue; | |
| 306 | + } | |
| 307 | + | |
| 308 | + $integration_file = $integrations_dir . DIRECTORY_SEPARATOR . $integration . DIRECTORY_SEPARATOR . $integration . '.php'; | |
| 309 | + | |
| 310 | + // Skip if no file to load | |
| 311 | + if( ! file_exists( $integration_file ) ) { | |
| 312 | + continue; | |
| 313 | + } | |
| 314 | + | |
| 315 | + require_once $integration_file; | |
| 316 | + | |
| 317 | + } | |
| 318 | + | |
| 319 | + closedir( $integrations ); | |
| 320 | + | |
| 321 | + } | |
| 322 | + | |
| 323 | + /** | |
| 324 | + * Include integrations files | |
| 325 | + * | |
| 326 | + * @access private | |
| 327 | + * @since 1.0.0 | |
| 328 | + * @param string $integration | |
| 329 | + * @param array $active_plugins | |
| 330 | + * @param array $active_sitewide_plugins | |
| 331 | + * @return bool | |
| 332 | + */ | |
| 333 | + private function is_integration_active( $integration, $active_plugins, $active_sitewide_plugins ) { | |
| 334 | + | |
| 335 | + $plugins = array( | |
| 336 | + "gamipress-{$integration}-integration/gamipress-{$integration}.php", | |
| 337 | + "gamipress-{$integration}-integration/gamipress-{$integration}-integration.php", | |
| 338 | + ); | |
| 339 | + | |
| 340 | + if( $integration === 'elementor' ) { | |
| 341 | + $plugins = array( | |
| 342 | + "gamipress-{$integration}-forms-integration/gamipress-{$integration}-forms.php", | |
| 343 | + ); | |
| 344 | + } | |
| 345 | + | |
| 346 | + foreach( $plugins as $plugin ) { | |
| 347 | + | |
| 348 | + // Bail if plugin is active | |
| 349 | + if( in_array( $plugin, $active_plugins, true ) ) { | |
| 350 | + return true; | |
| 351 | + } | |
| 352 | + | |
| 353 | + // Bail if plugin is network wide active | |
| 354 | + if ( isset( $active_sitewide_plugins[$plugin] ) ) { | |
| 355 | + return true; | |
| 356 | + } | |
| 357 | + | |
| 358 | + // Consider integration active during it's activation | |
| 359 | + if( isset( $_REQUEST['action'] ) && $_REQUEST['action'] === 'activate' | |
| 360 | + && isset( $_REQUEST['plugin'] ) && $_REQUEST['plugin'] === $plugin ) { | |
| 361 | + return true; | |
| 362 | + } | |
| 363 | + | |
| 364 | + // Support for bulk activate | |
| 365 | + if( isset( $_REQUEST['action'] ) && $_REQUEST['action'] === 'activate-selected' | |
| 366 | + && isset( $_REQUEST['checked'] ) && is_array( $_REQUEST['checked'] ) | |
| 367 | + && in_array( $plugin, $_REQUEST['checked'] ) ) { | |
| 368 | + return true; | |
| 369 | + } | |
| 370 | + | |
| 371 | + } | |
| 372 | + | |
| 373 | + return false; | |
| 374 | + | |
| 375 | + } | |
| 376 | + | |
| 377 | + /** | |
| 378 | + * Setup plugin hooks | |
| 379 | + * | |
| 380 | + * @access private | |
| 381 | + * @since 1.0.0 | |
| 382 | + * @return void | |
| 383 | + */ | |
| 384 | + private function hooks() { | |
| 385 | + | |
| 386 | + // Setup our activation and deactivation hooks | |
| 387 | + register_activation_hook( __FILE__, array( $this, 'activate' ) ); | |
| 388 | + register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); | |
| 389 | + | |
| 390 | + // Hook in all our important pieces | |
| 391 | + add_action( 'plugins_loaded', array( $this, 'pre_init' ), 20 ); | |
| 392 | + add_action( 'plugins_loaded', array( $this, 'init' ), 50 ); | |
| 393 | + add_action( 'plugins_loaded', array( $this, 'post_init' ), 999 ); | |
| 394 | + add_action( 'init', array( $this, 'load_textdomain' ), 10 ); | |
| 395 | + | |
| 396 | + } | |
| 397 | + | |
| 398 | + /** | |
| 399 | + * Pre init function | |
| 400 | + * | |
| 401 | + * @access private | |
| 402 | + * @since 1.4.6 | |
| 403 | + * @return void | |
| 404 | + */ | |
| 405 | + function pre_init() { | |
| 406 | + | |
| 407 | + // Load all integrations | |
| 408 | + $this->integrations(); | |
| 409 | + | |
| 410 | + global $wpdb; | |
| 411 | + | |
| 412 | + $this->db = new GamiPress_Database(); | |
| 413 | + | |
| 414 | + // Setup WordPress database tables | |
| 415 | + $this->db->posts = $wpdb->posts; | |
| 416 | + $this->db->postmeta = $wpdb->postmeta; | |
| 417 | + $this->db->users = $wpdb->users; | |
| 418 | + $this->db->usermeta = $wpdb->usermeta; | |
| 419 | + | |
| 420 | + // Setup GamiPress database tables | |
| 421 | + $this->db->logs = $wpdb->gamipress_logs; | |
| 422 | + $this->db->logs_meta = $wpdb->gamipress_logs_meta; | |
| 423 | + $this->db->user_earnings = $wpdb->gamipress_user_earnings; | |
| 424 | + $this->db->user_earnings_meta = $wpdb->gamipress_user_earnings_meta; | |
| 425 | + | |
| 426 | + // Trigger our action to let other plugins know that GamiPress is getting initialized | |
| 427 | + do_action( 'gamipress_pre_init' ); | |
| 428 | + | |
| 429 | + } | |
| 430 | + | |
| 431 | + /** | |
| 432 | + * Init function | |
| 433 | + * | |
| 434 | + * @access private | |
| 435 | + * @since 1.4.0 | |
| 436 | + * @return void | |
| 437 | + */ | |
| 438 | + function init() { | |
| 439 | + | |
| 440 | + // Trigger our action to let other plugins know that GamiPress is ready | |
| 441 | + do_action( 'gamipress_init' ); | |
| 442 | + | |
| 443 | + } | |
| 444 | + | |
| 445 | + /** | |
| 446 | + * Post init function | |
| 447 | + * | |
| 448 | + * @access private | |
| 449 | + * @since 1.0.0 | |
| 450 | + * @return void | |
| 451 | + */ | |
| 452 | + function post_init() { | |
| 453 | + | |
| 454 | + // Trigger our action to let other plugins know that GamiPress has been initialized | |
| 455 | + do_action( 'gamipress_post_init' ); | |
| 456 | + | |
| 457 | + } | |
| 458 | + | |
| 459 | + /** | |
| 460 | + * Activation hook for the plugin. | |
| 461 | + */ | |
| 462 | + function activate() { | |
| 463 | + | |
| 464 | + // Include our important bits | |
| 465 | + $this->libraries(); | |
| 466 | + $this->includes(); | |
| 467 | + | |
| 468 | + require_once GAMIPRESS_DIR . 'includes/install.php'; | |
| 469 | + | |
| 470 | + gamipress_install(); | |
| 471 | + | |
| 472 | + } | |
| 473 | + | |
| 474 | + /** | |
| 475 | + * Deactivation hook for the plugin. | |
| 476 | + */ | |
| 477 | + function deactivate() { | |
| 478 | + flush_rewrite_rules(); | |
| 479 | + } | |
| 480 | + | |
| 481 | + /** | |
| 482 | + * Internationalization | |
| 483 | + * | |
| 484 | + * @access public | |
| 485 | + * @since 1.0.0 | |
| 486 | + * @return void | |
| 487 | + */ | |
| 488 | + public function load_textdomain() { | |
| 489 | + | |
| 490 | + // Set filter for language directory | |
| 491 | + $lang_dir = GAMIPRESS_DIR . '/languages/'; | |
| 492 | + $lang_dir = apply_filters( 'gamipress_languages_directory', $lang_dir ); | |
| 493 | + | |
| 494 | + // Traditional WordPress plugin locale filter | |
| 495 | + $locale = apply_filters( 'plugin_locale', get_locale(), 'gamipress' ); | |
| 496 | + $mofile = sprintf( '%1$s-%2$s.mo', 'gamipress', $locale ); | |
| 497 | + | |
| 498 | + // Setup paths to current locale file | |
| 499 | + $mofile_local = $lang_dir . $mofile; | |
| 500 | + $mofile_global = WP_LANG_DIR . '/gamipress/' . $mofile; | |
| 501 | + | |
| 502 | + if( file_exists( $mofile_global ) ) { | |
| 503 | + // Look in global /wp-content/languages/gamipress/ folder | |
| 504 | + load_textdomain( 'gamipress', $mofile_global ); | |
| 505 | + } elseif( file_exists( $mofile_local ) ) { | |
| 506 | + // Look in local /wp-content/plugins/gamipress/languages/ folder | |
| 507 | + load_textdomain( 'gamipress', $mofile_local ); | |
| 508 | + } else { | |
| 509 | + // Load the default language files | |
| 510 | + load_plugin_textdomain( 'gamipress', false, $lang_dir ); | |
| 511 | + } | |
| 512 | + | |
| 513 | + } | |
| 514 | + | |
| 515 | +} | |
| 516 | + | |
| 517 | +/** | |
| 518 | + * The main function responsible for returning the one true GamiPress instance to functions everywhere | |
| 519 | + * | |
| 520 | + * @since 1.0.0 | |
| 521 | + * @return \GamiPress The one true GamiPress | |
| 522 | + */ | |
| 523 | +function GamiPress() { | |
| 524 | + return GamiPress::instance(); | |
| 525 | +} | |
| 526 | + | |
| 527 | +GamiPress(); | |