Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions includes/admin/post-types/class-sp-admin-cpt-team-metric.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Admin functions for the columns post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.30
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

if ( ! class_exists( 'SP_Admin_CPT' ) ) {
require 'class-sp-admin-cpt.php';
}

if ( ! class_exists( 'SP_Admin_CPT_Team_Metric' ) ) :

/**
* SP_Admin_CPT_Team_Metric Class
*/
class SP_Admin_CPT_Team_Metric extends SP_Admin_CPT {

/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_team_metric';

// Admin Columns
add_filter( 'manage_edit-sp_team_metric_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_team_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' => esc_attr__( 'Label', 'sportspress' ),
'sp_key' => esc_attr__( 'Variable', 'sportspress' ),
'sp_description' => esc_attr__( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_team_metric_admin_columns', $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 esc_html( $post->post_name );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
}
}

endif;

return new SP_Admin_CPT_Team_Metric();
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Team Metrics Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.30
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

if ( ! class_exists( 'SP_Meta_Box_Config' ) ) {
require 'class-sp-meta-box-config.php';
}

/**
* SP_Meta_Box_Team_Metrics_Details
*/
class SP_Meta_Box_Team_Metrics_Details extends SP_Meta_Box_Config {

/**
* Output the metabox
*/
public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$visible = get_post_meta( $post->ID, 'sp_visible', true );
if ( '' === $visible ) {
$visible = 1;
}
?>
<p><strong><?php esc_attr_e( 'Variable', 'sportspress' ); ?></strong></p>
<p>
<input name="sp_default_key" type="hidden" id="sp_default_key" value="<?php echo esc_attr( $post->post_name ); ?>">
<input name="sp_key" type="text" id="sp_key" value="<?php echo esc_attr( $post->post_name ); ?>">
</p>
<p>
<strong><?php esc_attr_e( 'Visible', 'sportspress' ); ?></strong>
<i class="dashicons dashicons-editor-help sp-desc-tip" title="<?php esc_attr_e( 'Display in team pages?', 'sportspress' ); ?>"></i>
</p>
<ul class="sp-visible-selector">
<li>
<label class="selectit">
<input name="sp_visible" id="sp_visible_yes" type="radio" value="1" <?php checked( $visible ); ?>>
<?php esc_attr_e( 'Yes', 'sportspress' ); ?>
</label>
</li>
<li>
<label class="selectit">
<input name="sp_visible" id="sp_visible_no" type="radio" value="0" <?php checked( ! $visible ); ?>>
<?php esc_attr_e( 'No', 'sportspress' ); ?>
</label>
</li>
</ul>
<?php
}

/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
self::delete_duplicate( $_POST );
update_post_meta( $post_id, 'sp_visible', sp_array_value( $_POST, 'sp_visible', 1, 'int' ) );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Team Metrics
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.30
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

/**
* SP_Meta_Box_Team_Metrics
*/
class SP_Meta_Box_Team_Metrics {

/**
* Output the metabox
*/
public static function output( $post ) {

$metrics = get_post_meta( $post->ID, 'sp_team_metrics', true );

$args = array(
'post_type' => 'sp_team_metric',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
);

$vars = get_posts( $args );

if ( $vars ) :
foreach ( $vars as $var ) :
?>
<p><strong><?php echo esc_html( $var->post_title ); ?></strong></p>
<p><input type="text" name="sp_team_metrics[<?php echo esc_attr( $var->post_name ); ?>]" value="<?php echo esc_attr( sp_array_value( $metrics, $var->post_name, '' ) ); ?>" /></p>
<?php
endforeach;
else :
sp_post_adder( 'sp_team_metric', esc_attr__( 'Add New', 'sportspress' ) );
endif;
}

/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_team_metrics', sp_array_value( $_POST, 'sp_team_metrics', array(), 'text' ) );
}
}
Loading