Modularize!

This commit is contained in:
Brian Miyaji
2015-01-28 14:02:35 +11:00
parent aa0eeae6cd
commit 87baaf7288
35 changed files with 1491 additions and 928 deletions

View File

@@ -0,0 +1,312 @@
<?php
/*
Plugin Name: SportsPress Calendars
Plugin URI: http://themeboy.com/
Description: Add event calendars to SportsPress.
Author: ThemeBoy
Author URI: http://themeboy.com/
Version: 1.6
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'SportsPress_Calendars' ) ) :
/**
* Main SportsPress Calendars Class
*
* @class SportsPress_Calendars
* @version 1.6
*/
class SportsPress_Calendars {
/**
* Constructor
*/
public function __construct() {
// Define constants
$this->define_constants();
// Actions
add_action( 'init', array( $this, 'register_post_type' ) );
add_action( 'sportspress_include_post_type_handlers', array( $this, 'include_post_type_handler' ) );
add_action( 'sportspress_widgets', array( $this, 'include_widgets' ) );
// Filters
add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) );
add_filter( 'sportspress_shortcodes', array( $this, 'add_shortcodes' ) );
add_filter( 'sportspress_event_settings', array( $this, 'add_settings' ) );
}
/**
* Define constants.
*/
private function define_constants() {
if ( !defined( 'SP_CALENDARS_VERSION' ) )
define( 'SP_CALENDARS_VERSION', '1.6' );
if ( !defined( 'SP_CALENDARS_URL' ) )
define( 'SP_CALENDARS_URL', plugin_dir_url( __FILE__ ) );
if ( !defined( 'SP_CALENDARS_DIR' ) )
define( 'SP_CALENDARS_DIR', plugin_dir_path( __FILE__ ) );
}
/**
* Register calendars post type
*/
public static function register_post_type() {
register_post_type( 'sp_calendar',
apply_filters( 'sportspress_register_post_type_calendar',
array(
'labels' => array(
'name' => __( 'Calendars', 'sportspress' ),
'singular_name' => __( 'Calendar', 'sportspress' ),
'add_new_item' => __( 'Add New Calendar', 'sportspress' ),
'edit_item' => __( 'Edit Calendar', 'sportspress' ),
'new_item' => __( 'New', 'sportspress' ),
'view_item' => __( 'View Calendar', 'sportspress' ),
'search_items' => __( 'Search', 'sportspress' ),
'not_found' => __( 'No results found.', 'sportspress' ),
'not_found_in_trash' => __( 'No results found.', 'sportspress' ),
),
'public' => true,
'show_ui' => true,
'capability_type' => 'sp_calendar',
'map_meta_cap' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'hierarchical' => false,
'rewrite' => array( 'slug' => get_option( 'sportspress_calendar_slug', 'calendar' ) ),
'supports' => array( 'title', 'author', 'thumbnail' ),
'has_archive' => false,
'show_in_nav_menus' => true,
'show_in_menu' => 'edit.php?post_type=sp_event',
'show_in_admin_bar' => true,
)
)
);
}
/**
* Conditonally load the class and functions only needed when viewing this post type.
*/
public function include_post_type_handler() {
include_once( SP()->plugin_path() . '/includes/admin/post-types/class-sp-admin-cpt-calendar.php' );
}
/**
* Add widgets.
*
* @return array
*/
public function include_widgets() {
include_once( SP()->plugin_path() . '/includes/widgets/class-sp-widget-event-calendar.php' );
include_once( SP()->plugin_path() . '/includes/widgets/class-sp-widget-event-list.php' );
include_once( SP()->plugin_path() . '/includes/widgets/class-sp-widget-event-blocks.php' );
}
/**
* Add meta boxes to calendars.
*
* @return array
*/
public function add_meta_boxes( $meta_boxes ) {
$meta_boxes['sp_calendar'] = array(
'shortcode' => array(
'title' => __( 'Shortcode', 'sportspress' ),
'output' => 'SP_Meta_Box_Calendar_Shortcode::output',
'context' => 'side',
'priority' => 'default',
),
'feeds' => array(
'title' => __( 'Feeds', 'sportspress' ),
'output' => 'SP_Meta_Box_Calendar_Feeds::output',
'context' => 'side',
'priority' => 'default',
),
'format' => array(
'title' => __( 'Layout', 'sportspress' ),
'save' => 'SP_Meta_Box_Calendar_Format::save',
'output' => 'SP_Meta_Box_Calendar_Format::output',
'context' => 'side',
'priority' => 'default',
),
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Calendar_Details::save',
'output' => 'SP_Meta_Box_Calendar_Details::output',
'context' => 'side',
'priority' => 'default',
),
'data' => array(
'title' => __( 'Events', 'sportspress' ),
'save' => 'SP_Meta_Box_Calendar_Data::save',
'output' => 'SP_Meta_Box_Calendar_Data::output',
'context' => 'normal',
'priority' => 'high',
),
'editor' => array(
'title' => __( 'Description', 'sportspress' ),
'output' => 'SP_Meta_Box_Calendar_Editor::output',
'context' => 'normal',
'priority' => 'low',
),
);
return $meta_boxes;
}
/**
* Add shortcodes.
*
* @return array
*/
public function add_shortcodes( $shortcodes ) {
$shortcodes['event'][] = 'calendar';
$shortcodes['event'][] = 'list';
$shortcodes['event'][] = 'blocks';
return $shortcodes;
}
/**
* Add settings.
*
* @return array
*/
public function add_settings( $settings ) {
$settings = array_merge( $settings,
array(
array( 'title' => __( 'Event List', 'sportspress' ), 'type' => 'title', 'id' => 'event_list_options' ),
),
apply_filters( 'sportspress_event_list_options', array(
array(
'title' => __( 'Teams', 'sportspress' ),
'desc' => __( 'Display logos', 'sportspress' ),
'id' => 'sportspress_event_list_show_logos',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Title Format', 'sportspress' ),
'id' => 'sportspress_event_list_title_format',
'default' => 'title',
'type' => 'select',
'options' => array(
'title' => __( 'Title', 'sportspress' ),
'teams' => __( 'Teams', 'sportspress' ),
'homeaway' => sprintf( '%s | %s', __( 'Home', 'sportspress' ), __( 'Away', 'sportspress' ) ),
),
),
array(
'title' => __( 'Time/Results Format', 'sportspress' ),
'id' => 'sportspress_event_list_time_format',
'default' => 'combined',
'type' => 'select',
'options' => array(
'combined' => __( 'Combined', 'sportspress' ),
'separate' => __( 'Separate', 'sportspress' ),
'time' => __( 'Time Only', 'sportspress' ),
'results' => __( 'Results Only', 'sportspress' ),
),
),
array(
'title' => __( 'Pagination', 'sportspress' ),
'desc' => __( 'Paginate', 'sportspress' ),
'id' => 'sportspress_event_list_paginated',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Limit', 'sportspress' ),
'id' => 'sportspress_event_list_rows',
'class' => 'small-text',
'default' => '10',
'desc' => __( 'events', 'sportspress' ),
'type' => 'number',
'custom_attributes' => array(
'min' => 1,
'step' => 1
),
),
)),
array(
array( 'type' => 'sectionend', 'id' => 'event_list_options' ),
array( 'title' => __( 'Event Blocks', 'sportspress' ), 'type' => 'title', 'id' => 'event_blocks_options' ),
),
apply_filters( 'sportspress_event_blocks_options', array(
array(
'title' => __( 'Title', 'sportspress' ),
'desc' => __( 'Display calendar title', 'sportspress' ),
'id' => 'sportspress_event_blocks_show_title',
'default' => 'no',
'type' => 'checkbox',
),
array(
'title' => __( 'Details', 'sportspress' ),
'desc' => __( 'Display competition', 'sportspress' ),
'id' => 'sportspress_event_blocks_show_league',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Display season', 'sportspress' ),
'id' => 'sportspress_event_blocks_show_season',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Display venue', 'sportspress' ),
'id' => 'sportspress_event_blocks_show_venue',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'title' => __( 'Pagination', 'sportspress' ),
'desc' => __( 'Paginate', 'sportspress' ),
'id' => 'sportspress_event_blocks_paginated',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Limit', 'sportspress' ),
'id' => 'sportspress_event_blocks_rows',
'class' => 'small-text',
'default' => '10',
'desc' => __( 'events', 'sportspress' ),
'type' => 'number',
'custom_attributes' => array(
'min' => 1,
'step' => 1
),
),
)),
array(
array( 'type' => 'sectionend', 'id' => 'event_list_options' ),
)
);
return $settings;
}
}
endif;
if ( get_option( 'sportspress_load_calendars_module', 'yes' ) == 'yes' ) {
new SportsPress_Calendars();
}

View File

@@ -0,0 +1,70 @@
<?php
/*
Plugin Name: SportsPress Event Videos
Plugin URI: http://themeboy.com/
Description: Add videos to SportsPress events.
Author: ThemeBoy
Author URI: http://themeboy.com/
Version: 1.6
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'SportsPress_Event_Videos' ) ) :
/**
* Main SportsPress Event Videos Class
*
* @class SportsPress_Event_Videos
* @version 1.6
*/
class SportsPress_Event_Videos {
/**
* Constructor
*/
public function __construct() {
// Define constants
$this->define_constants();
// Filters
add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_box' ) );
}
/**
* Define constants.
*/
private function define_constants() {
if ( !defined( 'SP_EVENT_VIDEOS_VERSION' ) )
define( 'SP_EVENT_VIDEOS_VERSION', '1.6' );
if ( !defined( 'SP_EVENT_VIDEOS_URL' ) )
define( 'SP_EVENT_VIDEOS_URL', plugin_dir_url( __FILE__ ) );
if ( !defined( 'SP_EVENT_VIDEOS_DIR' ) )
define( 'SP_EVENT_VIDEOS_DIR', plugin_dir_path( __FILE__ ) );
}
/**
* Add meta box to events.
*
* @return array
*/
public function add_meta_box( $meta_boxes ) {
$meta_boxes['sp_event']['video'] = array(
'title' => __( 'Video', 'sportspress' ),
'output' => 'SP_Meta_Box_Event_Video::output',
'save' => 'SP_Meta_Box_Event_Video::save',
'context' => 'side',
'priority' => 'low',
);
return $meta_boxes;
}
}
endif;
if ( get_option( 'sportspress_load_event_videos_module', 'yes' ) == 'yes' ) {
new SportsPress_Event_Videos();
}

View File

@@ -0,0 +1,232 @@
<?php
/*
Plugin Name: SportsPress Individual Mode
Plugin URI: http://themeboy.com/
Description: Modify SportsPress to work with individual (player vs player) sports.
Author: ThemeBoy
Author URI: http://themeboy.com/
Version: 1.6
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'SportsPress_Individual_Mode' ) ) :
/**
* Main SportsPress Individual Mode Class
*
* @class SportsPress_Individual_Mode
* @version 1.6
*/
class SportsPress_Individual_Mode {
/**
* Constructor
*/
public function __construct() {
// Define constants
$this->define_constants();
// Filters
add_filter( 'gettext', array( $this, 'gettext' ), 99, 3 );
add_filter( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
add_filter( 'sportspress_register_post_type_team', array( $this, 'hide_post_type' ), 99 );
add_filter( 'sportspress_register_post_type_table', array( $this, 'move_table_post_type' ), 99 );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'remove_team_settings_tab' ), 99 );
add_filter( 'sportspress_get_settings_pages', array( $this, 'remove_team_settings' ), 99 );
add_filter( 'sportspress_player_options', array( $this, 'add_player_options' ), 99 );
add_filter( 'sportspress_player_settings', array( $this, 'add_player_settings' ), 99 );
add_filter( 'sportspress_next_steps', array( $this, 'remove_team_step' ), 99 );
add_filter( 'sportspress_modules', array( $this, 'rearrange_modules' ), 99 );
add_filter( 'sportspress_glance_items', array( $this, 'remove_glance_item' ), 99 );
add_filter( 'sportspress_shortcodes', array( $this, 'remove_shortcodes' ), 99 );
add_filter( 'sportspress_list_admin_columns', array( $this, 'remove_team_column' ), 99 );
add_filter( 'sportspress_importers', array( $this, 'remove_teams_importer' ), 99 );
add_filter( 'sportspress_permalink_slugs', array( $this, 'remove_team_permalink_slug' ), 99 );
add_filter( 'sportspress_event_team_tabs', '__return_false' );
add_filter( 'sportspress_list_team_selector', '__return_false' );
// Remove templates
remove_action( 'sportspress_single_event_content', 'sportspress_output_event_performance', 50 );
}
/**
* Define constants.
*/
private function define_constants() {
if ( !defined( 'SP_INDIVIDUAL_MODE_VERSION' ) )
define( 'SP_INDIVIDUAL_MODE_VERSION', '1.6' );
if ( !defined( 'SP_INDIVIDUAL_MODE_URL' ) )
define( 'SP_INDIVIDUAL_MODE_URL', plugin_dir_url( __FILE__ ) );
if ( !defined( 'SP_INDIVIDUAL_MODE_DIR' ) )
define( 'SP_INDIVIDUAL_MODE_DIR', plugin_dir_path( __FILE__ ) );
}
/**
* Modify all team-related strings for players.
*/
public function gettext( $translated_text, $untranslated_text, $domain ) {
if ( 'sportspress' !== $domain ) return $translated_text;
switch ( $untranslated_text ) {
case 'Teams':
return __( 'Players', 'sportspress' );
break;
case 'Team':
return __( 'Player', 'sportspress' );
break;
case 'teams':
return __( 'players', 'sportspress' );
break;
}
return $translated_text;
}
/**
* Modify all team post type queries for players.
*/
public function pre_get_posts( $query ) {
if ( 'sp_team' !== $query->get( 'post_type' ) ) return $query;
$query->set( 'post_type', 'sp_player' );
return $query;
}
/**
* Hide post types.
*/
public function hide_post_type( $args ) {
return array_merge( $args, array(
'public' => false,
'exclude_from_search' => true,
'publicly_queryable' => false,
'show_ui' => false,
'show_in_nav_menus' => false,
'show_in_menu' => false,
'show_in_admin_bar' => false,
'can_export' => false,
) );
}
/**
* Move league table post type under players.
*/
public function move_table_post_type( $args ) {
return array_merge( $args, array(
'show_in_menu' => 'edit.php?post_type=sp_player',
) );
}
/**
* Remove team settings tab.
*/
public function remove_team_settings_tab( $tabs ) {
unset( $tabs['teams'] );
return $tabs;
}
/**
* Remove team settings section.
*/
public function remove_team_settings( $settings ) {
foreach ( $settings as $index => $section ) {
if ( is_a( $section, 'SP_Settings_Teams' ) ) {
unset( $settings[ $index ] );
}
}
return $settings;
}
/**
* Add options from teams to players tab.
*/
public function add_player_options( $options ) {
return apply_filters( 'sportspress_team_options', $options );
}
/**
* Add settings from teams to players tab.
*/
public function add_player_settings( $settings ) {
return apply_filters( 'sportspress_team_settings', $settings );
}
/**
* Remove team step from welcome screen.
*/
public function remove_team_step( $steps ) {
unset( $steps['teams'] );
return $steps;
}
/**
* Rearrange modules.
*/
public function rearrange_modules( $modules ) {
$modules['player'] = array_merge(
sp_array_value( $modules, 'team', array() ),
sp_array_value( $modules, 'player' )
);
unset( $modules['player']['team_colors'] );
return $modules;
}
/**
* Remove teams glance item.
*/
public function remove_glance_item( $items ) {
if ( ( $index = array_search ( 'sp_team', $items ) ) !== false ) {
unset( $items[ $index ] );
}
return $items;
}
/**
* Remove shortcodes from editor.
*/
public function remove_shortcodes( $shortcodes ) {
if ( array_key_exists( 'event', $shortcodes ) ) {
if ( ( $index = array_search ( 'performance', $shortcodes['event'] ) ) !== false ) {
unset( $shortcodes['event'][ $index ] );
}
}
return $shortcodes;
}
/**
* Remove team column from player list admin.
*/
public function remove_team_column( $columns ) {
unset( $columns['sp_team'] );
return $columns;
}
/**
* Remove the teams csv importer.
*/
public function remove_teams_importer( $importers ) {
unset( $importers['sp_team_csv'] );
return $importers;
}
/**
* Remove the team permalink slug setting.
*/
public function remove_team_permalink_slug( $slugs ) {
if ( ( $index = array_search ( array( 'team', __( 'Teams', 'sportspress' ) ), $slugs ) ) !== false ) {
unset( $slugs[ $index ] );
}
return $slugs;
}
}
endif;
if ( get_option( 'sportspress_load_individual_mode_module', 'yes' ) == 'yes' ) {
new SportsPress_Individual_Mode();
}

View File

@@ -0,0 +1,104 @@
<?php
/*
Plugin Name: SportsPress League Tables
Plugin URI: http://themeboy.com/
Description: Add league tables to SportsPress.
Author: ThemeBoy
Author URI: http://themeboy.com/
Version: 1.6
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'SportsPress_League_Tables' ) ) :
/**
* Main SportsPress League Tables Class
*
* @class SportsPress_League_Tables
* @version 1.6
*/
class SportsPress_League_Tables {
/**
* Constructor
*/
public function __construct() {
// Define constants
$this->define_constants();
// Mods
add_filter( 'sportspress_team_settings', array( $this, 'add_options' ) );
}
/**
* Define constants.
*/
private function define_constants() {
if ( !defined( 'SP_LEAGUE_TABLES_VERSION' ) )
define( 'SP_LEAGUE_TABLES_VERSION', '1.6' );
if ( !defined( 'SP_LEAGUE_TABLES_URL' ) )
define( 'SP_LEAGUE_TABLES_URL', plugin_dir_url( __FILE__ ) );
if ( !defined( 'SP_LEAGUE_TABLES_DIR' ) )
define( 'SP_LEAGUE_TABLES_DIR', plugin_dir_path( __FILE__ ) );
}
/**
* Add options to settings page.
*
* @return array
*/
public function add_options( $settings ) {
return array_merge( $settings,
array(
array( 'title' => __( 'League Tables', 'sportspress' ), 'type' => 'title', 'id' => 'table_options' ),
),
apply_filters( 'sportspress_table_options', array(
array(
'title' => __( 'Teams', 'sportspress' ),
'desc' => __( 'Display logos', 'sportspress' ),
'id' => 'sportspress_table_show_logos',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Pagination', 'sportspress' ),
'desc' => __( 'Paginate', 'sportspress' ),
'id' => 'sportspress_table_paginated',
'default' => 'yes',
'type' => 'checkbox',
),
array(
'title' => __( 'Limit', 'sportspress' ),
'id' => 'sportspress_table_rows',
'class' => 'small-text',
'default' => '10',
'desc' => __( 'teams', 'sportspress' ),
'type' => 'number',
'custom_attributes' => array(
'min' => 1,
'step' => 1
),
),
) ),
array(
array( 'type' => 'sectionend', 'id' => 'table_options' ),
)
);
}
}
endif;
if ( get_option( 'sportspress_load_league_tables_module', 'yes' ) == 'yes' ) {
new SportsPress_League_Tables();
}