Create CPT classes for config post types

This commit is contained in:
Brian Miyaji
2014-03-26 02:22:47 +11:00
parent a01e11ab71
commit 7b80f687f2
16 changed files with 555 additions and 127 deletions

View File

@@ -30,6 +30,12 @@ class SP_Admin_Post_Types {
*/
public function include_post_type_handlers() {
//include( 'post-types/class-sp-admin-meta-boxes.php' );
include( 'post-types/class-sp-admin-cpt-result.php' );
include( 'post-types/class-sp-admin-cpt-outcome.php' );
include( 'post-types/class-sp-admin-cpt-performance.php' );
include( 'post-types/class-sp-admin-cpt-column.php' );
include( 'post-types/class-sp-admin-cpt-metric.php' );
//include( 'post-types/class-sp-admin-cpt-statistic.php' );
include( 'post-types/class-sp-admin-cpt-event.php' );
include( 'post-types/class-sp-admin-cpt-calendar.php' );
include( 'post-types/class-sp-admin-cpt-team.php' );

View File

@@ -39,23 +39,6 @@ class SP_Admin_CPT_Calendar extends SP_Admin_CPT {
parent::__construct();
}
/**
* Check if we're editing or adding an event
* @return boolean
*/
private function is_editing() {
if ( ! empty( $_GET['post_type'] ) && 'sp_calendar' == $_GET['post_type'] ) {
return true;
}
if ( ! empty( $_GET['post'] ) && 'sp_calendar' == get_post_type( $_GET['post'] ) ) {
return true;
}
if ( ! empty( $_REQUEST['post_id'] ) && 'sp_calendar' == get_post_type( $_REQUEST['post_id'] ) ) {
return true;
}
return false;
}
/**
* Change the columns shown in admin.
*/

View File

@@ -0,0 +1,77 @@
<?php
/**
* Admin functions for the columns 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_Column' ) ) :
/**
* SP_Admin_CPT_Column Class
*/
class SP_Admin_CPT_Column extends SP_Admin_CPT {
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_column';
// Admin Columns
add_filter( 'manage_edit-sp_column_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_column_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Key', 'sportspress' ),
'sp_equation' => __( 'Equation', 'sportspress' ),
'sp_precision' => __( 'Rounding', 'sportspress' ),
'sp_order' => __( 'Sort Order', 'sportspress' ),
);
return $columns;
}
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_key':
global $post;
echo $post->post_name;
break;
case 'sp_equation':
echo sportspress_get_post_equation( $post_id );
break;
case 'sp_precision':
echo sportspress_get_post_precision( $post_id );
break;
case 'sp_order':
echo sportspress_get_post_order( $post_id );
break;
endswitch;
}
}
endif;
return new SP_Admin_CPT_Column();

View File

@@ -45,23 +45,6 @@ class SP_Admin_CPT_Event extends SP_Admin_CPT {
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

View File

@@ -39,23 +39,6 @@ class SP_Admin_CPT_List extends SP_Admin_CPT {
parent::__construct();
}
/**
* Check if we're editing or adding an event
* @return boolean
*/
private function is_editing() {
if ( ! empty( $_GET['post_type'] ) && 'sp_list' == $_GET['post_type'] ) {
return true;
}
if ( ! empty( $_GET['post'] ) && 'sp_list' == get_post_type( $_GET['post'] ) ) {
return true;
}
if ( ! empty( $_REQUEST['post_id'] ) && 'sp_list' == get_post_type( $_REQUEST['post_id'] ) ) {
return true;
}
return false;
}
/**
* Change the columns shown in admin.
*/

View File

@@ -0,0 +1,64 @@
<?php
/**
* Admin functions for the columns 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_Metric' ) ) :
/**
* SP_Admin_CPT_Metric Class
*/
class SP_Admin_CPT_Metric extends SP_Admin_CPT {
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_metric';
// Admin Columns
add_filter( 'manage_edit-sp_metric_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_metric_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_position' => __( 'Positions', '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;
endswitch;
}
}
endif;
return new SP_Admin_CPT_Metric();

View File

@@ -0,0 +1,65 @@
<?php
/**
* Admin functions for the outcomes 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_Outcome' ) ) :
/**
* SP_Admin_CPT_Outcome Class
*/
class SP_Admin_CPT_Outcome extends SP_Admin_CPT {
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_outcome';
// Admin Columns
add_filter( 'manage_edit-sp_outcome_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_outcome_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Key', 'sportspress' ),
);
return $columns;
}
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_key':
global $post;
echo $post->post_name;
break;
endswitch;
}
}
endif;
return new SP_Admin_CPT_Outcome();

View File

@@ -0,0 +1,73 @@
<?php
/**
* Admin functions for the performance 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_Performance' ) ) :
/**
* SP_Admin_CPT_Performance Class
*/
class SP_Admin_CPT_Performance extends SP_Admin_CPT {
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_performance';
// Admin Columns
add_filter( 'manage_edit-sp_performance_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_performance_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Key', 'sportspress' ),
'sp_position' => __( 'Positions', 'sportspress' ),
'sp_calculate' => __( 'Calculate', 'sportspress' ),
);
return $columns;
}
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_key':
global $post;
echo $post->post_name;
break;
case 'sp_position':
echo get_the_terms( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : '&mdash;';
break;
case 'sp_calculate':
echo sportspress_get_post_calculate( $post_id );
break;
endswitch;
}
}
endif;
return new SP_Admin_CPT_Performance();

View File

@@ -42,23 +42,6 @@ class SP_Admin_CPT_Player extends SP_Admin_CPT {
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

View File

@@ -0,0 +1,65 @@
<?php
/**
* Admin functions for the results 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_Result' ) ) :
/**
* SP_Admin_CPT_Result Class
*/
class SP_Admin_CPT_Result extends SP_Admin_CPT {
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_result';
// Admin Columns
add_filter( 'manage_edit-sp_result_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_result_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Key', 'sportspress' ),
);
return $columns;
}
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_key':
global $post;
echo $post->post_name;
break;
endswitch;
}
}
endif;
return new SP_Admin_CPT_Result();

View File

@@ -42,23 +42,6 @@ class SP_Admin_CPT_Staff extends SP_Admin_CPT {
parent::__construct();
}
/**
* Check if we're editing or adding an event
* @return boolean
*/
private function is_editing() {
if ( ! empty( $_GET['post_type'] ) && 'sp_staff' == $_GET['post_type'] ) {
return true;
}
if ( ! empty( $_GET['post'] ) && 'sp_staff' == get_post_type( $_GET['post'] ) ) {
return true;
}
if ( ! empty( $_REQUEST['post_id'] ) && 'sp_staff' == get_post_type( $_REQUEST['post_id'] ) ) {
return true;
}
return false;
}
/**
* Change title boxes in admin.
* @param string $text

View File

@@ -39,23 +39,6 @@ class SP_Admin_CPT_Table extends SP_Admin_CPT {
parent::__construct();
}
/**
* Check if we're editing or adding an event
* @return boolean
*/
private function is_editing() {
if ( ! empty( $_GET['post_type'] ) && 'sp_table' == $_GET['post_type'] ) {
return true;
}
if ( ! empty( $_GET['post'] ) && 'sp_table' == get_post_type( $_GET['post'] ) ) {
return true;
}
if ( ! empty( $_REQUEST['post_id'] ) && 'sp_table' == get_post_type( $_REQUEST['post_id'] ) ) {
return true;
}
return false;
}
/**
* Change the columns shown in admin.
*/

View File

@@ -41,23 +41,6 @@ class SP_Admin_CPT_Team extends SP_Admin_CPT {
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

View File

@@ -40,13 +40,30 @@ class SP_Admin_CPT {
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 );
$strings['insertIntoPost'] = sprintf( __( 'Insert into %s', 'sportspress' ), $obj->labels->singular_name );
$strings['uploadedToThisPost'] = sprintf( __( 'Uploaded to this %s', 'sportspress' ), $obj->labels->singular_name );
}
return $strings;
}
/**
* Check if we're editing or adding an event
* @return boolean
*/
private function is_editing() {
if ( ! empty( $_GET['post_type'] ) && $this->type == $_GET['post_type'] ) {
return true;
}
if ( ! empty( $_GET['post'] ) && $this->type == get_post_type( $_GET['post'] ) ) {
return true;
}
if ( ! empty( $_REQUEST['post_id'] ) && $this->type == get_post_type( $_REQUEST['post_id'] ) ) {
return true;
}
return false;
}
/**
* Custom column orderby
*

View File

@@ -169,6 +169,186 @@ class SP_Post_types {
do_action( 'sportspress_register_post_type' );
register_post_type( 'sp_result',
apply_filters( 'sportspress_register_post_type_result',
array(
'labels' => array(
'name' => __( 'Results', 'sportspress' ),
'singular_name' => __( 'Result', 'sportspress' ),
'add_new_item' => __( 'Add New Result', 'sportspress' ),
'edit_item' => __( 'Edit Result', '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' => false,
'show_ui' => true,
'capability_type' => 'sp_config',
'map_meta_cap' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'hierarchical' => false,
'supports' => array( 'title', 'page-attributes' ),
'has_archive' => false,
'show_in_menu' => false,
'show_in_nav_menus' => false,
'can_export' => false,
)
)
);
register_post_type( 'sp_outcome',
apply_filters( 'sportspress_register_post_type_outcome',
array(
'labels' => array(
'name' => __( 'Outcomes', 'sportspress' ),
'singular_name' => __( 'Outcome', 'sportspress' ),
'add_new_item' => __( 'Add New Outcome', 'sportspress' ),
'edit_item' => __( 'Edit Outcome', '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' => false,
'show_ui' => true,
'capability_type' => 'sp_config',
'map_meta_cap' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'hierarchical' => false,
'supports' => array( 'title', 'page-attributes' ),
'has_archive' => false,
'show_in_menu' => false,
'show_in_nav_menus' => false,
'can_export' => false,
)
)
);
register_post_type( 'sp_performance',
apply_filters( 'sportspress_register_post_type_performance',
array(
'labels' => array(
'name' => __( 'Performance', 'sportspress' ),
'singular_name' => __( 'Performance', 'sportspress' ),
'add_new_item' => __( 'Add New Performance', 'sportspress' ),
'edit_item' => __( 'Edit Performance', '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' => false,
'show_ui' => true,
'capability_type' => 'sp_config',
'map_meta_cap' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'hierarchical' => false,
'supports' => array( 'title', 'page-attributes' ),
'has_archive' => false,
'show_in_menu' => false,
'show_in_nav_menus' => false,
'can_export' => false,
)
)
);
register_post_type( 'sp_column',
apply_filters( 'sportspress_register_post_type_column',
array(
'labels' => array(
'name' => __( 'Columns', 'sportspress' ),
'singular_name' => __( 'Column', 'sportspress' ),
'add_new_item' => __( 'Add New Column', 'sportspress' ),
'edit_item' => __( 'Edit Column', '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' => false,
'show_ui' => true,
'capability_type' => 'sp_config',
'map_meta_cap' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'hierarchical' => false,
'supports' => array( 'title', 'page-attributes' ),
'has_archive' => false,
'show_in_menu' => false,
'show_in_nav_menus' => false,
'can_export' => false,
)
)
);
register_post_type( 'sp_metric',
apply_filters( 'sportspress_register_post_type_metric',
array(
'labels' => array(
'name' => __( 'Metrics', 'sportspress' ),
'singular_name' => __( 'Metric', 'sportspress' ),
'add_new_item' => __( 'Add New Metric', 'sportspress' ),
'edit_item' => __( 'Edit Metric', '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' => false,
'show_ui' => true,
'capability_type' => 'sp_config',
'map_meta_cap' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'hierarchical' => false,
'supports' => array( 'title', 'page-attributes' ),
'has_archive' => false,
'show_in_menu' => false,
'show_in_nav_menus' => false,
'can_export' => false,
)
)
);
register_post_type( 'sp_statistic',
apply_filters( 'sportspress_register_post_type_statistic',
array(
'labels' => array(
'name' => __( 'Statistics', 'sportspress' ),
'singular_name' => __( 'Statistic', 'sportspress' ),
'add_new_item' => __( 'Add New Statistic', 'sportspress' ),
'edit_item' => __( 'Edit Statistic', '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' => false,
'show_ui' => true,
'capability_type' => 'sp_config',
'map_meta_cap' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'hierarchical' => false,
'supports' => array( 'title', 'page-attributes' ),
'has_archive' => false,
'show_in_menu' => false,
'show_in_nav_menus' => false,
'can_export' => false,
)
)
);
register_post_type( 'sp_event',
apply_filters( 'sportspress_register_post_type_event',
array(

View File

@@ -209,12 +209,12 @@ final class SportsPress {
// Custom post types (deprecating)
//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/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/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/calendar.php' );
//include_once( 'admin/post-types/team.php' );
@@ -296,7 +296,7 @@ final class SportsPress {
* Include core widgets
*/
public function include_widgets() {
//include_once( 'includes/abstracts/abstract-wc-widget.php' );
//include_once( 'includes/abstracts/abstract-sp-widget.php' );
include_once( 'includes/widgets/class-sp-widget-countdown.php' );
include_once( 'includes/widgets/class-sp-widget-event-calendar.php' );
include_once( 'includes/widgets/class-sp-widget-event-list.php' );