Move sports presets class
This commit is contained in:
@@ -28,6 +28,7 @@ class SP_Admin_Settings {
|
||||
if ( empty( self::$settings ) ) {
|
||||
$settings = array();
|
||||
|
||||
include_once( 'class-sp-admin-sports.php' );
|
||||
include_once( 'settings/class-sp-settings-page.php' );
|
||||
|
||||
$settings[] = include( 'settings/class-sp-settings-general.php' );
|
||||
|
||||
74
includes/admin/class-sp-admin-sports.php
Normal file
74
includes/admin/class-sp-admin-sports.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Admin Sports Class.
|
||||
*
|
||||
* The SportsPress admin sports class stores preset sport data.
|
||||
*
|
||||
* @class SP_Admin_Sports
|
||||
* @version 0.8
|
||||
* @package SportsPress/Admin
|
||||
* @category Class
|
||||
* @author ThemeBoy
|
||||
*/
|
||||
class SP_Admin_Sports {
|
||||
private static $presets = array();
|
||||
|
||||
/**
|
||||
* Include the preset classes
|
||||
*/
|
||||
public static function get_presets() {
|
||||
if ( empty( self::$presets ) ) {
|
||||
$presets = array();
|
||||
|
||||
include( 'presets/class-sp-preset-sport.php' );
|
||||
|
||||
$dir = scandir( SP()->plugin_path() . '/presets' );
|
||||
$files = array();
|
||||
if ( $dir ) {
|
||||
foreach ( $dir as $key => $value ) {
|
||||
if ( ! in_array( $value, array( ".",".." ) ) ) {
|
||||
$files[] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach( $files as $file ) {
|
||||
$json_data = file_get_contents( SP()->plugin_path() . '/presets/' . $file );
|
||||
$data = json_decode( $json_data, true );
|
||||
pr( $data );
|
||||
}
|
||||
|
||||
//$presets[] = include( 'presets/class-sp-preset-soccer.php' );
|
||||
//$presets[] = include( 'presets/class-sp-preset-baseball.php' );SP_TEMPLATE_PATH
|
||||
|
||||
self::$presets = apply_filters( 'sportspress_get_presets', $presets );
|
||||
}
|
||||
return self::$presets;
|
||||
}
|
||||
|
||||
public static function get_preset_options() {
|
||||
$presets = self::get_presets();
|
||||
$options = apply_filters( 'sportspress_sport_presets_array', array() );
|
||||
return $options;
|
||||
}
|
||||
|
||||
/** @var array Array of sports */
|
||||
private $data;
|
||||
|
||||
/**
|
||||
* Constructor for the sports class - defines all preset sports.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->data = sp_get_sport_presets();
|
||||
}
|
||||
|
||||
public function __get( $key ) {
|
||||
return ( array_key_exists( $key, $this->data ) ? $this->data[ $key ] : null );
|
||||
}
|
||||
|
||||
public function __set( $key, $value ){
|
||||
$this->data[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
33
includes/admin/presets/class-sp-preset-baseball.php
Normal file
33
includes/admin/presets/class-sp-preset-baseball.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Baseball Preset
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.8
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Preset_Baseball' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Preset_Baseball
|
||||
*/
|
||||
class SP_Preset_Baseball extends SP_Preset_Sport {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'baseball';
|
||||
$this->label = __( 'Baseball', 'sportspress' );
|
||||
|
||||
add_filter( 'sportspress_sport_presets_array', array( $this, 'add_sport_preset' ), 20 );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Preset_Baseball();
|
||||
33
includes/admin/presets/class-sp-preset-soccer.php
Normal file
33
includes/admin/presets/class-sp-preset-soccer.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Soccer Preset
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.8
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Preset_Soccer' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Preset_Soccer
|
||||
*/
|
||||
class SP_Preset_Soccer extends SP_Preset_Sport {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->id = 'soccer';
|
||||
$this->label = __( 'Association Football (Soccer)', 'sportspress' );
|
||||
|
||||
add_filter( 'sportspress_sport_presets_array', array( $this, 'add_sport_preset' ), 20 );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_Preset_Soccer();
|
||||
33
includes/admin/presets/class-sp-preset-sport.php
Normal file
33
includes/admin/presets/class-sp-preset-sport.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* SportsPress Sport Preset
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin
|
||||
* @version 0.8
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_Preset_Sport' ) ) :
|
||||
|
||||
/**
|
||||
* SP_Preset_Sport
|
||||
*/
|
||||
class SP_Preset_Sport {
|
||||
|
||||
protected $id = '';
|
||||
protected $label = '';
|
||||
|
||||
/**
|
||||
* Add this page to settings
|
||||
*/
|
||||
public function add_sport_preset( $presets ) {
|
||||
$presets[ $this->id ] = $this->label;
|
||||
|
||||
return $presets;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
@@ -39,7 +39,10 @@ class SP_Settings_General extends SP_Settings_Page {
|
||||
* @return array
|
||||
*/
|
||||
public function get_settings() {
|
||||
$sports = sp_get_sport_options();
|
||||
|
||||
$sports = new SP_Admin_Sports();
|
||||
|
||||
$presets = $sports->get_preset_options();
|
||||
|
||||
return apply_filters( 'sportspress_general_settings', array(
|
||||
|
||||
@@ -52,7 +55,7 @@ class SP_Settings_General extends SP_Settings_Page {
|
||||
'id' => 'sportspress_sport',
|
||||
'default' => 'soccer',
|
||||
'type' => 'select',
|
||||
'options' => $sports,
|
||||
'options' => $presets,
|
||||
),
|
||||
|
||||
array( 'type' => 'sectionend', 'id' => 'general_options' ),
|
||||
|
||||
Reference in New Issue
Block a user