| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: SportsPress |
| 4 |
* Plugin URI: http://themeboy.com/sportspress/ |
| 5 |
* Description: Manage your club and its players, staff, events, league tables, and player lists. |
| 6 |
* Version: 2.7.31 |
| 7 |
* Author: ThemeBoy |
| 8 |
* Author URI: http://themeboy.com |
| 9 |
* Requires at least: 3.8 |
| 10 |
* Tested up to: 7.0 |
| 11 |
* |
| 12 |
* Text Domain: sportspress |
| 13 |
* Domain Path: /languages/ |
| 14 |
* |
| 15 |
* @package SportsPress |
| 16 |
* @category Core |
| 17 |
* @author ThemeBoy |
| 18 |
*/ |
| 19 |
if ( ! defined( 'ABSPATH' ) ) { |
| 20 |
exit; // Exit if accessed directly |
| 21 |
} |
| 22 |
|
| 23 |
if ( ! class_exists( 'SportsPress' ) ) : |
| 24 |
|
| 25 |
/** |
| 26 |
* Main SportsPress Class |
| 27 |
* |
| 28 |
* @class SportsPress |
| 29 |
* @version 2.7.31 |
| 30 |
*/ |
| 31 |
final class SportsPress { |
| 32 |
|
| 33 |
/** |
| 34 |
* @var string |
| 35 |
*/ |
| 36 |
public $version = '2.7.31'; |
| 37 |
|
| 38 |
/** |
| 39 |
* @var SportsPress The single instance of the class |
| 40 |
* @since 0.7 |
| 41 |
*/ |
| 42 |
protected static $_instance = null; |
| 43 |
|
| 44 |
/** |
| 45 |
* @var SP_Modules $modules |
| 46 |
*/ |
| 47 |
public $modules = null; |
| 48 |
|
| 49 |
/** |
| 50 |
* @var SP_Countries $countries |
| 51 |
*/ |
| 52 |
public $countries = null; |
| 53 |
|
| 54 |
/** |
| 55 |
* @var SP_Formats $formats |
| 56 |
*/ |
| 57 |
public $formats = null; |
| 58 |
|
| 59 |
/** |
| 60 |
* @var SP_Templates $templates |
| 61 |
*/ |
| 62 |
public $templates = null; |
| 63 |
|
| 64 |
/** |
| 65 |
* @var SP_Feeds $feeds |
| 66 |
*/ |
| 67 |
public $feeds = null; |
| 68 |
|
| 69 |
/** |
| 70 |
* @var array |
| 71 |
*/ |
| 72 |
public $text = array(); |
| 73 |
|
| 74 |
/** |
| 75 |
* Main SportsPress Instance |
| 76 |
* |
| 77 |
* Ensures only one instance of SportsPress is loaded or can be loaded. |
| 78 |
* |
| 79 |
* @since 0.7 |
| 80 |
* @static |
| 81 |
* @see SP() |
| 82 |
* @return SportsPress - Main instance |
| 83 |
*/ |
| 84 |
public static function instance() { |
| 85 |
if ( is_null( self::$_instance ) ) { |
| 86 |
self::$_instance = new self(); |
| 87 |
} |
| 88 |
return self::$_instance; |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Cloning is forbidden. |
| 93 |
* |
| 94 |
* @since 0.7 |
| 95 |
*/ |
| 96 |
public function __clone() { |
| 97 |
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'sportspress' ), '0.7' ); |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Unserializing instances of this class is forbidden. |
| 102 |
* |
| 103 |
* @since 0.7 |
| 104 |
*/ |
| 105 |
public function __wakeup() { |
| 106 |
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'sportspress' ), '0.7' ); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* SportsPress Constructor. |
| 111 |
* |
| 112 |
* @access public |
| 113 |
* @return SportsPress |
| 114 |
*/ |
| 115 |
public function __construct() { |
| 116 |
// Auto-load classes on demand |
| 117 |
if ( function_exists( '__autoload' ) ) { |
| 118 |
spl_autoload_register( '__autoload' ); |
| 119 |
} |
| 120 |
|
| 121 |
spl_autoload_register( array( $this, 'autoload' ) ); |
| 122 |
|
| 123 |
// Define constants |
| 124 |
$this->define_constants(); |
| 125 |
|
| 126 |
// Include required files |
| 127 |
$this->includes(); |
| 128 |
|
| 129 |
// Hooks |
| 130 |
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'action_links' ) ); |
| 131 |
add_action( 'init', array( $this, 'init' ), 0 ); |
| 132 |
add_action( 'init', array( 'SP_Shortcodes', 'init' ) ); |
| 133 |
add_action( 'after_setup_theme', array( $this, 'setup_environment' ) ); |
| 134 |
add_action( 'tgmpa_register', array( $this, 'extension' ) ); |
| 135 |
|
| 136 |
// Include core modules |
| 137 |
$this->include_modules(); |
| 138 |
|
| 139 |
// Loaded action |
| 140 |
do_action( 'sportspress_loaded' ); |
| 141 |
} |
| 142 |
|
| 143 |
/** |
| 144 |
* Show action links on the plugin screen. |
| 145 |
* |
| 146 |
* @param mixed $links |
| 147 |
* @return array |
| 148 |
*/ |
| 149 |
public function action_links( $links ) { |
| 150 |
return array_merge( |
| 151 |
array( |
| 152 |
'<a href="' . admin_url( 'admin.php?page=sportspress' ) . '">' . esc_attr__( 'Settings', 'sportspress' ) . '</a>', |
| 153 |
'<a href="' . apply_filters( 'sportspress_docs_url', 'http://tboy.co/docs' ) . '">' . esc_attr__( 'Docs', 'sportspress' ) . '</a>', |
| 154 |
'<a href="' . apply_filters( 'sportspress_pro_url', 'http://tboy.co/pro' ) . '">' . esc_attr__( 'Upgrade', 'sportspress' ) . '</a>', |
| 155 |
), |
| 156 |
$links |
| 157 |
); |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Auto-load SP classes on demand to reduce memory consumption. |
| 162 |
* |
| 163 |
* @param mixed $class |
| 164 |
* @return void |
| 165 |
*/ |
| 166 |
public function autoload( $class ) { |
| 167 |
$path = null; |
| 168 |
$class = strtolower( $class ); |
| 169 |
$file = 'class-' . str_replace( '_', '-', $class ) . '.php'; |
| 170 |
|
| 171 |
if ( strpos( $class, 'sp_shortcode_' ) === 0 ) { |
| 172 |
$path = $this->plugin_path() . '/includes/shortcodes/'; |
| 173 |
} elseif ( strpos( $class, 'sp_meta_box' ) === 0 ) { |
| 174 |
$path = $this->plugin_path() . '/includes/admin/post-types/meta-boxes/'; |
| 175 |
} elseif ( strpos( $class, 'sp_admin' ) === 0 ) { |
| 176 |
$path = $this->plugin_path() . '/includes/admin/'; |
| 177 |
} |
| 178 |
|
| 179 |
if ( $path && is_readable( $path . $file ) ) { |
| 180 |
include_once $path . $file; |
| 181 |
return; |
| 182 |
} |
| 183 |
|
| 184 |
// Fallback |
| 185 |
if ( strpos( $class, 'sp_' ) === 0 ) { |
| 186 |
$path = $this->plugin_path() . '/includes/'; |
| 187 |
} |
| 188 |
|
| 189 |
if ( $path && is_readable( $path . $file ) ) { |
| 190 |
include_once $path . $file; |
| 191 |
return; |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* Define SP Constants. |
| 197 |
*/ |
| 198 |
private function define_constants() { |
| 199 |
define( 'SP_PLUGIN_FILE', __FILE__ ); |
| 200 |
define( 'SP_VERSION', $this->version ); |
| 201 |
|
| 202 |
if ( ! defined( 'SP_TEMPLATE_PATH' ) ) { |
| 203 |
define( 'SP_TEMPLATE_PATH', $this->template_path() ); |
| 204 |
} |
| 205 |
|
| 206 |
if ( ! defined( 'SP_DELIMITER' ) ) { |
| 207 |
define( 'SP_DELIMITER', '|' ); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* Include required core files used in admin and on the frontend. |
| 213 |
*/ |
| 214 |
private function includes() { |
| 215 |
include_once 'includes/sp-core-functions.php'; |
| 216 |
include_once 'includes/class-sp-install.php'; |
| 217 |
|
| 218 |
if ( is_admin() ) { |
| 219 |
include_once 'includes/admin/class-sp-admin.php'; |
| 220 |
} |
| 221 |
|
| 222 |
if ( defined( 'DOING_AJAX' ) ) { |
| 223 |
$this->ajax_includes(); |
| 224 |
} |
| 225 |
|
| 226 |
if ( ! is_admin() || defined( 'DOING_AJAX' ) ) { |
| 227 |
$this->frontend_includes(); |
| 228 |
} |
| 229 |
|
| 230 |
// Post types |
| 231 |
include_once 'includes/class-sp-post-types.php'; // Registers post types |
| 232 |
|
| 233 |
// Include abstract classes |
| 234 |
include_once 'includes/abstracts/abstract-sp-custom-post.php'; // Custom posts |
| 235 |
include_once 'includes/abstracts/abstract-sp-secondary-post.php'; // Secondary posts |
| 236 |
|
| 237 |
// Classes (used on all pages) |
| 238 |
include_once 'includes/class-sp-modules.php'; // Defines available modules |
| 239 |
include_once 'includes/class-sp-countries.php'; // Defines continents and countries |
| 240 |
include_once 'includes/class-sp-formats.php'; // Defines custom post type formats |
| 241 |
include_once 'includes/class-sp-templates.php'; // Defines custom post type templates |
| 242 |
include_once 'includes/class-sp-feeds.php'; // Adds feeds |
| 243 |
|
| 244 |
// Include template functions making them pluggable by plugins and themes. |
| 245 |
include_once 'includes/sp-template-functions.php'; |
| 246 |
|
| 247 |
// Include template hooks in time for themes to remove/modify them |
| 248 |
include_once 'includes/sp-template-hooks.php'; |
| 249 |
|
| 250 |
// WPML-related localization hooks |
| 251 |
include_once 'includes/class-sp-wpml.php'; |
| 252 |
|
| 253 |
// REST API |
| 254 |
include_once 'includes/api/class-sp-rest-api.php'; |
| 255 |
|
| 256 |
// TGMPA |
| 257 |
include_once 'includes/libraries/class-tgm-plugin-activation.php'; |
| 258 |
} |
| 259 |
|
| 260 |
/** |
| 261 |
* Include required ajax files. |
| 262 |
*/ |
| 263 |
public function ajax_includes() { |
| 264 |
include_once 'includes/class-sp-ajax.php'; // Ajax functions for admin and the front-end |
| 265 |
} |
| 266 |
|
| 267 |
/** |
| 268 |
* Include required frontend files. |
| 269 |
*/ |
| 270 |
public function frontend_includes() { |
| 271 |
include_once 'includes/class-sp-template-loader.php'; // Template Loader |
| 272 |
include_once 'includes/class-sp-frontend-scripts.php'; // Frontend Scripts |
| 273 |
include_once 'includes/class-sp-shortcodes.php'; // Shortcodes class |
| 274 |
} |
| 275 |
|
| 276 |
/** |
| 277 |
* Include core modules. |
| 278 |
*/ |
| 279 |
private function include_modules() { |
| 280 |
$dir = scandir( $this->plugin_path() . '/modules' ); |
| 281 |
if ( $dir ) { |
| 282 |
$path = $this->plugin_path() . '/modules/'; |
| 283 |
foreach ( $dir as $module ) { |
| 284 |
if ( $path && substr( $module, 0, 1 ) !== '.' ) { |
| 285 |
if ( is_readable( $path . $module ) ) { |
| 286 |
include_once $path . $module; |
| 287 |
} |
| 288 |
} |
| 289 |
} |
| 290 |
} |
| 291 |
} |
| 292 |
|
| 293 |
/** |
| 294 |
* Init SportsPress when WordPress Initialises. |
| 295 |
*/ |
| 296 |
public function init() { |
| 297 |
// Before init action |
| 298 |
do_action( 'before_sportspress_init' ); |
| 299 |
|
| 300 |
// Set up localisation |
| 301 |
$this->load_plugin_textdomain(); |
| 302 |
|
| 303 |
// Load class instances |
| 304 |
$this->modules = new SP_Modules(); // Modules class |
| 305 |
$this->countries = new SP_Countries(); // Countries class |
| 306 |
$this->formats = new SP_Formats(); // Formats class |
| 307 |
$this->templates = new SP_Templates(); // Templates class |
| 308 |
$this->feeds = new SP_Feeds(); // Feeds class |
| 309 |
|
| 310 |
// Load string options |
| 311 |
$this->text = get_option( 'sportspress_text', array() ); |
| 312 |
|
| 313 |
// Init action |
| 314 |
do_action( 'sportspress_init' ); |
| 315 |
} |
| 316 |
|
| 317 |
/** |
| 318 |
* Load Localisation files. |
| 319 |
* |
| 320 |
* Note: the first-loaded translation file overrides any following ones if the same translation is present |
| 321 |
*/ |
| 322 |
public function load_plugin_textdomain() { |
| 323 |
$locale = apply_filters( 'plugin_locale', get_locale(), 'sportspress' ); |
| 324 |
|
| 325 |
// Global + Frontend Locale |
| 326 |
load_textdomain( 'sportspress', WP_LANG_DIR . "/sportspress/sportspress-$locale.mo" ); |
| 327 |
load_plugin_textdomain( 'sportspress', false, plugin_basename( dirname( __FILE__ ) . '/languages' ) ); |
| 328 |
} |
| 329 |
|
| 330 |
/** |
| 331 |
* Ensure theme and server variable compatibility and setup image sizes. |
| 332 |
*/ |
| 333 |
public function setup_environment() { |
| 334 |
if ( ! current_theme_supports( 'post-thumbnails' ) ) { |
| 335 |
add_theme_support( 'post-thumbnails' ); |
| 336 |
} |
| 337 |
|
| 338 |
// Add image sizes |
| 339 |
add_image_size( 'sportspress-crop-medium', 300, 300, true ); |
| 340 |
add_image_size( 'sportspress-fit-medium', 300, 300, false ); |
| 341 |
add_image_size( 'sportspress-fit-icon', 128, 128, false ); |
| 342 |
add_image_size( 'sportspress-fit-mini', 32, 32, false ); |
| 343 |
} |
| 344 |
|
| 345 |
/** |
| 346 |
* Recommend SportsPress extension for available sports. |
| 347 |
*/ |
| 348 |
public static function extension() { |
| 349 |
$sport = sp_array_value( $_POST, 'sportspress_sport', get_option( 'sportspress_sport', null ), 'key' ); |
| 350 |
if ( ! $sport ) { |
| 351 |
return; |
| 352 |
} |
| 353 |
|
| 354 |
$plugins = array(); |
| 355 |
|
| 356 |
switch ( $sport ) : |
| 357 |
case 'baseball': |
| 358 |
$plugins[] = array( |
| 359 |
'name' => 'SportsPress for Baseball', |
| 360 |
'slug' => 'sportspress-for-baseball', |
| 361 |
'required' => false, |
| 362 |
'version' => '1.0', |
| 363 |
); |
| 364 |
break; |
| 365 |
case 'basketball': |
| 366 |
$plugins[] = array( |
| 367 |
'name' => 'SportsPress for Basketball', |
| 368 |
'slug' => 'sportspress-for-basketball', |
| 369 |
'required' => false, |
| 370 |
'version' => '0.9.1', |
| 371 |
); |
| 372 |
break; |
| 373 |
case 'cricket': |
| 374 |
$plugins[] = array( |
| 375 |
'name' => 'SportsPress for Cricket', |
| 376 |
'slug' => 'sportspress-for-cricket', |
| 377 |
'required' => false, |
| 378 |
'version' => '1.1.1', |
| 379 |
); |
| 380 |
break; |
| 381 |
case 'golf': |
| 382 |
$plugins[] = array( |
| 383 |
'name' => 'SportsPress for Golf', |
| 384 |
'slug' => 'sportspress-for-golf', |
| 385 |
'required' => false, |
| 386 |
'version' => '0.9.1', |
| 387 |
); |
| 388 |
break; |
| 389 |
case 'soccer': |
| 390 |
$plugins[] = array( |
| 391 |
'name' => 'SportsPress for Football (Soccer)', |
| 392 |
'slug' => 'sportspress-for-soccer', |
| 393 |
'required' => false, |
| 394 |
'version' => '0.9.6', |
| 395 |
); |
| 396 |
break; |
| 397 |
case 'volleyball': |
| 398 |
$plugins[] = array( |
| 399 |
'name' => 'SportsPress for Volleyball', |
| 400 |
'slug' => 'sportspress-for-volleyball', |
| 401 |
'required' => false, |
| 402 |
'version' => '0.9', |
| 403 |
); |
| 404 |
break; |
| 405 |
endswitch; |
| 406 |
|
| 407 |
$config = array( |
| 408 |
'id' => 'sportspress', |
| 409 |
'default_path' => '', |
| 410 |
'menu' => 'tgmpa-install-plugins', |
| 411 |
'parent_slug' => 'plugins.php', |
| 412 |
'capability' => 'manage_options', |
| 413 |
'has_notices' => true, |
| 414 |
'dismissable' => true, |
| 415 |
'is_automatic' => true, |
| 416 |
'message' => '', |
| 417 |
'strings' => array( |
| 418 |
'nag_type' => 'updated', |
| 419 |
), |
| 420 |
); |
| 421 |
|
| 422 |
tgmpa( $plugins, $config ); |
| 423 |
} |
| 424 |
|
| 425 |
/** Helper functions ******************************************************/ |
| 426 |
|
| 427 |
/** |
| 428 |
* Get the plugin url. |
| 429 |
* |
| 430 |
* @return string |
| 431 |
*/ |
| 432 |
public function plugin_url() { |
| 433 |
return untrailingslashit( plugins_url( '/', __FILE__ ) ); |
| 434 |
} |
| 435 |
|
| 436 |
/** |
| 437 |
* Get the plugin path. |
| 438 |
* |
| 439 |
* @return string |
| 440 |
*/ |
| 441 |
public function plugin_path() { |
| 442 |
return untrailingslashit( plugin_dir_path( __FILE__ ) ); |
| 443 |
} |
| 444 |
|
| 445 |
/** |
| 446 |
* Get the template path. |
| 447 |
* |
| 448 |
* @return string |
| 449 |
*/ |
| 450 |
public function template_path() { |
| 451 |
return apply_filters( 'SP_TEMPLATE_PATH', 'sportspress/' ); |
| 452 |
} |
| 453 |
} |
| 454 |
|
| 455 |
endif; |
| 456 |
|
| 457 |
if ( ! function_exists( 'SP' ) ) : |
| 458 |
|
| 459 |
/** |
| 460 |
* Returns the main instance of SP to prevent the need to use globals. |
| 461 |
* |
| 462 |
* @since 0.7 |
| 463 |
* @return SportsPress |
| 464 |
*/ |
| 465 |
function SP() { |
| 466 |
return SportsPress::instance(); |
| 467 |
} |
| 468 |
|
| 469 |
endif; |
| 470 |
|
| 471 |
SP(); |
| 472 |
|
| 473 |
/** |
| 474 |
* Want to work with us? |
| 475 |
* |
| 476 |
* @link https://www.themeboy.com/jobs/ |
| 477 |
*/ |
| 478 |
|