Create CPT classes for primary post types

This commit is contained in:
Brian Miyaji
2014-03-26 00:02:46 +11:00
parent 9cf595a941
commit 212d623a33
9 changed files with 872 additions and 39 deletions

View File

@@ -28,32 +28,6 @@ function sportspress_event_post_init() {
}
add_action( 'init', 'sportspress_event_post_init' );
function sportspress_event_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'sp_format' => '<span class="dashicons sp-icon-calendar tips" title="' . __( 'Format', 'sportspress' ) . '"></span>',
'title' => __( 'Event', 'sportspress' ),
'date' => __( 'Date', 'sportspress' ),
'sp_time' => __( 'Time', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_views' => __( 'Views', 'sportspress' ),
);
return $columns;
}
add_filter( 'manage_edit-sp_event_columns', 'sportspress_event_edit_columns' );
function sportspress_event_display_scheduled( $posts ) {
global $wp_query, $wpdb;
if ( is_single() && $wp_query->post_count == 0 && isset( $wp_query->query_vars['sp_event'] )) {
$posts = $wpdb->get_results( $wp_query->request );
}
return $posts;
}
add_filter( 'the_posts', 'sportspress_event_display_scheduled' );
function sportspress_event_meta_init( $post ) {
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
$players = (array)get_post_meta( $post->ID, 'sp_player', false );

View File

@@ -0,0 +1,98 @@
<?php
/**
* Post Types Admin
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Admin_Post_Types' ) ) :
/**
* SP_Admin_Post_Types Class
*/
class SP_Admin_Post_Types {
/**
* Constructor
*/
public function __construct() {
add_action( 'admin_init', array( $this, 'include_post_type_handlers' ) );
add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
}
/**
* Conditonally load classes and functions only needed when viewing a post type.
*/
public function include_post_type_handlers() {
//include( 'post-types/class-sp-admin-meta-boxes.php' );
include( 'post-types/class-sp-admin-cpt-event.php' );
include( 'post-types/class-sp-admin-cpt-team.php' );
include( 'post-types/class-sp-admin-cpt-player.php' );
}
/**
* Change messages when a post type is updated.
*
* @param array $messages
* @return array
*/
public function post_updated_messages( $messages ) {
global $post, $post_ID;
$messages['product'] = array(
0 => '', // Unused. Messages start at index 1.
1 => sprintf( __( 'Product updated. <a href="%s">View Product</a>', 'sportspress' ), esc_url( get_permalink($post_ID) ) ),
2 => __( 'Custom field updated.', 'sportspress' ),
3 => __( 'Custom field deleted.', 'sportspress' ),
4 => __( 'Product updated.', 'sportspress' ),
5 => isset($_GET['revision']) ? sprintf( __( 'Product restored to revision from %s', 'sportspress' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => sprintf( __( 'Product published. <a href="%s">View Product</a>', 'sportspress' ), esc_url( get_permalink($post_ID) ) ),
7 => __( 'Product saved.', 'sportspress' ),
8 => sprintf( __( 'Product submitted. <a target="_blank" href="%s">Preview Product</a>', 'sportspress' ), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
9 => sprintf( __( 'Product scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Product</a>', 'sportspress' ),
date_i18n( __( 'M j, Y @ G:i', 'sportspress' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __( 'Product draft updated. <a target="_blank" href="%s">Preview Product</a>', 'sportspress' ), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
);
$messages['shop_order'] = array(
0 => '', // Unused. Messages start at index 1.
1 => __( 'Order updated.', 'sportspress' ),
2 => __( 'Custom field updated.', 'sportspress' ),
3 => __( 'Custom field deleted.', 'sportspress' ),
4 => __( 'Order updated.', 'sportspress' ),
5 => isset($_GET['revision']) ? sprintf( __( 'Order restored to revision from %s', 'sportspress' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => __( 'Order updated.', 'sportspress' ),
7 => __( 'Order saved.', 'sportspress' ),
8 => __( 'Order submitted.', 'sportspress' ),
9 => sprintf( __( 'Order scheduled for: <strong>%1$s</strong>.', 'sportspress' ),
date_i18n( __( 'M j, Y @ G:i', 'sportspress' ), strtotime( $post->post_date ) ) ),
10 => __( 'Order draft updated.', 'sportspress' )
);
$messages['shop_coupon'] = array(
0 => '', // Unused. Messages start at index 1.
1 => __( 'Coupon updated.', 'sportspress' ),
2 => __( 'Custom field updated.', 'sportspress' ),
3 => __( 'Custom field deleted.', 'sportspress' ),
4 => __( 'Coupon updated.', 'sportspress' ),
5 => isset($_GET['revision']) ? sprintf( __( 'Coupon restored to revision from %s', 'sportspress' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6 => __( 'Coupon updated.', 'sportspress' ),
7 => __( 'Coupon saved.', 'sportspress' ),
8 => __( 'Coupon submitted.', 'sportspress' ),
9 => sprintf( __( 'Coupon scheduled for: <strong>%1$s</strong>.', 'sportspress' ),
date_i18n( __( 'M j, Y @ G:i', 'sportspress' ), strtotime( $post->post_date ) ) ),
10 => __( 'Coupon draft updated.', 'sportspress' )
);
return $messages;
}
}
endif;
return new SP_Admin_Post_Types();

View File

@@ -34,7 +34,7 @@ class SP_Admin {
// include_once( 'sp-meta-box-functions.php' );
// Classes
// include_once( 'class-sp-admin-post-types.php' );
include_once( 'class-sp-admin-post-types.php' );
// include_once( 'class-sp-admin-taxonomies.php' );
// Classes we only need if the ajax is not-ajax

View File

@@ -0,0 +1,254 @@
<?php
/**
* Admin functions for the events post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post Types
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Admin_CPT' ) )
include( 'class-sp-admin-cpt.php' );
if ( ! class_exists( 'SP_Admin_CPT_Event' ) ) :
/**
* SP_Admin_CPT_Event Class
*/
class SP_Admin_CPT_Event extends SP_Admin_CPT {
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_event';
// Post title fields
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
// Before data updates
add_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ), 99, 2 );
// Admin Columns
add_filter( 'manage_edit-sp_event_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_event_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
add_filter( 'manage_edit-sp_event_sortable_columns', array( $this, 'custom_columns_sort' ) );
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Check if we're editing or adding an event
* @return boolean
*/
private function is_editing() {
if ( ! empty( $_GET['post_type'] ) && 'sp_event' == $_GET['post_type'] ) {
return true;
}
if ( ! empty( $_GET['post'] ) && 'sp_event' == get_post_type( $_GET['post'] ) ) {
return true;
}
if ( ! empty( $_REQUEST['post_id'] ) && 'sp_event' == get_post_type( $_REQUEST['post_id'] ) ) {
return true;
}
return false;
}
/**
* Change title boxes in admin.
* @param string $text
* @param object $post
* @return string
*/
public function enter_title_here( $text, $post ) {
if ( $post->post_type == 'sp_event' )
return __( '(Auto)', 'sportspress' );
return $text;
}
/**
* Auto-generate an event title based on the team playing if left blank.
*
* @param array $data
* @return array
*/
public function wp_insert_post_data( $data, $postarr ) {
global $sportspress_options;
if ( $data['post_type'] == 'sp_event' && $data['post_title'] == '' ):
$teams = sportspress_array_value( $postarr, 'sp_team', array() );
$team_names = array();
foreach( $teams as $team ):
$team_names[] = get_the_title( $team );
endforeach;
$data['post_title'] = implode( ' ' . sportspress_array_value( $sportspress_options, 'event_teams_delimiter', 'vs' ) . ' ', $team_names );
endif;
return $data;
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'sp_format' => '<span class="dashicons sp-icon-calendar tips" title="' . __( 'Format', 'sportspress' ) . '"></span>',
'title' => __( 'Event', 'sportspress' ),
'date' => __( 'Date', 'sportspress' ),
'sp_time' => __( 'Time', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_views' => __( 'Views', 'sportspress' ),
);
return $columns;
}
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_format':
$format = get_post_meta( $post_id, 'sp_format', true );
switch ( $format ):
case 'league':
echo '<span class="dashicons sp-icon-crown tips" title="' . __( 'League', 'sportspress' ) . '"></span>';
break;
case 'friendly':
echo '<span class="dashicons sp-icon-smile tips" title="' . __( 'Friendly', 'sportspress' ) . '"></span>';
break;
endswitch;
break;
case 'sp_time':
echo get_post_time( 'H:i', false, $post_id );
break;
case 'sp_team':
$teams = (array)get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
if ( empty( $teams ) ):
echo '&mdash;';
else:
$current_team = get_post_meta( $post_id, 'sp_current_team', true );
foreach( $teams as $team_id ):
if ( ! $team_id ) continue;
$team = get_post( $team_id );
if ( $team ):
echo $team->post_title;
if ( $team_id == $current_team ):
echo '<span class="dashicons dashicons-yes" title="' . __( 'Current Team', 'sportspress' ) . '"></span>';
endif;
echo '<br>';
endif;
endforeach;
endif;
break;
case 'sp_league':
echo get_the_terms ( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : '&mdash;';
break;
case 'sp_season':
echo get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '&mdash;';
break;
case 'sp_venue':
echo get_the_terms ( $post_id, 'sp_venue' ) ? the_terms( $post_id, 'sp_venue' ) : '&mdash;';
break;
case 'sp_views':
echo sportspress_get_post_views( $post_id );
break;
endswitch;
}
/**
* Make columns sortable
*
* https://gist.github.com/906872
*
* @access public
* @param mixed $columns
* @return array
*/
public function custom_columns_sort( $columns ) {
$custom = array(
'sp_views' => 'sp_views',
);
return wp_parse_args( $custom, $columns );
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_event' )
return;
sportspress_highlight_admin_menu();
$selected = isset( $_REQUEST['team'] ) ? $_REQUEST['team'] : null;
$args = array(
'post_type' => 'sp_team',
'name' => 'team',
'show_option_none' => __( 'Show all teams', 'sportspress' ),
'selected' => $selected,
'values' => 'ID',
);
wp_dropdown_pages( $args );
$selected = isset( $_REQUEST['sp_league'] ) ? $_REQUEST['sp_league'] : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected
);
sportspress_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? $_REQUEST['sp_season'] : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sportspress_dropdown_taxonomies( $args );
}
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
if ( $typenow == 'sp_event' ) {
if ( isset( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = $_GET['team'];
$query->query_vars['meta_key'] = 'sp_team';
}
}
}
}
endif;
return new SP_Admin_CPT_Event();

View File

@@ -0,0 +1,233 @@
<?php
/**
* Admin functions for the players post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post Types
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Admin_CPT' ) )
include( 'class-sp-admin-cpt.php' );
if ( ! class_exists( 'SP_Admin_CPT_Player' ) ) :
/**
* SP_Admin_CPT_Player Class
*/
class SP_Admin_CPT_Player extends SP_Admin_CPT {
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_player';
// Post title fields
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
// Admin Columns
add_filter( 'manage_edit-sp_player_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_player_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
add_filter( 'manage_edit-sp_player_sortable_columns', array( $this, 'custom_columns_sort' ) );
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Check if we're editing or adding an event
* @return boolean
*/
private function is_editing() {
if ( ! empty( $_GET['post_type'] ) && 'sp_player' == $_GET['post_type'] ) {
return true;
}
if ( ! empty( $_GET['post'] ) && 'sp_player' == get_post_type( $_GET['post'] ) ) {
return true;
}
if ( ! empty( $_REQUEST['post_id'] ) && 'sp_player' == get_post_type( $_REQUEST['post_id'] ) ) {
return true;
}
return false;
}
/**
* Change title boxes in admin.
* @param string $text
* @param object $post
* @return string
*/
public function enter_title_here( $text, $post ) {
if ( $post->post_type == 'sp_player' )
return __( 'Name', 'sportspress' );
return $text;
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'sp_number' => '<span class="dashicons sp-icon-tshirt tips" title="' . __( 'Number', 'sportspress' ) . '"></span>',
'title' => __( 'Player', 'sportspress' ),
'sp_position' => __( 'Positions', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
'sp_views' => __( 'Views', 'sportspress' ),
);
return $columns;
}
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_position':
echo get_the_terms( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : '&mdash;';
break;
case 'sp_team':
$teams = (array)get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
if ( empty( $teams ) ):
echo '&mdash;';
else:
$results = get_post_meta( $post_id, 'sp_results', true );
global $sportspress_options;
$main_result = sportspress_array_value( $sportspress_options, 'main_result', null );
foreach( $teams as $team_id ):
if ( ! $team_id ) continue;
$team = get_post( $team_id );
if ( $team ):
$team_results = sportspress_array_value( $results, $team_id, null );
if ( $main_result ):
$team_result = sportspress_array_value( $team_results, $main_result, null );
else:
if ( is_array( $team_results ) ):
end( $team_results );
$team_result = prev( $team_results );
else:
$team_result = null;
endif;
endif;
if ( $team_result != null ):
unset( $team_results['outcome'] );
$team_results = implode( ' | ', $team_results );
echo '<a class="result tips" title="' . $team_results . '" href="' . get_edit_post_link( $post_id ) . '">' . $team_result . '</a> ';
endif;
echo $team->post_title;
echo '<br>';
endif;
endforeach;
endif;
break;
case 'sp_league':
echo get_the_terms ( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : '&mdash;';
break;
case 'sp_season':
echo get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '&mdash;';
break;
case 'sp_venue':
echo get_the_terms ( $post_id, 'sp_venue' ) ? the_terms( $post_id, 'sp_venue' ) : '&mdash;';
break;
case 'sp_views':
echo sportspress_get_post_views( $post_id );
break;
endswitch;
}
/**
* Make columns sortable
*
* https://gist.github.com/906872
*
* @access public
* @param mixed $columns
* @return array
*/
public function custom_columns_sort( $columns ) {
$custom = array(
'sp_views' => 'sp_views',
);
return wp_parse_args( $custom, $columns );
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_player' )
return;
sportspress_highlight_admin_menu();
$selected = isset( $_REQUEST['team'] ) ? $_REQUEST['team'] : null;
$args = array(
'post_type' => 'sp_team',
'name' => 'team',
'show_option_none' => __( 'Show all teams', 'sportspress' ),
'selected' => $selected,
'values' => 'ID',
);
wp_dropdown_pages( $args );
$selected = isset( $_REQUEST['sp_league'] ) ? $_REQUEST['sp_league'] : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected
);
sportspress_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? $_REQUEST['sp_season'] : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sportspress_dropdown_taxonomies( $args );
}
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
if ( $typenow == 'sp_player' ) {
if ( isset( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = $_GET['team'];
$query->query_vars['meta_key'] = 'sp_team';
}
}
}
}
endif;
return new SP_Admin_CPT_Player();

View File

@@ -0,0 +1,157 @@
<?php
/**
* Admin functions for the teams post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post Types
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Admin_CPT' ) )
include( 'class-sp-admin-cpt.php' );
if ( ! class_exists( 'SP_Admin_CPT_Team' ) ) :
/**
* SP_Admin_CPT_Team Class
*/
class SP_Admin_CPT_Team extends SP_Admin_CPT {
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_team';
// Post title fields
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
// Admin Columns
add_filter( 'manage_edit-sp_team_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_team_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
add_filter( 'manage_edit-sp_team_sortable_columns', array( $this, 'custom_columns_sort' ) );
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Check if we're editing or adding a team
* @return boolean
*/
private function is_editing() {
if ( ! empty( $_GET['post_type'] ) && 'sp_team' == $_GET['post_type'] ) {
return true;
}
if ( ! empty( $_GET['post'] ) && 'sp_team' == get_post_type( $_GET['post'] ) ) {
return true;
}
if ( ! empty( $_REQUEST['post_id'] ) && 'sp_team' == get_post_type( $_REQUEST['post_id'] ) ) {
return true;
}
return false;
}
/**
* Change title boxes in admin.
* @param string $text
* @param object $post
* @return string
*/
public function enter_title_here( $text, $post ) {
if ( $post->post_type == 'sp_team' )
return __( 'Name', 'sportspress' );
return $text;
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'sp_icon' => '<span class="dashicons sp-icon-shield tips" title="' . __( 'Logo', 'sportspress' ) . '"></span>',
'title' => __( 'Team', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
'sp_views' => __( 'Views', 'sportspress' ),
);
return $columns;
}
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_league':
echo get_the_terms ( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : '&mdash;';
break;
case 'sp_season':
echo get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : '&mdash;';
break;
case 'sp_views':
echo sportspress_get_post_views( $post_id );
break;
endswitch;
}
/**
* Make columns sortable
*
* https://gist.github.com/906872
*
* @access public
* @param mixed $columns
* @return array
*/
public function custom_columns_sort( $columns ) {
$custom = array(
'sp_views' => 'sp_views',
);
return wp_parse_args( $custom, $columns );
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_team' )
return;
sportspress_highlight_admin_menu();
$selected = isset( $_REQUEST['sp_league'] ) ? $_REQUEST['sp_league'] : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected
);
sportspress_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? $_REQUEST['sp_season'] : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sportspress_dropdown_taxonomies( $args );
}
}
endif;
return new SP_Admin_CPT_Team();

View File

@@ -0,0 +1,73 @@
<?php
/**
* Admin functions for post types
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post Types
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Admin_CPT' ) ) :
/**
* SP_Admin_CPT Class
*/
class SP_Admin_CPT {
protected $type = '';
/**
* Constructor
*/
public function __construct() {
// Insert into X media browser
add_filter( 'media_view_strings', array( $this, 'change_insert_into_post' ) );
add_filter( 'request', array( $this, 'custom_columns_orderby' ) );
}
/**
* Change label for insert buttons.
* @access public
* @param array $strings
* @return array
*/
function change_insert_into_post( $strings ) {
global $post_type;
if ( $post_type == $this->type ) {
$obj = get_post_type_object( $this->type );
$strings['insertIntoPost'] = sprintf( __( 'Insert into %s', 'woocommerce' ), $obj->labels->singular_name );
$strings['uploadedToThisPost'] = sprintf( __( 'Uploaded to this %s', 'woocommerce' ), $obj->labels->singular_name );
}
return $strings;
}
/**
* Custom column orderby
*
* http://scribu.net/wordpress/custom-sortable-columns.html#comment-4732
*
* @access public
* @param mixed $vars
* @return array
*/
public function custom_columns_orderby( $vars ) {
if (isset( $vars['orderby'] )) :
if ( 'sp_views' == $vars['orderby'] ) :
$vars = array_merge( $vars, array(
'meta_key' => 'sp_views',
'orderby' => 'meta_value_num'
) );
endif;
endif;
return $vars;
}
}
endif;

View File

@@ -22,6 +22,7 @@ class SP_Post_types {
public function __construct() {
add_action( 'init', array( __CLASS__, 'register_taxonomies' ), 5 );
add_action( 'init', array( __CLASS__, 'register_post_types' ), 5 );
add_filter( 'the_posts', array( __CLASS__, 'display_scheduled_events' ) );
}
/**
@@ -155,9 +156,59 @@ class SP_Post_types {
*/
public static function register_post_types() {
register_post_type( 'sp_separator',
array(
'label' => '',
'public' => false,
'show_ui' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => false,
'can_export' => false,
)
);
do_action( 'sportspress_register_post_type' );
register_post_type( 'sp_event',
apply_filters( 'sportspress_register_post_type_product',
array(
'label' => __( 'Events', 'sportspress' ),
'labels' => array(
'name' => __( 'Schedule', 'sportspress' ),
'singular_name' => __( 'Event', 'sportspress' ),
'all_items' => __( 'Events', 'sportspress' ),
'add_new_item' => __( 'Add New Event', 'sportspress' ),
'edit_item' => __( 'Edit Event', 'sportspress' ),
'new_item' => __( 'New', 'sportspress' ),
'view_item' => __( 'View', '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_event',
'map_meta_cap' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'hierarchical' => false,
'rewrite' => array( 'slug' => get_option( 'sportspress_events_slug', 'events' ) ),
'query_var' => true,
'supports' => array( 'title', 'author', 'thumbnail', 'comments' ),
'has_archive' => true,
'show_in_nav_menus' => true,
'menu_icon' => 'dashicons-calendar',
)
)
);
}
public function display_scheduled_events( $posts ) {
global $wp_query, $wpdb;
if ( is_single() && $wp_query->post_count == 0 && isset( $wp_query->query_vars['sp_event'] )) {
$posts = $wpdb->get_results( $wp_query->request );
}
return $posts;
}
}

View File

@@ -208,14 +208,14 @@ final class SportsPress {
include_once( 'includes/admin/settings/options-permalink.php' );
// Custom post types (deprecating)
include_once( 'admin/post-types/separator.php' );
//include_once( 'admin/post-types/separator.php' );
include_once( 'admin/post-types/column.php' );
include_once( 'admin/post-types/performance.php' );
//include_once( 'admin/post-types/statistic.php' );
include_once( 'admin/post-types/metric.php' );
include_once( 'admin/post-types/result.php' );
include_once( 'admin/post-types/outcome.php' );
include_once( 'admin/post-types/event.php' );
//include_once( 'admin/post-types/event.php' );
include_once( 'admin/post-types/calendar.php' );
include_once( 'admin/post-types/team.php' );
include_once( 'admin/post-types/table.php' );
@@ -235,13 +235,6 @@ final class SportsPress {
// Post types
include_once( 'includes/class-sp-post-types.php' ); // Registers post types
// Include abstract classes
// include_once( 'includes/abstracts/abstract-sp-product.php' ); // Products
// include_once( 'includes/abstracts/abstract-sp-settings-api.php' ); // Settings API (for gateways, shipping, and integrations)
// include_once( 'includes/abstracts/abstract-sp-shipping-method.php' ); // A Shipping method
// include_once( 'includes/abstracts/abstract-sp-payment-gateway.php' ); // A Payment gateway
// include_once( 'includes/abstracts/abstract-sp-integration.php' ); // An integration with a service
// Classes (used on all pages)
include_once( 'includes/class-sp-countries.php' ); // Defines continents and countries
include_once( 'includes/class-sp-text.php' ); // Defines editable strings
@@ -264,10 +257,10 @@ final class SportsPress {
include_once( 'admin/hooks/current-screen.php' );
// Administrative actions (deprecating)
include_once( 'admin/hooks/manage-posts-columns.php' );
//include_once( 'admin/hooks/manage-posts-columns.php' );
include_once( 'admin/hooks/post-thumbnail-html.php' );
include_once( 'admin/hooks/restrict-manage-posts.php' );
include_once( 'admin/hooks/parse-query.php' );
//include_once( 'admin/hooks/restrict-manage-posts.php' );
//include_once( 'admin/hooks/parse-query.php' );
include_once( 'admin/hooks/save-post.php' );
// Filters (deprecating)