Clean up spaces, tabs, indentation, and bracket formatting

This commit is contained in:
Brian Miyaji
2021-11-10 15:41:40 +09:00
parent e58beb1201
commit 3dff686a00
285 changed files with 29638 additions and 24147 deletions

View File

@@ -4,11 +4,11 @@
*
* The SportsPress custom post class handles individual post data.
*
* @class SP_Custom_Post
* @version 2.6.5
* @package SportsPress/Abstracts
* @category Abstract Class
* @author ThemeBoy
* @class SP_Custom_Post
* @version 2.6.5
* @package SportsPress/Abstracts
* @category Abstract Class
* @author ThemeBoy
*/
abstract class SP_Custom_Post {
@@ -25,11 +25,11 @@ abstract class SP_Custom_Post {
* @param mixed $post
*/
public function __construct( $post ) {
if ( $post instanceof WP_Post || $post instanceof SP_Custom_Post ):
if ( $post instanceof WP_Post || $post instanceof SP_Custom_Post ) :
$this->ID = absint( $post->ID );
$this->post = $post;
else:
$this->ID = absint( $post );
else :
$this->ID = absint( $post );
$this->post = get_post( $this->ID );
endif;
}
@@ -53,9 +53,9 @@ abstract class SP_Custom_Post {
* @return bool
*/
public function __get( $key ) {
if ( ! isset( $key ) ):
if ( ! isset( $key ) ) :
return $this->post;
else:
else :
$value = get_post_meta( $this->ID, 'sp_' . $key, true );
endif;
@@ -77,7 +77,7 @@ abstract class SP_Custom_Post {
*
* @access public
* @param string $taxonomy The taxonomy.
* @return array|false|WP_Error See `get_the_terms()`
* @return array|false|WP_Error See `get_the_terms()`
*/
public function get_terms_sorted_by_sp_order( $taxonomy ) {
$terms = get_the_terms( $this->ID, $taxonomy );

View File

@@ -4,70 +4,70 @@
*
* The SportsPress secondary post class extends custom posts with handling of secondary post types.
*
* @class SP_Secondary_Post
* @class SP_Secondary_Post
* @version 2.5.3
* @package SportsPress/Abstracts
* @category Abstract Class
* @author ThemeBoy
* @package SportsPress/Abstracts
* @category Abstract Class
* @author ThemeBoy
*/
abstract class SP_Secondary_Post extends SP_Custom_Post {
/** @var string The date filter for events. */
public $date = 0;
/** @var string The date filter for events. */
public $date = 0;
/** @var string The date to range from. */
public $from = 'now';
/** @var string The date to range from. */
public $from = 'now';
/** @var string The date to range to. */
public $to = 'now';
/** @var string The date to range to. */
public $to = 'now';
/** @var string The number of days to query in the past. */
public $past = 0;
/** @var string The number of days to query in the past. */
public $past = 0;
/** @var string The number of days to query in the future. */
public $future = 0;
/** @var string The number of days to query in the future. */
public $future = 0;
/** @var boolean Determines whether the date range is relative. */
public $relative = false;
/** @var boolean Determines whether the date range is relative. */
public $relative = false;
/**
* __construct function.
*
* @access public
* @param mixed $post
*/
public function __construct( $post ) {
if ( $post instanceof WP_Post || $post instanceof SP_Secondary_Post ):
$this->ID = absint( $post->ID );
$this->post = $post;
else:
$this->ID = absint( $post );
$this->post = get_post( $this->ID );
endif;
}
/**
* __construct function.
*
* @access public
* @param mixed $post
*/
public function __construct( $post ) {
if ( $post instanceof WP_Post || $post instanceof SP_Secondary_Post ) :
$this->ID = absint( $post->ID );
$this->post = $post;
else :
$this->ID = absint( $post );
$this->post = get_post( $this->ID );
endif;
}
public function range( $where = '', $format = 'Y-m-d' ) {
$from = new DateTime( $this->from );
$to = new DateTime( $this->to );
public function range( $where = '', $format = 'Y-m-d' ) {
$from = new DateTime( $this->from );
$to = new DateTime( $this->to );
$to->modify( '+1 day' );
$to->modify( '+1 day' );
$where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'";
$where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'";
return $where;
}
return $where;
}
public function relative( $where = '', $format = 'Y-m-d' ) {
$from = new DateTime( 'now' );
$to = new DateTime( 'now' );
public function relative( $where = '', $format = 'Y-m-d' ) {
$from = new DateTime( 'now' );
$to = new DateTime( 'now' );
$from->modify( '-' . abs( (int) $this->past ) . ' day' );
$to->modify( '+' . abs( (int) $this->future ) . ' day' );
$from->modify( '-' . abs( (int) $this->past ) . ' day' );
$to->modify( '+' . abs( (int) $this->future ) . ' day' );
$to->modify( '+1 day' );
$to->modify( '+1 day' );
$where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'";
$where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'";
return $where;
}
return $where;
}
}

View File

@@ -6,10 +6,10 @@ if ( ! defined( 'ABSPATH' ) ) {
/**
* SportsPress Admin.
*
* @class SP_Admin_AJAX
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @class SP_Admin_AJAX
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 1.7
*/
class SP_Admin_AJAX {
@@ -59,10 +59,10 @@ class SP_Admin_AJAX {
function save_inline_results() {
check_ajax_referer( 'sp-save-inline-results', 'nonce' );
$id = sp_array_value( $_POST, 'post_id' );
$id = sp_array_value( $_POST, 'post_id' );
$results = sp_array_value( $_POST, 'results' );
if ( sp_update_main_results ( $id, $results ) ) {
if ( sp_update_main_results( $id, $results ) ) {
wp_send_json_success();
} else {
wp_send_json_error();

View File

@@ -2,144 +2,149 @@
/**
* Load assets.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.6.15
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_Assets' ) ) :
/**
* SP_Admin_Assets Class
*/
class SP_Admin_Assets {
/**
* Hook in tabs.
* SP_Admin_Assets Class
*/
public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
}
class SP_Admin_Assets {
/**
* Enqueue styles
*/
public function admin_styles( $hook ) {
// Sitewide menu CSS
wp_enqueue_style( 'sportspress-admin-menu-styles', SP()->plugin_url() . '/assets/css/menu.css', array(), SP_VERSION );
$screen = get_current_screen();
if ( in_array( $screen->id, sp_get_screen_ids() ) ) {
// Admin styles for SP pages only
wp_enqueue_style( 'jquery-chosen', SP()->plugin_url() . '/assets/css/chosen.css', array(), '1.1.0' );
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . '/assets/css/admin.css', array(), SP_VERSION );
} elseif ( strpos( $screen->id, 'sportspress-config' ) !== false ) {
wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . '/assets/css/admin.css', array(), SP_VERSION );
/**
* Hook in tabs.
*/
public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
}
if ( strpos( $screen->id, 'sportspress-overview' ) !== false ) {
wp_enqueue_style( 'sportspress-admin-slickmap', SP()->plugin_url() . '/assets/css/slickmap.css', array(), '1.1.0' );
/**
* Enqueue styles
*/
public function admin_styles( $hook ) {
// Sitewide menu CSS
wp_enqueue_style( 'sportspress-admin-menu-styles', SP()->plugin_url() . '/assets/css/menu.css', array(), SP_VERSION );
$screen = get_current_screen();
if ( in_array( $screen->id, sp_get_screen_ids() ) ) {
// Admin styles for SP pages only
wp_enqueue_style( 'jquery-chosen', SP()->plugin_url() . '/assets/css/chosen.css', array(), '1.1.0' );
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . '/assets/css/admin.css', array(), SP_VERSION );
} elseif ( strpos( $screen->id, 'sportspress-config' ) !== false ) {
wp_enqueue_style( 'sportspress-admin', SP()->plugin_url() . '/assets/css/admin.css', array(), SP_VERSION );
}
if ( strpos( $screen->id, 'sportspress-overview' ) !== false ) {
wp_enqueue_style( 'sportspress-admin-slickmap', SP()->plugin_url() . '/assets/css/slickmap.css', array(), '1.1.0' );
}
if ( in_array( $screen->id, array( 'dashboard' ) ) ) {
wp_enqueue_style( 'sportspress-admin-dashboard-styles', SP()->plugin_url() . '/assets/css/dashboard.css', array(), SP_VERSION );
}
if ( in_array( $screen->id, array( 'customize' ) ) ) {
wp_enqueue_style( 'sportspress-admin-customize-styles', SP()->plugin_url() . '/assets/css/customize.css', array(), SP_VERSION );
}
if ( in_array( $screen->id, array( 'sp_result', 'sp_performance', 'sp_column', 'sp_statistic' ) ) ) {
wp_enqueue_style( 'sportspress-admin-equation-styles', SP()->plugin_url() . '/assets/css/equation.css', array(), SP_VERSION );
}
if ( in_array( $screen->id, apply_filters( 'sportspress_admin_datepicker_screen_ids', array( 'sp_calendar', 'sp_table', 'sp_list', 'widgets' ) ) ) || in_array( $hook, array( 'post.php', 'post-new.php' ) ) ) {
wp_enqueue_style( 'jquery-ui-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css' );
wp_enqueue_style( 'sportspress-admin-datepicker-styles', SP()->plugin_url() . '/assets/css/datepicker.css', array( 'jquery-ui-style' ), SP_VERSION );
}
do_action( 'sportspress_admin_css', $screen );
}
if ( in_array( $screen->id, array( 'dashboard' ) ) ) {
wp_enqueue_style( 'sportspress-admin-dashboard-styles', SP()->plugin_url() . '/assets/css/dashboard.css', array(), SP_VERSION );
}
/**
* Enqueue scripts
*/
public function admin_scripts( $hook ) {
global $wp_query, $post;
if ( in_array( $screen->id, array( 'customize' ) ) ) {
wp_enqueue_style( 'sportspress-admin-customize-styles', SP()->plugin_url() . '/assets/css/customize.css', array(), SP_VERSION );
}
$screen = get_current_screen();
if ( in_array( $screen->id, array( 'sp_result', 'sp_performance', 'sp_column', 'sp_statistic' ) ) ) {
wp_enqueue_style( 'sportspress-admin-equation-styles', SP()->plugin_url() . '/assets/css/equation.css', array(), SP_VERSION );
}
// Register scripts
wp_register_script( 'chosen', SP()->plugin_url() . '/assets/js/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true );
if ( in_array( $screen->id, apply_filters( 'sportspress_admin_datepicker_screen_ids', array( 'sp_calendar', 'sp_table', 'sp_list', 'widgets' ) ) ) || in_array( $hook, array('post.php', 'post-new.php') ) ) {
wp_enqueue_style( 'jquery-ui-style' , '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css' );
wp_enqueue_style( 'sportspress-admin-datepicker-styles', SP()->plugin_url() . '/assets/css/datepicker.css', array( 'jquery-ui-style' ), SP_VERSION );
}
wp_register_script( 'jquery-tiptip', SP()->plugin_url() . '/assets/js/jquery.tipTip.min.js', array( 'jquery' ), '1.3', true );
do_action( 'sportspress_admin_css', $screen );
}
wp_register_script( 'jquery-caret', SP()->plugin_url() . '/assets/js/jquery.caret.min.js', array( 'jquery' ), '1.02', true );
/**
* Enqueue scripts
*/
public function admin_scripts($hook) {
global $wp_query, $post;
wp_register_script( 'jquery-fitvids', SP()->plugin_url() . '/assets/js/jquery.fitvids.js', array( 'jquery' ), '1.1', true );
$screen = get_current_screen();
wp_register_script( 'sportspress-admin-equationbuilder', SP()->plugin_url() . '/assets/js/admin/equationbuilder.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable' ), SP_VERSION, true );
// Register scripts
wp_register_script( 'chosen', SP()->plugin_url() . '/assets/js/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true );
wp_register_script( 'sportspress-admin-colorpicker', SP()->plugin_url() . '/assets/js/admin/colorpicker.js', array( 'jquery', 'wp-color-picker', 'iris' ), SP_VERSION, true );
wp_register_script( 'jquery-tiptip', SP()->plugin_url() . '/assets/js/jquery.tipTip.min.js', array( 'jquery' ), '1.3', true );
wp_register_script( 'sportspress-admin-widgets', SP()->plugin_url() . '/assets/js/admin/widgets.js', array( 'jquery' ), SP_VERSION, true );
wp_register_script( 'jquery-caret', SP()->plugin_url() . '/assets/js/jquery.caret.min.js', array( 'jquery' ), '1.02', true );
wp_register_script( 'sportspress-admin-quickeditor', SP()->plugin_url() . '/assets/js/admin/quickeditor.js', array( 'jquery' ), SP_VERSION, true );
wp_register_script( 'jquery-fitvids', SP()->plugin_url() . '/assets/js/jquery.fitvids.js', array( 'jquery' ), '1.1', true );
// SportsPress admin pages
if ( in_array( $screen->id, sp_get_screen_ids() ) || strpos( $screen->id, 'sportspress-config' ) || in_array( $hook, array( 'post.php', 'post-new.php' ) ) ) {
wp_register_script( 'sportspress-admin-equationbuilder', SP()->plugin_url() . '/assets/js/admin/equationbuilder.js', array( 'jquery', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable' ), SP_VERSION, true );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'chosen' );
wp_enqueue_script( 'jquery-ui-core' );
wp_enqueue_script( 'jquery-ui-draggable' );
wp_enqueue_script( 'jquery-ui-droppable' );
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_script( 'jquery-tiptip' );
wp_enqueue_script( 'jquery-caret' );
wp_enqueue_script( 'jquery-fitvids' );
wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret', 'jquery-fitvids' ), SP_VERSION, true );
wp_register_script( 'sportspress-admin-colorpicker', SP()->plugin_url() . '/assets/js/admin/colorpicker.js', array( 'jquery', 'wp-color-picker', 'iris' ), SP_VERSION, true );
$strings = apply_filters(
'sportspress_localized_strings',
array(
'none' => __( 'None', 'sportspress' ),
'remove_text' => __( '— Remove —', 'sportspress' ),
'days' => __( 'days', 'sportspress' ),
'hrs' => __( 'hrs', 'sportspress' ),
'mins' => __( 'mins', 'sportspress' ),
'secs' => __( 'secs', 'sportspress' ),
'displaying_posts' => html_entity_decode( __( 'Displaying %1$s–%2$s of %3$s', 'sportspress' ) ),
)
);
wp_register_script( 'sportspress-admin-widgets', SP()->plugin_url() . '/assets/js/admin/widgets.js', array( 'jquery' ), SP_VERSION, true );
// Localize scripts
wp_localize_script( 'sportspress-admin', 'localized_strings', $strings );
}
wp_register_script( 'sportspress-admin-quickeditor', SP()->plugin_url() . '/assets/js/admin/quickeditor.js', array( 'jquery' ), SP_VERSION, true );
if ( in_array( $screen->id, array( 'widgets' ) ) ) {
wp_enqueue_script( 'sportspress-admin-widgets' );
}
// SportsPress admin pages
if ( in_array( $screen->id, sp_get_screen_ids() ) || strpos( $screen->id, 'sportspress-config' ) || in_array($hook, array('post.php', 'post-new.php') ) ) {
// Edit color
if ( in_array( $screen->id, array( 'sp_outcome' ) ) ) {
wp_enqueue_script( 'sportspress-admin-colorpicker' );
}
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'chosen' );
wp_enqueue_script( 'jquery-ui-core' );
wp_enqueue_script( 'jquery-ui-draggable' );
wp_enqueue_script( 'jquery-ui-droppable' );
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_script( 'jquery-tiptip' );
wp_enqueue_script( 'jquery-caret' );
wp_enqueue_script( 'jquery-fitvids' );
wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret', 'jquery-fitvids' ), SP_VERSION, true );
$strings = apply_filters( 'sportspress_localized_strings', array(
'none' => __( 'None', 'sportspress' ),
'remove_text' => __( '— Remove —', 'sportspress' ),
'days' => __( 'days', 'sportspress' ),
'hrs' => __( 'hrs', 'sportspress' ),
'mins' => __( 'mins', 'sportspress' ),
'secs' => __( 'secs', 'sportspress' ),
'displaying_posts' => html_entity_decode( __( 'Displaying %s–%s of %s', 'sportspress' ) ),
) );
// Edit equation
if ( in_array( $screen->id, array( 'sp_result', 'sp_performance', 'sp_column', 'sp_statistic' ) ) ) {
wp_enqueue_script( 'sportspress-admin-equationbuilder' );
}
// Localize scripts
wp_localize_script( 'sportspress-admin', 'localized_strings', $strings );
}
if ( in_array( $screen->id, array( 'widgets' ) ) ) {
wp_enqueue_script( 'sportspress-admin-widgets' );
}
// Edit color
if ( in_array( $screen->id, array( 'sp_outcome' ) ) ) {
wp_enqueue_script( 'sportspress-admin-colorpicker' );
}
// Edit equation
if ( in_array( $screen->id, array( 'sp_result', 'sp_performance', 'sp_column', 'sp_statistic' ) ) ) {
wp_enqueue_script( 'sportspress-admin-equationbuilder' );
}
// Quick edit
if ( in_array( $screen->id, array( 'edit-sp_player' ) ) ) {
wp_enqueue_script( 'sportspress-admin-quickeditor' );
// Quick edit
if ( in_array( $screen->id, array( 'edit-sp_player' ) ) ) {
wp_enqueue_script( 'sportspress-admin-quickeditor' );
}
}
}
}
endif;

View File

@@ -2,126 +2,130 @@
/**
* Admin Dashboard
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_Dashboard' ) ) :
/**
* SP_Admin_Dashboard Class
*/
class SP_Admin_Dashboard {
/**
* SP_Admin_Dashboard Class
*/
class SP_Admin_Dashboard {
/**
* Hook in tabs.
*/
public function __construct() {
// Only hook in admin parts if the user has admin access
if ( current_user_can( 'view_sportspress_reports' ) || current_user_can( 'manage_sportspress' ) || current_user_can( 'publish_sp_events' ) ) {
add_action( 'wp_dashboard_setup', array( $this, 'init' ) );
}
}
/**
* Hook in tabs.
*/
public function __construct() {
// Only hook in admin parts if the user has admin access
if ( current_user_can( 'view_sportspress_reports' ) || current_user_can( 'manage_sportspress' ) || current_user_can( 'publish_sp_events' ) ) {
add_action( 'wp_dashboard_setup', array( $this, 'init' ) );
}
}
/**
* Init dashboard widgets
*/
public function init() {
//wp_add_dashboard_widget( 'sportspress_dashboard_news', __( 'Sports News', 'sportspress' ), array( $this, 'news_widget' ), null, null, 'side' );
wp_add_dashboard_widget( 'sportspress_dashboard_status', __( 'SportsPress', 'sportspress' ), array( $this, 'status_widget' ) );
add_filter( 'dashboard_glance_items', array( $this, 'glance_items' ), 10, 1 );
}
/**
* Init dashboard widgets
*/
public function init() {
// wp_add_dashboard_widget( 'sportspress_dashboard_news', __( 'Sports News', 'sportspress' ), array( $this, 'news_widget' ), null, null, 'side' );
wp_add_dashboard_widget( 'sportspress_dashboard_status', __( 'SportsPress', 'sportspress' ), array( $this, 'status_widget' ) );
add_filter( 'dashboard_glance_items', array( $this, 'glance_items' ), 10, 1 );
}
/**
* Add links to At a Glance
*/
function glance_items( $items = array() ) {
$post_types = apply_filters( 'sportspress_glance_items', array( 'sp_event', 'sp_team', 'sp_player', 'sp_staff' ) );
foreach ( $post_types as $type ):
if ( ! post_type_exists( $type ) ) continue;
$num_posts = wp_count_posts( $type );
if ( $num_posts ):
$published = intval( $num_posts->publish );
$post_type = get_post_type_object( $type );
$text = _n( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $published, 'sportspress' );
$text = sprintf( $text, number_format_i18n( $published ) );
if ( current_user_can( $post_type->cap->edit_posts ) ):
$output = '<a href="edit.php?post_type=' . $post_type->name . '">' . $text . '</a>';
else:
$output = '<span>' . $text . '</span>';
endif;
echo '<li class="post-count ' . eac_attr( $post_type->name ) . '-count">' . esc_html( $output ) . '</li>';
endif;
endforeach;
return $items;
}
/**
* Add links to At a Glance
*/
function glance_items( $items = array() ) {
$post_types = apply_filters( 'sportspress_glance_items', array( 'sp_event', 'sp_team', 'sp_player', 'sp_staff' ) );
foreach ( $post_types as $type ) :
if ( ! post_type_exists( $type ) ) {
continue;
}
$num_posts = wp_count_posts( $type );
if ( $num_posts ) :
$published = intval( $num_posts->publish );
$post_type = get_post_type_object( $type );
$text = _n( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $published, 'sportspress' );
$text = sprintf( $text, number_format_i18n( $published ) );
if ( current_user_can( $post_type->cap->edit_posts ) ) :
$output = '<a href="edit.php?post_type=' . $post_type->name . '">' . $text . '</a>';
else :
$output = '<span>' . $text . '</span>';
endif;
echo '<li class="post-count ' . eac_attr( $post_type->name ) . '-count">' . esc_html( $output ) . '</li>';
endif;
endforeach;
return $items;
}
/**
* Show status widget
*/
public function status_widget() {
?>
<ul class="sp_status_list">
<?php
$count = wp_count_posts( 'sp_event' );
$scheduled_count = isset( $count->future ) ? $count->future : 0;
$published_count = isset( $count->publish ) ? $count->publish : 0;
$next_event = sp_get_next_event();
if ( $next_event ):
$now = new DateTime( current_time( 'mysql', 0 ) );
$date = new DateTime( $next_event->post_date );
$interval = date_diff( $now, $date );
?>
<li class="countdown" data-countdown="<?php echo str_replace( '-', '/', get_gmt_from_date( $next_event->post_date ) ); ?>">
<a href="<?php echo get_edit_post_link( $next_event->ID ); ?>">
<?php printf( __( '<strong>%s</strong> until next event', 'sportspress' ), $interval->days . ' ' . __( 'days', 'sportspress' ) . ' ' . sprintf( '%02s:%02s:%02s', $interval->h, $interval->i, $interval->s ) ); ?>
(<?php echo esc_html( $next_event->post_title ); ?>)
</a>
</li>
<?php endif; ?>
<li class="events-scheduled">
<a href="<?php echo admin_url( 'edit.php?post_type=sp_event&post_status=future' ); ?>">
<?php printf( _n( '<strong>%s event</strong> scheduled', '<strong>%s events</strong> scheduled', $scheduled_count, 'sportspress' ), $scheduled_count ); ?>
</a>
</li>
<li class="events-published">
<a href="<?php echo admin_url( 'edit.php?post_type=sp_event&post_status=publish' ); ?>">
<?php printf( _n( '<strong>%s event</strong> published', '<strong>%s events</strong> published', $published_count, 'sportspress' ), $published_count ); ?>
</a>
</li>
</ul>
<?php
}
/**
* Show status widget
*/
public function status_widget() {
?>
<ul class="sp_status_list">
<?php
$count = wp_count_posts( 'sp_event' );
$scheduled_count = isset( $count->future ) ? $count->future : 0;
$published_count = isset( $count->publish ) ? $count->publish : 0;
$next_event = sp_get_next_event();
if ( $next_event ) :
$now = new DateTime( current_time( 'mysql', 0 ) );
$date = new DateTime( $next_event->post_date );
$interval = date_diff( $now, $date );
?>
<li class="countdown" data-countdown="<?php echo str_replace( '-', '/', get_gmt_from_date( $next_event->post_date ) ); ?>">
<a href="<?php echo get_edit_post_link( $next_event->ID ); ?>">
<?php printf( __( '<strong>%s</strong> until next event', 'sportspress' ), $interval->days . ' ' . __( 'days', 'sportspress' ) . ' ' . sprintf( '%02s:%02s:%02s', $interval->h, $interval->i, $interval->s ) ); ?>
(<?php echo esc_html( $next_event->post_title ); ?>)
</a>
</li>
<?php endif; ?>
<li class="events-scheduled">
<a href="<?php echo admin_url( 'edit.php?post_type=sp_event&post_status=future' ); ?>">
<?php printf( _n( '<strong>%s event</strong> scheduled', '<strong>%s events</strong> scheduled', $scheduled_count, 'sportspress' ), $scheduled_count ); ?>
</a>
</li>
<li class="events-published">
<a href="<?php echo admin_url( 'edit.php?post_type=sp_event&post_status=publish' ); ?>">
<?php printf( _n( '<strong>%s event</strong> published', '<strong>%s events</strong> published', $published_count, 'sportspress' ), $published_count ); ?>
</a>
</li>
</ul>
<?php
}
/**
* Show news widget
*/
public function news_widget() {
$rss = fetch_feed("https://tboy.co/sportsnews/");
if (!is_wp_error($rss)) { // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 2.
$maxitems = $rss->get_item_quantity(5);
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items(0, $maxitems);
}
if (!empty($maxitems)) {
?>
<div class="rss-widget">
<ul>
<?php foreach ($rss_items as $item) { ?>
<li><a class="rsswidget" href="<?php echo esc_url( $item->get_permalink() ); ?>" target="_blank"><?php echo esc_attr( $item->get_title() ); ?></a> <span class="rss-date"><?php echo esc_html( $item->get_date('j F Y') ); ?></span></li>
<?php } ?>
</ul>
</div>
<?php
}
}
}
/**
* Show news widget
*/
public function news_widget() {
$rss = fetch_feed( 'https://tboy.co/sportsnews/' );
if ( ! is_wp_error( $rss ) ) { // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 2.
$maxitems = $rss->get_item_quantity( 5 );
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items( 0, $maxitems );
}
if ( ! empty( $maxitems ) ) {
?>
<div class="rss-widget">
<ul>
<?php foreach ( $rss_items as $item ) { ?>
<li><a class="rsswidget" href="<?php echo esc_url( $item->get_permalink() ); ?>" target="_blank"><?php echo esc_attr( $item->get_title() ); ?></a> <span class="rss-date"><?php echo esc_html( $item->get_date( 'j F Y' ) ); ?></span></li>
<?php } ?>
</ul>
</div>
<?php
}
}
}
endif;
return new SP_Admin_Dashboard();
return new SP_Admin_Dashboard();

View File

@@ -4,11 +4,11 @@
*
* Methods which tweak the WP Editor.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.4
*/
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
@@ -51,8 +51,8 @@ class SP_Admin_Editor {
* @return array
*/
public function add_tinymce_lang( $arr ) {
$arr['sp_shortcodes_button'] = SP()->plugin_path() . '/assets/js/admin/editor-lang.php';
return $arr;
$arr['sp_shortcodes_button'] = SP()->plugin_path() . '/assets/js/admin/editor-lang.php';
return $arr;
}
/**

View File

@@ -2,166 +2,172 @@
/**
* Setup importers for SP data.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.5.1
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.5.1
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_Importers' ) ) :
/**
* SP_Admin_Importers Class
*/
class SP_Admin_Importers {
/**
* Hook in tabs.
* SP_Admin_Importers Class
*/
public function __construct() {
add_action( 'admin_init', array( $this, 'register_importers' ) );
}
class SP_Admin_Importers {
/**
* Add menu items
*/
public function register_importers() {
global $pagenow;
$importers = apply_filters( 'sportspress_importers', array(
'sp_event_csv' => array(
'name' => __( 'SportsPress Events (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>events</strong> from a csv file.', 'sportspress'),
'callback' => array( $this, 'events_importer' ),
),
'sp_fixture_csv' => array(
'name' => __( 'SportsPress Fixtures (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>upcoming events</strong> from a csv file.', 'sportspress'),
'callback' => array( $this, 'fixtures_importer' ),
),
'sp_team_csv' => array(
'name' => __( 'SportsPress Teams (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>teams</strong> from a csv file.', 'sportspress'),
'callback' => array( $this, 'teams_importer' ),
),
'sp_player_csv' => array(
'name' => __( 'SportsPress Players (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>players</strong> from a csv file.', 'sportspress'),
'callback' => array( $this, 'players_importer' ),
),
'sp_staff_csv' => array(
'name' => __( 'SportsPress Staff (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>staff</strong> from a csv file.', 'sportspress'),
'callback' => array( $this, 'staff_importer' ),
),
) );
/**
* Hook in tabs.
*/
public function __construct() {
add_action( 'admin_init', array( $this, 'register_importers' ) );
}
if ( 'import.php' !== $pagenow ) {
$importers['sp_event_performance_csv'] = array(
'name' => __( 'SportsPress Box Score (CSV)', 'sportspress' ),
'description' => '<a href="' . admin_url( add_query_arg( array( 'post_type' => 'sp_event' ), 'edit.php' ) ) . '">' . sprintf( __( 'Select %s', 'sportspress' ), __( 'Event', 'sportspress' ) ) . '</a>',
'callback' => array( $this, 'event_performance_importer' ),
/**
* Add menu items
*/
public function register_importers() {
global $pagenow;
$importers = apply_filters(
'sportspress_importers',
array(
'sp_event_csv' => array(
'name' => __( 'SportsPress Events (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>events</strong> from a csv file.', 'sportspress' ),
'callback' => array( $this, 'events_importer' ),
),
'sp_fixture_csv' => array(
'name' => __( 'SportsPress Fixtures (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>upcoming events</strong> from a csv file.', 'sportspress' ),
'callback' => array( $this, 'fixtures_importer' ),
),
'sp_team_csv' => array(
'name' => __( 'SportsPress Teams (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>teams</strong> from a csv file.', 'sportspress' ),
'callback' => array( $this, 'teams_importer' ),
),
'sp_player_csv' => array(
'name' => __( 'SportsPress Players (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>players</strong> from a csv file.', 'sportspress' ),
'callback' => array( $this, 'players_importer' ),
),
'sp_staff_csv' => array(
'name' => __( 'SportsPress Staff (CSV)', 'sportspress' ),
'description' => __( 'Import <strong>staff</strong> from a csv file.', 'sportspress' ),
'callback' => array( $this, 'staff_importer' ),
),
)
);
if ( 'import.php' !== $pagenow ) {
$importers['sp_event_performance_csv'] = array(
'name' => __( 'SportsPress Box Score (CSV)', 'sportspress' ),
'description' => '<a href="' . admin_url( add_query_arg( array( 'post_type' => 'sp_event' ), 'edit.php' ) ) . '">' . sprintf( __( 'Select %s', 'sportspress' ), __( 'Event', 'sportspress' ) ) . '</a>',
'callback' => array( $this, 'event_performance_importer' ),
);
}
foreach ( $importers as $id => $importer ) {
register_importer( $id, $importer['name'], $importer['description'], $importer['callback'] );
}
}
foreach ( $importers as $id => $importer ) {
register_importer( $id, $importer['name'], $importer['description'], $importer['callback'] );
/**
* Add menu item
*/
public function events_importer() {
$this->includes();
require 'importers/class-sp-event-importer.php';
// Dispatch
$importer = new SP_Event_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function event_performance_importer() {
$this->includes();
require 'importers/class-sp-event-performance-importer.php';
// Dispatch
$importer = new SP_Event_Performance_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function fixtures_importer() {
$this->includes();
require 'importers/class-sp-fixture-importer.php';
// Dispatch
$importer = new SP_Fixture_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function teams_importer() {
$this->includes();
require 'importers/class-sp-team-importer.php';
// Dispatch
$importer = new SP_Team_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function players_importer() {
$this->includes();
require 'importers/class-sp-player-importer.php';
// Dispatch
$importer = new SP_Player_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function staff_importer() {
$this->includes();
require 'importers/class-sp-staff-importer.php';
// Dispatch
$importer = new SP_Staff_Importer();
$importer->dispatch();
}
public static function includes() {
// Load Importer API
require_once ABSPATH . 'wp-admin/includes/import.php';
if ( ! class_exists( 'WP_Importer' ) ) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if ( file_exists( $class_wp_importer ) ) {
require $class_wp_importer;
}
}
require 'importers/class-sp-importer.php';
}
}
/**
* Add menu item
*/
public function events_importer() {
$this->includes();
require 'importers/class-sp-event-importer.php';
// Dispatch
$importer = new SP_Event_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function event_performance_importer() {
$this->includes();
require 'importers/class-sp-event-performance-importer.php';
// Dispatch
$importer = new SP_Event_Performance_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function fixtures_importer() {
$this->includes();
require 'importers/class-sp-fixture-importer.php';
// Dispatch
$importer = new SP_Fixture_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function teams_importer() {
$this->includes();
require 'importers/class-sp-team-importer.php';
// Dispatch
$importer = new SP_Team_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function players_importer() {
$this->includes();
require 'importers/class-sp-player-importer.php';
// Dispatch
$importer = new SP_Player_Importer();
$importer->dispatch();
}
/**
* Add menu item
*/
public function staff_importer() {
$this->includes();
require 'importers/class-sp-staff-importer.php';
// Dispatch
$importer = new SP_Staff_Importer();
$importer->dispatch();
}
public static function includes() {
// Load Importer API
require_once ABSPATH . 'wp-admin/includes/import.php';
if ( ! class_exists( 'WP_Importer' ) ) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if ( file_exists( $class_wp_importer ) )
require $class_wp_importer;
}
require 'importers/class-sp-importer.php';
}
}
endif;
return new SP_Admin_Importers();
return new SP_Admin_Importers();

View File

@@ -2,283 +2,293 @@
/**
* Setup menus in WP admin.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_Menus' ) ) :
/**
* SP_Admin_Menus Class
*/
class SP_Admin_Menus {
/**
* Hook in tabs.
* SP_Admin_Menus Class
*/
public function __construct() {
add_filter( 'admin_menu', array( $this, 'menu_clean' ), 5 );
add_action( 'admin_menu', array( $this, 'admin_menu' ), 6 );
add_action( 'admin_menu', array( $this, 'config_menu' ), 7 );
add_action( 'admin_menu', array( $this, 'leagues_menu' ), 20 );
add_action( 'admin_menu', array( $this, 'seasons_menu' ), 21 );
class SP_Admin_Menus {
add_action( 'admin_head', array( $this, 'menu_highlight' ) );
add_action( 'admin_head', array( $this, 'menu_rename' ) );
add_action( 'parent_file', array( $this, 'parent_file' ) );
add_filter( 'menu_order', array( $this, 'menu_order' ) );
add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) );
add_filter( 'sportspress_sitemap_taxonomy_post_types', array( $this, 'sitemap_taxonomy_post_types' ), 10, 2 );
}
/**
* Hook in tabs.
*/
public function __construct() {
add_filter( 'admin_menu', array( $this, 'menu_clean' ), 5 );
add_action( 'admin_menu', array( $this, 'admin_menu' ), 6 );
add_action( 'admin_menu', array( $this, 'config_menu' ), 7 );
add_action( 'admin_menu', array( $this, 'leagues_menu' ), 20 );
add_action( 'admin_menu', array( $this, 'seasons_menu' ), 21 );
/**
* Add menu item
*/
public function admin_menu() {
global $menu;
if ( current_user_can( 'manage_sportspress' ) )
$menu[] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' );
$main_page = add_menu_page( __( 'SportsPress', 'sportspress' ), __( 'SportsPress', 'sportspress' ), 'manage_sportspress', 'sportspress', array( $this, 'settings_page' ), apply_filters( 'sportspress_menu_icon', null ), '51.5' );
}
/**
* Add menu item
*/
public function config_menu() {
add_submenu_page( 'sportspress', __( 'Configure', 'sportspress' ), __( 'Configure', 'sportspress' ), 'manage_sportspress', 'sportspress-config', array( $this, 'config_page' ) );
}
/**
* Add menu item
*/
public function leagues_menu() {
add_submenu_page( 'sportspress', __( 'Leagues', 'sportspress' ), __( 'Leagues', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_league');
}
/**
* Add menu item
*/
public function seasons_menu() {
add_submenu_page( 'sportspress', __( 'Seasons', 'sportspress' ), __( 'Seasons', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_season');
}
/**
* Highlights the correct top level admin menu item for post type add screens.
*
* @access public
* @return void
*/
public function menu_highlight() {
global $typenow;
$screen = get_current_screen();
if ( ! is_object( $screen ) ) return;
if ( $screen->id == 'sp_role' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_staff', 'edit-tags.php?taxonomy=sp_role&post_type=sp_staff' );
} elseif ( is_sp_config_type( $typenow ) ) {
$this->highlight_admin_menu( 'sportspress', 'sportspress-config' );
} elseif ( $typenow == 'sp_calendar' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_event', 'edit.php?post_type=sp_calendar' );
} elseif ( $typenow == 'sp_table' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_team', 'edit.php?post_type=sp_table' );
} elseif ( $typenow == 'sp_list' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_player', 'edit.php?post_type=sp_list' );
add_action( 'admin_head', array( $this, 'menu_highlight' ) );
add_action( 'admin_head', array( $this, 'menu_rename' ) );
add_action( 'parent_file', array( $this, 'parent_file' ) );
add_filter( 'menu_order', array( $this, 'menu_order' ) );
add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) );
add_filter( 'sportspress_sitemap_taxonomy_post_types', array( $this, 'sitemap_taxonomy_post_types' ), 10, 2 );
}
}
/**
* Renames admin menu items.
*
* @access public
* @return void
*/
public function menu_rename() {
global $menu, $submenu;
/**
* Add menu item
*/
public function admin_menu() {
global $menu;
if ( isset( $submenu['sportspress'] ) && isset( $submenu['sportspress'][0] ) && isset( $submenu['sportspress'][0][0] ) )
$submenu['sportspress'][0][0] = __( 'Settings', 'sportspress' );
}
if ( current_user_can( 'manage_sportspress' ) ) {
$menu[] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' );
}
public function parent_file( $parent_file ) {
global $current_screen;
$taxonomy = $current_screen->taxonomy;
if ( in_array( $taxonomy, array( 'sp_league', 'sp_season' ) ) )
$parent_file = 'sportspress';
return $parent_file;
}
$main_page = add_menu_page( __( 'SportsPress', 'sportspress' ), __( 'SportsPress', 'sportspress' ), 'manage_sportspress', 'sportspress', array( $this, 'settings_page' ), apply_filters( 'sportspress_menu_icon', null ), '51.5' );
}
/**
* Reorder the SP menu items in admin.
*
* @param mixed $menu_order
* @return array
*/
public function menu_order( $menu_order ) {
// Initialize our custom order array
$sportspress_menu_order = array();
/**
* Add menu item
*/
public function config_menu() {
add_submenu_page( 'sportspress', __( 'Configure', 'sportspress' ), __( 'Configure', 'sportspress' ), 'manage_sportspress', 'sportspress-config', array( $this, 'config_page' ) );
}
// Get the index of our custom separator
$sportspress_separator = array_search( 'separator-sportspress', $menu_order );
/**
* Add menu item
*/
public function leagues_menu() {
add_submenu_page( 'sportspress', __( 'Leagues', 'sportspress' ), __( 'Leagues', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_league' );
}
// Get index of menu items
$sportspress_event = array_search( 'edit.php?post_type=sp_event', $menu_order );
$sportspress_team = array_search( 'edit.php?post_type=sp_team', $menu_order );
$sportspress_player = array_search( 'edit.php?post_type=sp_player', $menu_order );
$sportspress_staff = array_search( 'edit.php?post_type=sp_staff', $menu_order );
/**
* Add menu item
*/
public function seasons_menu() {
add_submenu_page( 'sportspress', __( 'Seasons', 'sportspress' ), __( 'Seasons', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_season' );
}
// Loop through menu order and do some rearranging
foreach ( $menu_order as $index => $item ):
/**
* Highlights the correct top level admin menu item for post type add screens.
*
* @access public
* @return void
*/
public function menu_highlight() {
global $typenow;
$screen = get_current_screen();
if ( ! is_object( $screen ) ) {
return;
}
if ( $screen->id == 'sp_role' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_staff', 'edit-tags.php?taxonomy=sp_role&post_type=sp_staff' );
} elseif ( is_sp_config_type( $typenow ) ) {
$this->highlight_admin_menu( 'sportspress', 'sportspress-config' );
} elseif ( $typenow == 'sp_calendar' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_event', 'edit.php?post_type=sp_calendar' );
} elseif ( $typenow == 'sp_table' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_team', 'edit.php?post_type=sp_table' );
} elseif ( $typenow == 'sp_list' ) {
$this->highlight_admin_menu( 'edit.php?post_type=sp_player', 'edit.php?post_type=sp_list' );
}
}
if ( ( ( 'sportspress' ) == $item ) ):
$sportspress_menu_order[] = 'separator-sportspress';
$sportspress_menu_order[] = $item;
$sportspress_menu_order[] = 'edit.php?post_type=sp_event';
$sportspress_menu_order[] = 'edit.php?post_type=sp_team';
$sportspress_menu_order[] = 'edit.php?post_type=sp_player';
$sportspress_menu_order[] = 'edit.php?post_type=sp_staff';
unset( $menu_order[ $sportspress_separator ] );
unset( $menu_order[ $sportspress_event ] );
unset( $menu_order[ $sportspress_team ] );
unset( $menu_order[ $sportspress_player ] );
unset( $menu_order[ $sportspress_staff ] );
/**
* Renames admin menu items.
*
* @access public
* @return void
*/
public function menu_rename() {
global $menu, $submenu;
// Apply to added menu items
$menu_items = apply_filters( 'sportspress_menu_items', array() );
foreach ( $menu_items as $menu_item ):
$sportspress_menu_order[] = $menu_item;
$index = array_search( $menu_item, $menu_order );
unset( $menu_order[ $index ] );
endforeach;
if ( isset( $submenu['sportspress'] ) && isset( $submenu['sportspress'][0] ) && isset( $submenu['sportspress'][0][0] ) ) {
$submenu['sportspress'][0][0] = __( 'Settings', 'sportspress' );
}
}
elseif ( !in_array( $item, array( 'separator-sportspress' ) ) ) :
$sportspress_menu_order[] = $item;
public function parent_file( $parent_file ) {
global $current_screen;
$taxonomy = $current_screen->taxonomy;
if ( in_array( $taxonomy, array( 'sp_league', 'sp_season' ) ) ) {
$parent_file = 'sportspress';
}
return $parent_file;
}
/**
* Reorder the SP menu items in admin.
*
* @param mixed $menu_order
* @return array
*/
public function menu_order( $menu_order ) {
// Initialize our custom order array
$sportspress_menu_order = array();
// Get the index of our custom separator
$sportspress_separator = array_search( 'separator-sportspress', $menu_order );
// Get index of menu items
$sportspress_event = array_search( 'edit.php?post_type=sp_event', $menu_order );
$sportspress_team = array_search( 'edit.php?post_type=sp_team', $menu_order );
$sportspress_player = array_search( 'edit.php?post_type=sp_player', $menu_order );
$sportspress_staff = array_search( 'edit.php?post_type=sp_staff', $menu_order );
// Loop through menu order and do some rearranging
foreach ( $menu_order as $index => $item ) :
if ( ( ( 'sportspress' ) == $item ) ) :
$sportspress_menu_order[] = 'separator-sportspress';
$sportspress_menu_order[] = $item;
$sportspress_menu_order[] = 'edit.php?post_type=sp_event';
$sportspress_menu_order[] = 'edit.php?post_type=sp_team';
$sportspress_menu_order[] = 'edit.php?post_type=sp_player';
$sportspress_menu_order[] = 'edit.php?post_type=sp_staff';
unset( $menu_order[ $sportspress_separator ] );
unset( $menu_order[ $sportspress_event ] );
unset( $menu_order[ $sportspress_team ] );
unset( $menu_order[ $sportspress_player ] );
unset( $menu_order[ $sportspress_staff ] );
// Apply to added menu items
$menu_items = apply_filters( 'sportspress_menu_items', array() );
foreach ( $menu_items as $menu_item ) :
$sportspress_menu_order[] = $menu_item;
$index = array_search( $menu_item, $menu_order );
unset( $menu_order[ $index ] );
endforeach;
elseif ( ! in_array( $item, array( 'separator-sportspress' ) ) ) :
$sportspress_menu_order[] = $item;
endif;
endforeach;
// Return order
return $sportspress_menu_order;
}
/**
* custom_menu_order
*
* @return bool
*/
public function custom_menu_order() {
if ( ! current_user_can( 'manage_sportspress' ) ) {
return false;
}
return true;
}
/**
* Clean the SP menu items in admin.
*/
public function menu_clean() {
global $menu, $submenu, $current_user;
// Find where our separator is in the menu
foreach ( $menu as $key => $data ) :
if ( is_array( $data ) && array_key_exists( 2, $data ) && $data[2] == 'edit.php?post_type=sp_separator' ) {
$separator_position = $key;
}
endforeach;
// Swap our separator post type with a menu separator
if ( isset( $separator_position ) ) :
$menu[ $separator_position ] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' );
endif;
endforeach;
// Remove "Leagues" and "Seasons" links from Events submenu
if ( isset( $submenu['edit.php?post_type=sp_event'] ) ) :
$submenu['edit.php?post_type=sp_event'] = array_filter( $submenu['edit.php?post_type=sp_event'], array( $this, 'remove_leagues' ) );
$submenu['edit.php?post_type=sp_event'] = array_filter( $submenu['edit.php?post_type=sp_event'], array( $this, 'remove_seasons' ) );
endif;
// Return order
return $sportspress_menu_order;
// Remove "Venues", "Leagues" and "Seasons" links from Teams submenu
if ( isset( $submenu['edit.php?post_type=sp_team'] ) ) :
$submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_venues' ) );
$submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_leagues' ) );
$submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_seasons' ) );
endif;
// Remove "Leagues" and "Seasons" links from Players submenu
if ( isset( $submenu['edit.php?post_type=sp_player'] ) ) :
$submenu['edit.php?post_type=sp_player'] = array_filter( $submenu['edit.php?post_type=sp_player'], array( $this, 'remove_leagues' ) );
$submenu['edit.php?post_type=sp_player'] = array_filter( $submenu['edit.php?post_type=sp_player'], array( $this, 'remove_seasons' ) );
endif;
// Remove "Leagues" and "Seasons" links from Staff submenu
if ( isset( $submenu['edit.php?post_type=sp_staff'] ) ) :
$submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_leagues' ) );
$submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_seasons' ) );
endif;
$user_roles = $current_user->roles;
$user_role = array_shift( $user_roles );
if ( in_array( $user_role, array( 'sp_player', 'sp_staff', 'sp_event_manager', 'sp_team_manager' ) ) ) :
remove_menu_page( 'upload.php' );
remove_menu_page( 'edit-comments.php' );
remove_menu_page( 'tools.php' );
endif;
}
/**
* Init the config page
*/
public function config_page() {
include 'views/html-admin-config.php';
}
/**
* Init the settings page
*/
public function settings_page() {
include_once 'class-sp-admin-settings.php';
SP_Admin_Settings::output();
}
public function remove_add_new( $arr = array() ) {
return $arr[0] != __( 'Add New', 'sportspress' );
}
public function remove_leagues( $arr = array() ) {
return $arr[0] != __( 'Leagues', 'sportspress' );
}
public function remove_positions( $arr = array() ) {
return $arr[0] != __( 'Positions', 'sportspress' );
}
public function remove_seasons( $arr = array() ) {
return $arr[0] != __( 'Seasons', 'sportspress' );
}
public function remove_venues( $arr = array() ) {
return $arr[0] != __( 'Venues', 'sportspress' );
}
public static function highlight_admin_menu( $p = 'sportspress', $s = 'sportspress' ) {
global $parent_file, $submenu_file;
$parent_file = $p;
$submenu_file = $s;
}
public static function sitemap_taxonomy_post_types( $post_types = array(), $taxonomy = 'sp_venue' ) {
$post_types = array_intersect( $post_types, sp_primary_post_types() );
// Remove teams from venues taxonomy post type array
if ( $taxonomy === 'sp_venue' && ( $key = array_search( 'sp_team', $post_types ) ) !== false ) :
unset( $post_types[ $key ] );
endif;
return $post_types;
}
}
/**
* custom_menu_order
* @return bool
*/
public function custom_menu_order() {
if ( ! current_user_can( 'manage_sportspress' ) )
return false;
return true;
}
/**
* Clean the SP menu items in admin.
*/
public function menu_clean() {
global $menu, $submenu, $current_user;
// Find where our separator is in the menu
foreach( $menu as $key => $data ):
if ( is_array( $data ) && array_key_exists( 2, $data ) && $data[2] == 'edit.php?post_type=sp_separator' )
$separator_position = $key;
endforeach;
// Swap our separator post type with a menu separator
if ( isset( $separator_position ) ):
$menu[ $separator_position ] = array( '', 'read', 'separator-sportspress', '', 'wp-menu-separator sportspress' );
endif;
// Remove "Leagues" and "Seasons" links from Events submenu
if ( isset( $submenu['edit.php?post_type=sp_event'] ) ):
$submenu['edit.php?post_type=sp_event'] = array_filter( $submenu['edit.php?post_type=sp_event'], array( $this, 'remove_leagues' ) );
$submenu['edit.php?post_type=sp_event'] = array_filter( $submenu['edit.php?post_type=sp_event'], array( $this, 'remove_seasons' ) );
endif;
// Remove "Venues", "Leagues" and "Seasons" links from Teams submenu
if ( isset( $submenu['edit.php?post_type=sp_team'] ) ):
$submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_venues' ) );
$submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_leagues' ) );
$submenu['edit.php?post_type=sp_team'] = array_filter( $submenu['edit.php?post_type=sp_team'], array( $this, 'remove_seasons' ) );
endif;
// Remove "Leagues" and "Seasons" links from Players submenu
if ( isset( $submenu['edit.php?post_type=sp_player'] ) ):
$submenu['edit.php?post_type=sp_player'] = array_filter( $submenu['edit.php?post_type=sp_player'], array( $this, 'remove_leagues' ) );
$submenu['edit.php?post_type=sp_player'] = array_filter( $submenu['edit.php?post_type=sp_player'], array( $this, 'remove_seasons' ) );
endif;
// Remove "Leagues" and "Seasons" links from Staff submenu
if ( isset( $submenu['edit.php?post_type=sp_staff'] ) ):
$submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_leagues' ) );
$submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_seasons' ) );
endif;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
if ( in_array( $user_role, array( 'sp_player', 'sp_staff', 'sp_event_manager', 'sp_team_manager' ) ) ):
remove_menu_page( 'upload.php' );
remove_menu_page( 'edit-comments.php' );
remove_menu_page( 'tools.php' );
endif;
}
/**
* Init the config page
*/
public function config_page() {
include( 'views/html-admin-config.php' );
}
/**
* Init the settings page
*/
public function settings_page() {
include_once( 'class-sp-admin-settings.php' );
SP_Admin_Settings::output();
}
public function remove_add_new( $arr = array() ) {
return $arr[0] != __( 'Add New', 'sportspress' );
}
public function remove_leagues( $arr = array() ) {
return $arr[0] != __( 'Leagues', 'sportspress' );
}
public function remove_positions( $arr = array() ) {
return $arr[0] != __( 'Positions', 'sportspress' );
}
public function remove_seasons( $arr = array() ) {
return $arr[0] != __( 'Seasons', 'sportspress' );
}
public function remove_venues( $arr = array() ) {
return $arr[0] != __( 'Venues', 'sportspress' );
}
public static function highlight_admin_menu( $p = 'sportspress', $s = 'sportspress' ) {
global $parent_file, $submenu_file;
$parent_file = $p;
$submenu_file = $s;
}
public static function sitemap_taxonomy_post_types( $post_types = array(), $taxonomy = 'sp_venue' ) {
$post_types = array_intersect( $post_types, sp_primary_post_types() );
// Remove teams from venues taxonomy post type array
if ( $taxonomy === 'sp_venue' && ( $key = array_search( 'sp_team', $post_types ) ) !== false ):
unset( $post_types[ $key ] );
endif;
return $post_types;
}
}
endif;
return new SP_Admin_Menus();

View File

@@ -2,145 +2,149 @@
/**
* Display notices in admin.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.3
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_Notices' ) ) :
/**
* SP_Admin_Notices Class
*/
class SP_Admin_Notices {
/**
* Hook in tabs.
* SP_Admin_Notices Class
*/
public function __construct() {
add_action( 'switch_theme', array( $this, 'reset_admin_notices' ) );
add_action( 'sportspress_updated', array( $this, 'reset_admin_notices' ) );
add_action( 'admin_print_styles', array( $this, 'add_notices' ) );
}
class SP_Admin_Notices {
/**
* Reset notices for themes when switched or a new version of SP is installed
*/
public function reset_admin_notices() {
update_option( 'sportspress_admin_notices', array( 'template_files', 'theme_support' ) );
}
/**
* Add notices + styles if needed.
*/
public function add_notices() {
$screen = get_current_screen();
$notices = get_option( 'sportspress_admin_notices', array() );
if ( ! is_object( $screen ) ) return;
if ( ! get_option( 'sportspress_completed_setup' ) && ! in_array( $screen->id, array( 'dashboard_page_sp-about', 'dashboard_page_sp-credits', 'dashboard_page_sp-translators' ) ) ) {
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) );
add_action( 'admin_notices', array( $this, 'setup_notice' ) );
/**
* Hook in tabs.
*/
public function __construct() {
add_action( 'switch_theme', array( $this, 'reset_admin_notices' ) );
add_action( 'sportspress_updated', array( $this, 'reset_admin_notices' ) );
add_action( 'admin_print_styles', array( $this, 'add_notices' ) );
}
if ( 'post' == $screen->base ) {
$post_id = get_the_ID();
if ( ! apply_filters( 'sportspress_user_can', current_user_can( 'edit_post', $post_id ), $post_id ) ) {
add_action( 'admin_notices', array( $this, 'no_access_notice' ) );
}
/**
* Reset notices for themes when switched or a new version of SP is installed
*/
public function reset_admin_notices() {
update_option( 'sportspress_admin_notices', array( 'template_files', 'theme_support' ) );
}
if ( ! empty( $_GET['hide_theme_support_notice'] ) ) {
$notices = array_diff( $notices, array( 'theme_support' ) );
update_option( 'sportspress_admin_notices', $notices );
}
/**
* Add notices + styles if needed.
*/
public function add_notices() {
$screen = get_current_screen();
$notices = get_option( 'sportspress_admin_notices', array() );
if ( ! empty( $_GET['hide_template_files_notice'] ) ) {
$notices = array_diff( $notices, array( 'template_files' ) );
update_option( 'sportspress_admin_notices', $notices );
}
if ( in_array( 'theme_support', $notices ) && ! current_theme_supports( 'sportspress' ) && ! in_array( $screen->id, array( 'toplevel_page_sportspress', 'dashboard_page_sp-about', 'dashboard_page_sp-credits', 'dashboard_page_sp-translators' ) ) ) {
$template = get_option( 'template' );
if ( ! in_array( $template, array( 'twentyfifteen', 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' ) ) ) {
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) );
add_action( 'admin_notices', array( $this, 'theme_check_notice' ) );
}
}
if ( in_array( 'template_files', $notices ) ) {
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) );
add_action( 'admin_notices', array( $this, 'template_file_check_notice' ) );
}
}
/**
* Show the setup notices
*/
public function setup_notice() {
include( 'views/html-notice-install.php' );
}
/**
* Displays a notice when the user doesn't have access to edit a post type
*/
public function no_access_notice() {
include( 'views/html-notice-no-access.php' );
}
/**
* Show the Theme Check notice
*/
public function theme_check_notice() {
include( 'views/html-notice-theme-support.php' );
}
/**
* Show a notice highlighting bad template files
*/
public function template_file_check_notice() {
if ( isset( $_GET['page'] ) && 'sportspress' == $_GET['page'] && isset( $_GET['tab'] ) && 'status' == $_GET['tab'] ) {
return;
}
$status = include( 'class-sp-admin-status.php' );
$core_templates = $status->scan_template_files( SP()->plugin_path() . '/templates' );
$outdated = false;
foreach ( $core_templates as $file ) {
$theme_file = false;
if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
$theme_file = get_stylesheet_directory() . '/' . $file;
} elseif ( file_exists( get_stylesheet_directory() . '/sportspress/' . $file ) ) {
$theme_file = get_stylesheet_directory() . '/sportspress/' . $file;
} elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
$theme_file = get_template_directory() . '/' . $file;
} elseif( file_exists( get_template_directory() . '/sportspress/' . $file ) ) {
$theme_file = get_template_directory() . '/sportspress/' . $file;
if ( ! is_object( $screen ) ) {
return;
}
if ( $theme_file ) {
$core_version = $status->get_file_version( SP()->plugin_path() . '/templates/' . $file );
$theme_version = $status->get_file_version( $theme_file );
if ( ! get_option( 'sportspress_completed_setup' ) && ! in_array( $screen->id, array( 'dashboard_page_sp-about', 'dashboard_page_sp-credits', 'dashboard_page_sp-translators' ) ) ) {
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) );
add_action( 'admin_notices', array( $this, 'setup_notice' ) );
}
if ( $core_version && $theme_version && version_compare( $theme_version, $core_version, '<' ) ) {
$outdated = true;
break;
if ( 'post' == $screen->base ) {
$post_id = get_the_ID();
if ( ! apply_filters( 'sportspress_user_can', current_user_can( 'edit_post', $post_id ), $post_id ) ) {
add_action( 'admin_notices', array( $this, 'no_access_notice' ) );
}
}
if ( ! empty( $_GET['hide_theme_support_notice'] ) ) {
$notices = array_diff( $notices, array( 'theme_support' ) );
update_option( 'sportspress_admin_notices', $notices );
}
if ( ! empty( $_GET['hide_template_files_notice'] ) ) {
$notices = array_diff( $notices, array( 'template_files' ) );
update_option( 'sportspress_admin_notices', $notices );
}
if ( in_array( 'theme_support', $notices ) && ! current_theme_supports( 'sportspress' ) && ! in_array( $screen->id, array( 'toplevel_page_sportspress', 'dashboard_page_sp-about', 'dashboard_page_sp-credits', 'dashboard_page_sp-translators' ) ) ) {
$template = get_option( 'template' );
if ( ! in_array( $template, array( 'twentyfifteen', 'twentyfourteen', 'twentythirteen', 'twentyeleven', 'twentytwelve', 'twentyten' ) ) ) {
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) );
add_action( 'admin_notices', array( $this, 'theme_check_notice' ) );
}
}
if ( in_array( 'template_files', $notices ) ) {
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ) );
add_action( 'admin_notices', array( $this, 'template_file_check_notice' ) );
}
}
if ( $outdated ) {
include( 'views/html-notice-template-check.php' );
/**
* Show the setup notices
*/
public function setup_notice() {
include 'views/html-notice-install.php';
}
/**
* Displays a notice when the user doesn't have access to edit a post type
*/
public function no_access_notice() {
include 'views/html-notice-no-access.php';
}
/**
* Show the Theme Check notice
*/
public function theme_check_notice() {
include 'views/html-notice-theme-support.php';
}
/**
* Show a notice highlighting bad template files
*/
public function template_file_check_notice() {
if ( isset( $_GET['page'] ) && 'sportspress' == $_GET['page'] && isset( $_GET['tab'] ) && 'status' == $_GET['tab'] ) {
return;
}
$status = include 'class-sp-admin-status.php';
$core_templates = $status->scan_template_files( SP()->plugin_path() . '/templates' );
$outdated = false;
foreach ( $core_templates as $file ) {
$theme_file = false;
if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
$theme_file = get_stylesheet_directory() . '/' . $file;
} elseif ( file_exists( get_stylesheet_directory() . '/sportspress/' . $file ) ) {
$theme_file = get_stylesheet_directory() . '/sportspress/' . $file;
} elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
$theme_file = get_template_directory() . '/' . $file;
} elseif ( file_exists( get_template_directory() . '/sportspress/' . $file ) ) {
$theme_file = get_template_directory() . '/sportspress/' . $file;
}
if ( $theme_file ) {
$core_version = $status->get_file_version( SP()->plugin_path() . '/templates/' . $file );
$theme_version = $status->get_file_version( $theme_file );
if ( $core_version && $theme_version && version_compare( $theme_version, $core_version, '<' ) ) {
$outdated = true;
break;
}
}
}
if ( $outdated ) {
include 'views/html-notice-template-check.php';
}
}
}
}
endif;
return new SP_Admin_Notices();
return new SP_Admin_Notices();

View File

@@ -2,102 +2,111 @@
/**
* Adds settings to the permalinks admin settings page.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_Permalink_Settings' ) ) :
/**
* SP_Admin_Permalink_Settings Class
*/
class SP_Admin_Permalink_Settings {
/**
* Hook in tabs.
* SP_Admin_Permalink_Settings Class
*/
public function __construct() {
$this->slugs = apply_filters( 'sportspress_permalink_slugs', array(
array( 'event', __( 'Events', 'sportspress' ) ),
array( 'venue', __( 'Venues', 'sportspress' ) ),
array( 'calendar', __( 'Calendars', 'sportspress' ) ),
array( 'team', __( 'Teams', 'sportspress' ) ),
array( 'league', __( 'Leagues', 'sportspress' ) ),
array( 'season', __( 'Seasons', 'sportspress' ) ),
array( 'table', __( 'League Tables', 'sportspress' ) ),
array( 'player', __( 'Players', 'sportspress' ) ),
array( 'position', __( 'Positions', 'sportspress' ) ),
array( 'list', __( 'Player Lists', 'sportspress' ) ),
array( 'staff', __( 'Staff', 'sportspress' ) ),
) );
class SP_Admin_Permalink_Settings {
add_action( 'admin_init', array( $this, 'settings_init' ) );
add_action( 'admin_init', array( $this, 'settings_save' ) );
}
/**
* Init our settings
*/
public function settings_init() {
// Add a section to the permalinks page
add_settings_section( 'sportspress-permalink', __( 'SportsPress', 'sportspress' ), array( $this, 'settings' ), 'permalink' );
// Add our settings
foreach ( $this->slugs as $slug ):
add_settings_field(
$slug[0], // id
$slug[1], // setting title
array( $this, 'slug_input' ), // display callback
'permalink', // settings page
'sportspress-permalink' // settings section
/**
* Hook in tabs.
*/
public function __construct() {
$this->slugs = apply_filters(
'sportspress_permalink_slugs',
array(
array( 'event', __( 'Events', 'sportspress' ) ),
array( 'venue', __( 'Venues', 'sportspress' ) ),
array( 'calendar', __( 'Calendars', 'sportspress' ) ),
array( 'team', __( 'Teams', 'sportspress' ) ),
array( 'league', __( 'Leagues', 'sportspress' ) ),
array( 'season', __( 'Seasons', 'sportspress' ) ),
array( 'table', __( 'League Tables', 'sportspress' ) ),
array( 'player', __( 'Players', 'sportspress' ) ),
array( 'position', __( 'Positions', 'sportspress' ) ),
array( 'list', __( 'Player Lists', 'sportspress' ) ),
array( 'staff', __( 'Staff', 'sportspress' ) ),
)
);
endforeach;
}
/**
* Show a slug input box.
*/
public function slug_input() {
$slug = array_shift( $this->slugs );
$key = $slug[0];
$text = get_option( 'sportspress_' . $key . '_slug', null );
?><fieldset><input id="sportspress_<?php echo esc_attr( $key ); ?>_slug" name="sportspress_<?php echo esc_attr( $key ); ?>_slug" type="text" class="regular-text code" value="<?php echo esc_attr( $text ); ?>" placeholder="<?php echo esc_attr( $key ); ?>"></fieldset><?php
}
add_action( 'admin_init', array( $this, 'settings_init' ) );
add_action( 'admin_init', array( $this, 'settings_save' ) );
}
/**
* Show the settings
*/
public function settings() {
echo wpautop( __( 'These settings control the permalinks used for SportsPress. These settings only apply when <strong>not using "default" permalinks above</strong>.', 'sportspress' ) );
}
/**
* Init our settings
*/
public function settings_init() {
// Add a section to the permalinks page
add_settings_section( 'sportspress-permalink', __( 'SportsPress', 'sportspress' ), array( $this, 'settings' ), 'permalink' );
/**
* Save the settings
*/
public function settings_save() {
if ( ! is_admin() )
return;
if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['sportspress_event_slug'] ) ):
foreach ( $this->slugs as $slug ):
$key = 'sportspress_' . $slug[0] . '_slug';
$value = null;
if ( isset( $_POST[ $key ] ) )
$value = sanitize_text_field( $_POST[ $key ] );
if ( empty( $value ) )
delete_option( $key );
else
update_option( $key, $value );
// Add our settings
foreach ( $this->slugs as $slug ) :
add_settings_field(
$slug[0], // id
$slug[1], // setting title
array( $this, 'slug_input' ), // display callback
'permalink', // settings page
'sportspress-permalink' // settings section
);
endforeach;
sp_flush_rewrite_rules();
endif;
}
/**
* Show a slug input box.
*/
public function slug_input() {
$slug = array_shift( $this->slugs );
$key = $slug[0];
$text = get_option( 'sportspress_' . $key . '_slug', null );
?><fieldset><input id="sportspress_<?php echo esc_attr( $key ); ?>_slug" name="sportspress_<?php echo esc_attr( $key ); ?>_slug" type="text" class="regular-text code" value="<?php echo esc_attr( $text ); ?>" placeholder="<?php echo esc_attr( $key ); ?>"></fieldset>
<?php
}
/**
* Show the settings
*/
public function settings() {
echo wpautop( __( 'These settings control the permalinks used for SportsPress. These settings only apply when <strong>not using "default" permalinks above</strong>.', 'sportspress' ) );
}
/**
* Save the settings
*/
public function settings_save() {
if ( ! is_admin() ) {
return;
}
if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['sportspress_event_slug'] ) ) :
foreach ( $this->slugs as $slug ) :
$key = 'sportspress_' . $slug[0] . '_slug';
$value = null;
if ( isset( $_POST[ $key ] ) ) {
$value = sanitize_text_field( $_POST[ $key ] );
}
if ( empty( $value ) ) {
delete_option( $key );
} else {
update_option( $key, $value );
}
endforeach;
sp_flush_rewrite_rules();
endif;
}
}
}
endif;
return new SP_Admin_Permalink_Settings();
return new SP_Admin_Permalink_Settings();

View File

@@ -2,122 +2,126 @@
/**
* Post Types Admin
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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
* SP_Admin_Post_Types Class
*/
public function __construct() {
add_action( 'admin_init', array( $this, 'include_post_type_handlers' ) );
add_action( 'save_post', array( $this, 'unflag_post' ) );
add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
add_filter( 'sportspress_meta_boxes', array( $this, 'meta_boxes' ) );
}
class SP_Admin_Post_Types {
/**
* Conditonally load classes and functions only needed when viewing a post type.
*/
public function include_post_type_handlers() {
include_once( 'post-types/class-sp-admin-meta-boxes.php' );
include_once( 'post-types/class-sp-admin-cpt-result.php' );
include_once( 'post-types/class-sp-admin-cpt-outcome.php' );
include_once( 'post-types/class-sp-admin-cpt-performance.php' );
include_once( 'post-types/class-sp-admin-cpt-column.php' );
include_once( 'post-types/class-sp-admin-cpt-metric.php' );
include_once( 'post-types/class-sp-admin-cpt-statistic.php' );
include_once( 'post-types/class-sp-admin-cpt-event.php' );
include_once( 'post-types/class-sp-admin-cpt-team.php' );
include_once( 'post-types/class-sp-admin-cpt-player.php' );
include_once( 'post-types/class-sp-admin-cpt-staff.php' );
do_action( 'sportspress_include_post_type_handlers' );
}
/**
* Constructor
*/
public function __construct() {
add_action( 'admin_init', array( $this, 'include_post_type_handlers' ) );
add_action( 'save_post', array( $this, 'unflag_post' ) );
add_filter( 'post_updated_messages', array( $this, 'post_updated_messages' ) );
add_filter( 'sportspress_meta_boxes', array( $this, 'meta_boxes' ) );
}
/**
* Unflag preset and sample posts.
*/
public function unflag_post( $post_id ) {
$post_types = sp_post_types();
$config_types = sp_config_types();
$post_type = get_post_type( $post_id );
if ( in_array( $post_type, $post_types ) ):
delete_post_meta( $post_id, '_sp_sample' );
elseif ( in_array( $post_type, $config_types ) ):
delete_post_meta( $post_id, '_sp_preset' );
endif;
}
/**
* Conditonally load classes and functions only needed when viewing a post type.
*/
public function include_post_type_handlers() {
include_once 'post-types/class-sp-admin-meta-boxes.php';
include_once 'post-types/class-sp-admin-cpt-result.php';
include_once 'post-types/class-sp-admin-cpt-outcome.php';
include_once 'post-types/class-sp-admin-cpt-performance.php';
include_once 'post-types/class-sp-admin-cpt-column.php';
include_once 'post-types/class-sp-admin-cpt-metric.php';
include_once 'post-types/class-sp-admin-cpt-statistic.php';
include_once 'post-types/class-sp-admin-cpt-event.php';
include_once 'post-types/class-sp-admin-cpt-team.php';
include_once 'post-types/class-sp-admin-cpt-player.php';
include_once 'post-types/class-sp-admin-cpt-staff.php';
do_action( 'sportspress_include_post_type_handlers' );
}
/**
* Change messages when a post type is updated.
*
* @param array $messages
* @return array
*/
public function post_updated_messages( $messages ) {
global $typenow, $post;
/**
* Unflag preset and sample posts.
*/
public function unflag_post( $post_id ) {
$post_types = sp_post_types();
$config_types = sp_config_types();
$post_type = get_post_type( $post_id );
if ( in_array( $post_type, $post_types ) ) :
delete_post_meta( $post_id, '_sp_sample' );
elseif ( in_array( $post_type, $config_types ) ) :
delete_post_meta( $post_id, '_sp_preset' );
endif;
}
if ( is_sp_config_type( $typenow ) ):
$obj = get_post_type_object( $typenow );
/**
* Change messages when a post type is updated.
*
* @param array $messages
* @return array
*/
public function post_updated_messages( $messages ) {
global $typenow, $post;
for ( $i = 0; $i <= 10; $i++ ):
$messages['post'][ $i ] = __( 'Settings saved.', 'sportspress' ) .
if ( is_sp_config_type( $typenow ) ) :
$obj = get_post_type_object( $typenow );
for ( $i = 0; $i <= 10; $i++ ) :
$messages['post'][ $i ] = __( 'Settings saved.', 'sportspress' ) .
' <a href="' . esc_url( admin_url( 'edit.php?post_type=' . $typenow ) ) . '">' .
__( 'View All', 'sportspress' ) . '</a>';
endfor;
elseif ( is_sp_post_type( $typenow ) ):
$obj = get_post_type_object( $typenow );
endfor;
elseif ( is_sp_post_type( $typenow ) ) :
$obj = get_post_type_object( $typenow );
$messages['post'][1] = __( 'Changes saved.', 'sportspress' ) .
' <a href="' . esc_url( get_permalink($post->ID) ) . '">' . $obj->labels->view_item . '</a>';
$messages['post'][1] = __( 'Changes saved.', 'sportspress' ) .
' <a href="' . esc_url( get_permalink( $post->ID ) ) . '">' . $obj->labels->view_item . '</a>';
$messages['post'][4] = __( 'Changes saved.', 'sportspress' );
$messages['post'][4] = __( 'Changes saved.', 'sportspress' );
$messages['post'][6] = __( 'Success!', 'sportspress' ) .
' <a href="' . esc_url( get_permalink($post->ID) ) . '">' . $obj->labels->view_item . '</a>';
$messages['post'][6] = __( 'Success!', 'sportspress' ) .
' <a href="' . esc_url( get_permalink( $post->ID ) ) . '">' . $obj->labels->view_item . '</a>';
$messages['post'][7] = __( 'Changes saved.', 'sportspress' );
$messages['post'][7] = __( 'Changes saved.', 'sportspress' );
$messages['post'][8] = __( 'Success!', 'sportspress' ) .
' <a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink($post->ID) ) ) . '">' .
$messages['post'][8] = __( 'Success!', 'sportspress' ) .
' <a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) . '">' .
sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . '</a>';
$messages['post'][9] = sprintf(
__( 'Scheduled for: <b>%1$s</b>.', 'sportspress' ),
date_i18n( __( 'M j, Y @ G:i', 'sportspress' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post->ID) ) ) .
' <a target="_blank" href="' . esc_url( get_permalink($post->ID) ) . '">' .
sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . '</a>';
$messages['post'][9] = sprintf(
__( 'Scheduled for: <b>%1$s</b>.', 'sportspress' ),
date_i18n( __( 'M j, Y @ G:i', 'sportspress' ), strtotime( $post->post_date ) ),
esc_url( get_permalink( $post->ID ) )
) .
' <a target="_blank" href="' . esc_url( get_permalink( $post->ID ) ) . '">' .
sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . '</a>';
$messages['post'][10] = __( 'Success!', 'sportspress' ) .
' <a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink($post->ID) ) ) . '">' .
sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . '</a>';
endif;
$messages['post'][10] = __( 'Success!', 'sportspress' ) .
' <a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) . '">' .
sprintf( __( 'Preview %s', 'sportspress' ), $obj->labels->singular_name ) . '</a>';
endif;
return $messages;
}
/**
* Remove meta boxes as needed
*/
public static function meta_boxes( $meta_boxes ) {
if ( 'manual' != get_option( 'sportspress_player_columns', 'auto' ) ) {
unset( $meta_boxes['sp_player']['columns'] );
return $messages;
}
/**
* Remove meta boxes as needed
*/
public static function meta_boxes( $meta_boxes ) {
if ( 'manual' != get_option( 'sportspress_player_columns', 'auto' ) ) {
unset( $meta_boxes['sp_player']['columns'] );
}
return $meta_boxes;
}
return $meta_boxes;
}
}
endif;
return new SP_Admin_Post_Types();
return new SP_Admin_Post_Types();

View File

@@ -4,11 +4,11 @@
*
* The SportsPress admin sample data class stores demo content.
*
* @class SP_Admin_Sample_Data
* @version 2.5
* @package SportsPress/Admin
* @category Class
* @author ThemeBoy
* @class SP_Admin_Sample_Data
* @version 2.5
* @package SportsPress/Admin
* @category Class
* @author ThemeBoy
*/
class SP_Admin_Sample_Data {
@@ -23,18 +23,18 @@ class SP_Admin_Sample_Data {
// Initialize inserted ids array
$inserted_ids = array(
'sp_league' => array(),
'sp_season' => array(),
'sp_venue' => array(),
'sp_league' => array(),
'sp_season' => array(),
'sp_venue' => array(),
'sp_position' => array(),
'sp_role' => array(),
'sp_event' => array(),
'sp_role' => array(),
'sp_event' => array(),
'sp_calendar' => array(),
'sp_team' => array(),
'sp_table' => array(),
'sp_player' => array(),
'sp_list' => array(),
'sp_staff' => array(),
'sp_team' => array(),
'sp_table' => array(),
'sp_player' => array(),
'sp_list' => array(),
'sp_staff' => array(),
);
// Terms to insert
@@ -44,33 +44,33 @@ class SP_Admin_Sample_Data {
$taxonomies['sp_league'] = array( _x( 'Primary League', 'example', 'sportspress' ), _x( 'Secondary League', 'example', 'sportspress' ) );
// Seasons
$current_year = date( 'Y' );
$current_year = intval( $current_year );
$current_year = date( 'Y' );
$current_year = intval( $current_year );
$taxonomies['sp_season'] = array( $current_year - 1, $current_year, $current_year + 1 );
// Venues
$taxonomies['sp_venue'] = array(
$taxonomies['sp_venue'] = array(
array(
'name' => 'Bentleigh',
'meta' => array(
'sp_address' => '12A Bolinda Street, Bentleigh VIC 3204, Australia',
'sp_latitude' => -37.920537,
'sp_address' => '12A Bolinda Street, Bentleigh VIC 3204, Australia',
'sp_latitude' => -37.920537,
'sp_longitude' => 145.043199,
),
),
array(
'name' => 'Essendon',
'meta' => array(
'sp_address' => '74 Napier Street, Essendon VIC 3040, Australia',
'sp_latitude' => -37.751940,
'sp_address' => '74 Napier Street, Essendon VIC 3040, Australia',
'sp_latitude' => -37.751940,
'sp_longitude' => 144.919549,
),
),
array(
'name' => 'Kensington',
'meta' => array(
'sp_address' => '50 Altona Street, Kensington, Victoria, Australia',
'sp_latitude' => -37.797789,
'sp_address' => '50 Altona Street, Kensington, Victoria, Australia',
'sp_latitude' => -37.797789,
'sp_longitude' => 144.924709,
),
),
@@ -92,14 +92,21 @@ class SP_Admin_Sample_Data {
}
// Insert term
$inserted = wp_insert_term( $name, $taxonomy, array( 'description' => $name, 'slug' => sanitize_title( $name ) ) );
$inserted = wp_insert_term(
$name,
$taxonomy,
array(
'description' => $name,
'slug' => sanitize_title( $name ),
)
);
// Add meta to term if is array
if ( ! is_wp_error( $inserted ) && is_array( $term ) && array_key_exists( 'meta', $term ) ) {
$t_id = sp_array_value( $inserted, 'term_id', 1 );
$meta = sp_array_value( $term, 'meta' );
update_option( "taxonomy_$t_id", $meta );
// Add to inserted ids array
$inserted_ids[ $taxonomy ][] = $t_id;
}
@@ -113,15 +120,15 @@ class SP_Admin_Sample_Data {
$teams = array(
array(
'name' => 'Bluebirds',
'url' => 'http://tboy.co/bluebirds',
'url' => 'http://tboy.co/bluebirds',
),
array(
'name' => 'Eagles',
'url' => 'http://tboy.co/eagles',
'url' => 'http://tboy.co/eagles',
),
array(
'name' => 'Kangaroos',
'url' => 'http://tboy.co/kangaroos',
'url' => 'http://tboy.co/kangaroos',
),
);
@@ -160,19 +167,35 @@ class SP_Admin_Sample_Data {
* Insert teams
*/
foreach ( $teams as $index => $team ) {
$post['post_title'] = $team['name'];
$post['post_type'] = 'sp_team';
$post['post_status'] = 'publish';
$post['post_title'] = $team['name'];
$post['post_type'] = 'sp_team';
$post['post_status'] = 'publish';
$post['post_content'] = sprintf( $sample_content, __( 'Team', 'sportspress' ), __( 'Teams', 'sportspress' ), add_query_arg( 'post_type', 'sp_team', admin_url( 'edit.php' ) ) );
// Terms
$post['tax_input'] = array();
$taxonomies = array( 'sp_league', 'sp_season' );
$taxonomies = array( 'sp_league', 'sp_season' );
foreach ( $taxonomies as $taxonomy ) {
$post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids' ) );
};
$post['tax_input'][ $taxonomy ] = get_terms(
$taxonomy,
array(
'hide_empty' => 0,
'fields' => 'ids',
)
);
}
$post['tax_input']['sp_venue'] = get_terms( 'sp_venue', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1, 'offset' => $index ) );
$post['tax_input']['sp_venue'] = get_terms(
'sp_venue',
array(
'hide_empty' => 0,
'fields' => 'ids',
'orderby' => 'id',
'order' => 'ASC',
'number' => 1,
'offset' => $index,
)
);
// Insert post
$id = wp_insert_post( $post );
@@ -189,13 +212,13 @@ class SP_Admin_Sample_Data {
// Get columns
$columns = array( 'team' );
$args = array(
'post_type' => array( 'sp_performance', 'sp_statistic' ),
$args = array(
'post_type' => array( 'sp_performance', 'sp_statistic' ),
'posts_per_page' => 2,
'orderby' => 'menu_order',
'order' => 'ASC',
'orderby' => 'menu_order',
'order' => 'ASC',
);
$vars = get_posts( $args );
$vars = get_posts( $args );
foreach ( $vars as $var ) {
$columns[] = $var->post_name;
}
@@ -204,24 +227,39 @@ class SP_Admin_Sample_Data {
* Insert players
*/
foreach ( $players as $index => $name ) {
$post['post_title'] = $name;
$post['post_type'] = 'sp_player';
$post['post_status'] = 'publish';
$post['post_title'] = $name;
$post['post_type'] = 'sp_player';
$post['post_status'] = 'publish';
$post['post_content'] = sprintf( $sample_content, __( 'Player', 'sportspress' ), __( 'Players', 'sportspress' ), add_query_arg( 'post_type', 'sp_player', admin_url( 'edit.php' ) ) );
// Terms
$post['tax_input'] = array();
$taxonomies = array( 'sp_league', 'sp_season' );
$taxonomies = array( 'sp_league', 'sp_season' );
foreach ( $taxonomies as $taxonomy ) {
$post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids' ) );
};
$post['tax_input'][ $taxonomy ] = get_terms(
$taxonomy,
array(
'hide_empty' => 0,
'fields' => 'ids',
)
);
}
$taxonomies = array( 'sp_position' );
foreach ( $taxonomies as $taxonomy ) {
$terms = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'slug', 'number' => 1, 'offset' => $index % 4 ) );
$terms = get_terms(
$taxonomy,
array(
'hide_empty' => 0,
'fields' => 'ids',
'orderby' => 'slug',
'number' => 1,
'offset' => $index % 4,
)
);
if ( $terms && ! is_wp_error( $terms ) ) {
$post['tax_input'][ $taxonomy ] = $terms;
}
};
}
// Insert post
$id = wp_insert_post( $post );
@@ -233,13 +271,13 @@ class SP_Admin_Sample_Data {
update_post_meta( $id, '_sp_sample', 1 );
// Calculate meta
$nationality = array_rand( $countries->countries );
$team_index = floor( $index / 4 );
$nationality = array_rand( $countries->countries );
$team_index = floor( $index / 4 );
$past_team_index = ( $team_index + 1 ) % 3;
$current_team = sp_array_value( $inserted_ids['sp_team'], $team_index, 0 );
$past_team = sp_array_value( $inserted_ids['sp_team'], $past_team_index, 0 );
$primary_league = reset( $post['tax_input']['sp_league'] );
$season_teams = $season_stats = array();
$current_team = sp_array_value( $inserted_ids['sp_team'], $team_index, 0 );
$past_team = sp_array_value( $inserted_ids['sp_team'], $past_team_index, 0 );
$primary_league = reset( $post['tax_input']['sp_league'] );
$season_teams = $season_stats = array();
foreach ( $post['tax_input']['sp_season'] as $season_index => $season_id ) {
$season_stats[ $season_id ] = array();
if ( $season_index == 0 ) {
@@ -253,7 +291,7 @@ class SP_Admin_Sample_Data {
}
}
}
$player_stats = array( $primary_league => $season_stats );
$player_stats = array( $primary_league => $season_stats );
$player_leagues = array( $primary_league => $season_teams );
// Update meta
@@ -268,30 +306,32 @@ class SP_Admin_Sample_Data {
}
// Get columns
$columns = array();
$args = array(
'post_type' => 'sp_performance',
$columns = array();
$args = array(
'post_type' => 'sp_performance',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'orderby' => 'menu_order',
'order' => 'ASC',
);
$performance_posts = get_posts( $args );
foreach ( $performance_posts as $performance_post ) {
if ( sizeof( $columns ) >= 5 ) continue;
if ( sizeof( $columns ) >= 5 ) {
continue;
}
$columns[] = $performance_post->post_name;
}
$args = array(
'post_type' => 'sp_result',
$args = array(
'post_type' => 'sp_result',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'orderby' => 'menu_order',
'order' => 'ASC',
);
$result_posts = get_posts( $args );
$args = array(
'post_type' => 'sp_outcome',
$result_posts = get_posts( $args );
$args = array(
'post_type' => 'sp_outcome',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'orderby' => 'menu_order',
'order' => 'ASC',
);
$outcome_posts = get_posts( $args );
@@ -299,22 +339,37 @@ class SP_Admin_Sample_Data {
* Insert staff
*/
foreach ( $staff as $index => $name ) {
$post['post_title'] = $name;
$post['post_type'] = 'sp_staff';
$post['post_status'] = 'publish';
$post['post_title'] = $name;
$post['post_type'] = 'sp_staff';
$post['post_status'] = 'publish';
$post['post_content'] = sprintf( $sample_content, __( 'Staff', 'sportspress' ), __( 'Staff', 'sportspress' ), add_query_arg( 'post_type', 'sp_staff', admin_url( 'edit.php' ) ) );
// Terms
$post['tax_input'] = array();
$taxonomies = array( 'sp_league', 'sp_season' );
$taxonomies = array( 'sp_league', 'sp_season' );
foreach ( $taxonomies as $taxonomy ) {
$post['tax_input'][ $taxonomy ] = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids' ) );
};
$post['tax_input'][ $taxonomy ] = get_terms(
$taxonomy,
array(
'hide_empty' => 0,
'fields' => 'ids',
)
);
}
$taxonomies = array( 'sp_role' );
foreach ( $taxonomies as $taxonomy ) {
$terms = get_terms( $taxonomy, array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'slug', 'number' => 1, 'offset' => $index % 4 ) );
$terms = get_terms(
$taxonomy,
array(
'hide_empty' => 0,
'fields' => 'ids',
'orderby' => 'slug',
'number' => 1,
'offset' => $index % 4,
)
);
$post['tax_input'][ $taxonomy ] = $terms;
};
}
// Insert post
$id = wp_insert_post( $post );
@@ -326,8 +381,8 @@ class SP_Admin_Sample_Data {
update_post_meta( $id, '_sp_sample', 1 );
// Calculate meta
$team_index = floor( $index / 4 );
$past_teams = $inserted_ids['sp_team'];
$team_index = floor( $index / 4 );
$past_teams = $inserted_ids['sp_team'];
$current_team = sp_array_value( $past_teams, $team_index, 0 );
unset( $past_teams[ $team_index ] );
@@ -347,27 +402,67 @@ class SP_Admin_Sample_Data {
// Determine team index and post status
$i = $index % 3;
if ( $index < 3 ) {
$post_status = 'publish';
$post_year = $current_year - 1;
$event_season = get_terms( 'sp_season', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) );
$post_status = 'publish';
$post_year = $current_year - 1;
$event_season = get_terms(
'sp_season',
array(
'hide_empty' => 0,
'fields' => 'ids',
'orderby' => 'id',
'order' => 'ASC',
'number' => 1,
)
);
} else {
$post_status = 'future';
$post_year = $current_year + 1;
$event_season = get_terms( 'sp_season', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'DESC', 'number' => 1 ) );
$post_status = 'future';
$post_year = $current_year + 1;
$event_season = get_terms(
'sp_season',
array(
'hide_empty' => 0,
'fields' => 'ids',
'orderby' => 'id',
'order' => 'DESC',
'number' => 1,
)
);
}
// The away team should be the next inserted team, or the first if this is the last event
if ( $i == 2 ) $away_index = 0;
else $away_index = $i + 1;
if ( $i == 2 ) {
$away_index = 0;
} else {
$away_index = $i + 1;
}
$post = array(
'post_title' => $teams[ $i ]['name'] . ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ' . $teams[ $away_index ]['name'],
'post_type' => 'sp_event',
'post_status' => $post_status,
'post_title' => $teams[ $i ]['name'] . ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ' . $teams[ $away_index ]['name'],
'post_type' => 'sp_event',
'post_status' => $post_status,
'post_content' => sprintf( $sample_content, __( 'Event', 'sportspress' ), __( 'Events', 'sportspress' ), add_query_arg( 'post_type', 'sp_event', admin_url( 'edit.php' ) ) ),
'post_date' => $post_year . '-' . sprintf( '%02d', 3 + $i * 3 ) . '-' . sprintf( '%02d', 5 + $i * 10 ) . ' ' . ( 18 + $i ) . ':00:00',
'tax_input' => array(
'sp_league' => get_terms( 'sp_league', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) ),
'post_date' => $post_year . '-' . sprintf( '%02d', 3 + $i * 3 ) . '-' . sprintf( '%02d', 5 + $i * 10 ) . ' ' . ( 18 + $i ) . ':00:00',
'tax_input' => array(
'sp_league' => get_terms(
'sp_league',
array(
'hide_empty' => 0,
'fields' => 'ids',
'orderby' => 'id',
'order' => 'ASC',
'number' => 1,
)
),
'sp_season' => $event_season,
'sp_venue' => get_terms( 'sp_venue', array( 'hide_empty' => 0, 'fields' => 'ids', 'orderby' => 'id', 'order' => 'ASC', 'number' => 1, 'offset' => $i ) ),
'sp_venue' => get_terms(
'sp_venue',
array(
'hide_empty' => 0,
'fields' => 'ids',
'orderby' => 'id',
'order' => 'ASC',
'number' => 1,
'offset' => $i,
)
),
),
);
@@ -383,23 +478,23 @@ class SP_Admin_Sample_Data {
// Calculate home and away team ids
$home_team_index = ( $i ) % 3;
$away_team_index = ( $i + 1 ) % 3;
$home_team_id = sp_array_value( $inserted_ids['sp_team'], $home_team_index, 0 );
$away_team_id = sp_array_value( $inserted_ids['sp_team'], $away_team_index, 0 );
$event_teams = array(
$home_team_id = sp_array_value( $inserted_ids['sp_team'], $home_team_index, 0 );
$away_team_id = sp_array_value( $inserted_ids['sp_team'], $away_team_index, 0 );
$event_teams = array(
$home_team_id,
$away_team_id,
);
// Initialize meta
$event_players = array( 0 );
$performance = $results = array();
$performance = $results = array();
if ( $home_team_id ) {
// Add home team player performance
$performance[ $home_team_id ] = array();
for ( $j = 0; $j < 4; $j ++ ) {
$player_id = sp_array_value( $inserted_ids['sp_player'], $home_team_index * 4 + $j );
$event_players[] = $player_id;
$player_id = sp_array_value( $inserted_ids['sp_player'], $home_team_index * 4 + $j );
$event_players[] = $player_id;
$player_performance = array();
foreach ( $performance_posts as $performance_post ) {
$player_performance[ $performance_post->post_name ] = rand( 0, 1 );
@@ -413,7 +508,9 @@ class SP_Admin_Sample_Data {
$results[ $home_team_id ][ $result_post->post_name ] = 1 + $result_post_index;
}
$outcome = reset( $outcome_posts );
if ( is_object( $outcome ) ) $results[ $home_team_id ]['outcome'] = array( $outcome->post_name );
if ( is_object( $outcome ) ) {
$results[ $home_team_id ]['outcome'] = array( $outcome->post_name );
}
}
// Separate teams with zero
@@ -422,8 +519,8 @@ class SP_Admin_Sample_Data {
if ( $away_team_id ) {
$performance[ $away_team_id ] = array();
for ( $j = 0; $j < 4; $j ++ ) {
$player_id = sp_array_value( $inserted_ids['sp_player'], $away_team_index * 4 + $j );
$event_players[] = $player_id;
$player_id = sp_array_value( $inserted_ids['sp_player'], $away_team_index * 4 + $j );
$event_players[] = $player_id;
$player_performance = array();
foreach ( $performance_posts as $performance_post ) {
$player_performance[ $performance_post->post_name ] = rand( 0, 1 );
@@ -437,15 +534,17 @@ class SP_Admin_Sample_Data {
$results[ $away_team_id ][ $result_post->post_name ] = '0';
}
$outcome = next( $outcome_posts );
if ( is_object( $outcome ) ) $results[ $away_team_id ]['outcome'] = array( $outcome->post_name );
if ( is_object( $outcome ) ) {
$results[ $away_team_id ]['outcome'] = array( $outcome->post_name );
}
}
if ( 'publish' === $post_status ) {
// Swap results for last event only
if ( $i == 2 ) {
$k = array_keys( $results );
$v = array_values( $results );
$rv = array_reverse( $v );
$k = array_keys( $results );
$v = array_values( $results );
$rv = array_reverse( $v );
$results = array_combine( $k, $rv );
}
@@ -466,10 +565,10 @@ class SP_Admin_Sample_Data {
* Insert calendar
*/
$post = array(
'post_title' => _x( 'Fixtures & Results', 'example', 'sportspress' ),
'post_type' => 'sp_calendar',
'post_status' => 'publish',
'post_content' => sprintf( $sample_content, __( 'Calendar', 'sportspress' ), __( 'Calendars', 'sportspress' ), add_query_arg( 'post_type', 'sp_calendar', admin_url( 'edit.php' ) ) )
'post_title' => _x( 'Fixtures & Results', 'example', 'sportspress' ),
'post_type' => 'sp_calendar',
'post_status' => 'publish',
'post_content' => sprintf( $sample_content, __( 'Calendar', 'sportspress' ), __( 'Calendars', 'sportspress' ), add_query_arg( 'post_type', 'sp_calendar', admin_url( 'edit.php' ) ) ),
);
// Insert post
@@ -495,16 +594,32 @@ class SP_Admin_Sample_Data {
/*
* Insert league table
*/
$leagues = get_terms( 'sp_league', array( 'hide_empty' => 0, 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) );
$league = reset( $leagues );
$seasons = get_terms( 'sp_season', array( 'hide_empty' => 0, 'orderby' => 'id', 'order' => 'ASC', 'number' => 1 ) );
$season = reset( $seasons );
$post = array(
'post_title' => $league->name . ' ' . $season->name,
'post_type' => 'sp_table',
'post_status' => 'publish',
$leagues = get_terms(
'sp_league',
array(
'hide_empty' => 0,
'orderby' => 'id',
'order' => 'ASC',
'number' => 1,
)
);
$league = reset( $leagues );
$seasons = get_terms(
'sp_season',
array(
'hide_empty' => 0,
'orderby' => 'id',
'order' => 'ASC',
'number' => 1,
)
);
$season = reset( $seasons );
$post = array(
'post_title' => $league->name . ' ' . $season->name,
'post_type' => 'sp_table',
'post_status' => 'publish',
'post_content' => sprintf( $sample_content, __( 'League Table', 'sportspress' ), __( 'League Tables', 'sportspress' ), add_query_arg( 'post_type', 'sp_table', admin_url( 'edit.php' ) ) ),
'tax_input' => array(
'tax_input' => array(
'sp_league' => $league->term_id,
'sp_season' => $season->term_id,
),
@@ -520,12 +635,12 @@ class SP_Admin_Sample_Data {
update_post_meta( $id, '_sp_sample', 1 );
// Get columns
$columns = array();
$args = array(
'post_type' => 'sp_column',
$columns = array();
$args = array(
'post_type' => 'sp_column',
'posts_per_page' => 8,
'orderby' => 'menu_order',
'order' => 'ASC',
'orderby' => 'menu_order',
'order' => 'ASC',
);
$column_posts = get_posts( $args );
foreach ( $column_posts as $column_post ) {
@@ -542,9 +657,9 @@ class SP_Admin_Sample_Data {
*/
foreach ( $inserted_ids['sp_team'] as $index => $team_id ) {
$post = array(
'post_title' => get_the_title( $team_id ) . ' ' . _x( 'Roster', 'example', 'sportspress' ),
'post_type' => 'sp_list',
'post_status' => 'publish',
'post_title' => get_the_title( $team_id ) . ' ' . _x( 'Roster', 'example', 'sportspress' ),
'post_type' => 'sp_list',
'post_status' => 'publish',
'post_content' => sprintf( $sample_content, __( 'Player List', 'sportspress' ), __( 'Player Lists', 'sportspress' ), add_query_arg( 'post_type', 'sp_list', admin_url( 'edit.php' ) ) ),
);
@@ -561,12 +676,12 @@ class SP_Admin_Sample_Data {
$list_players = array_slice( $inserted_ids['sp_player'], $index * 4, 4 );
// Get columns
$columns = array();
$args = array(
'post_type' => array( 'sp_metric' ),
$columns = array();
$args = array(
'post_type' => array( 'sp_metric' ),
'posts_per_page' => 2,
'orderby' => 'menu_order',
'order' => 'ASC',
'orderby' => 'menu_order',
'order' => 'ASC',
);
$column_posts = get_posts( $args );
foreach ( $column_posts as $column_post ) {
@@ -587,9 +702,9 @@ class SP_Admin_Sample_Data {
* Insert player list for player ranking
*/
$post = array(
'post_title' => _x( 'Player Ranking', 'example', 'sportspress' ),
'post_type' => 'sp_list',
'post_status' => 'publish',
'post_title' => _x( 'Player Ranking', 'example', 'sportspress' ),
'post_type' => 'sp_list',
'post_status' => 'publish',
'post_content' => sprintf( $sample_content, __( 'Player List', 'sportspress' ), __( 'Player Lists', 'sportspress' ), add_query_arg( 'post_type', 'sp_list', admin_url( 'edit.php' ) ) ),
);
@@ -603,9 +718,11 @@ class SP_Admin_Sample_Data {
update_post_meta( $id, '_sp_sample', 1 );
// Get columns
$columns = array( 'team' );
$columns = array( 'team' );
$performance_post = reset( $performance_posts );
if ( is_object( $performance_post ) ) $columns[] = $performance_post->post_name;
if ( is_object( $performance_post ) ) {
$columns[] = $performance_post->post_name;
}
// Update meta
update_post_meta( $id, 'sp_format', 'list' );
@@ -613,7 +730,9 @@ class SP_Admin_Sample_Data {
update_post_meta( $id, 'sp_columns', $columns );
update_post_meta( $id, 'sp_grouping', '0' );
update_post_meta( $id, 'sp_order', 'DESC' );
if ( is_object( $performance_post ) ) update_post_meta( $id, 'sp_orderby', $performance_post->post_name );
if ( is_object( $performance_post ) ) {
update_post_meta( $id, 'sp_orderby', $performance_post->post_name );
}
/*
* Update player list and league table per team
@@ -631,21 +750,21 @@ class SP_Admin_Sample_Data {
*/
public static function delete_posts() {
$post_types = sp_post_types();
$args = array(
'post_type' => $post_types,
$args = array(
'post_type' => $post_types,
'posts_per_page' => -1,
'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ),
'meta_query' => array(
'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ),
'meta_query' => array(
array(
'key' => '_sp_sample',
'value' => 1
)
'key' => '_sp_sample',
'value' => 1,
),
),
);
// Delete posts
$old_posts = get_posts( $args );
foreach( $old_posts as $post ):
foreach ( $old_posts as $post ) :
wp_delete_post( $post->ID, true );
endforeach;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -4,11 +4,11 @@
*
* The SportsPress admin sports class stores preset sport data.
*
* @class SP_Admin_Sports
* @version 2.6
* @package SportsPress/Admin
* @category Class
* @author ThemeBoy
* @class SP_Admin_Sports
* @version 2.6
* @package SportsPress/Admin
* @category Class
* @author ThemeBoy
*/
class SP_Admin_Sports {
@@ -20,18 +20,18 @@ class SP_Admin_Sports {
*/
public static function get_presets() {
if ( empty( self::$presets ) ) {
$presets = array();
$presets = array();
self::$options = array(
'team-sports' => array(),
'team-sports' => array(),
'racket-sports' => array(),
'water-sports' => array(),
'water-sports' => array(),
'target-sports' => array(),
'esports' => array(),
'other' => array(),
'esports' => array(),
'other' => array(),
);
foreach ( self::$options as $slug => $options ) {
$dir = scandir( SP()->plugin_path() . '/presets/' . $slug );
$dir = scandir( SP()->plugin_path() . '/presets/' . $slug );
$files = array();
if ( $dir ) {
foreach ( $dir as $key => $value ) {
@@ -40,13 +40,15 @@ class SP_Admin_Sports {
}
}
}
foreach( $files as $file ) {
foreach ( $files as $file ) {
$json_data = file_get_contents( SP()->plugin_path() . '/presets/' . $slug . '/' . $file );
$data = json_decode( $json_data, true );
if ( ! is_array( $data ) ) continue;
$id = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file );
$data = json_decode( $json_data, true );
if ( ! is_array( $data ) ) {
continue;
}
$id = preg_replace( '/\\.[^.\\s]{3,4}$/', '', $file );
$presets[ $id ] = $data;
$name = array_key_exists( 'name', $data ) ? __( $data['name'], 'sportspress' ) : $id;
$name = array_key_exists( 'name', $data ) ? __( $data['name'], 'sportspress' ) : $id;
// Conditionally append filename in parentheses for clarity
if ( false === strpos( str_replace( ' ', '', strtolower( $data['name'] ) ), str_replace( '-', '', $id ) ) ) {
@@ -69,15 +71,19 @@ class SP_Admin_Sports {
public static function get_preset( $id ) {
$json_data = @file_get_contents( SP()->plugin_path() . '/presets/' . $id . '.json', true );
if ( $json_data ) return json_decode( $json_data, true );
if ( $json_data ) {
return json_decode( $json_data, true );
}
$dir = scandir( SP()->plugin_path() . '/presets' );
if ( $dir ) {
foreach ( $dir as $key => $value ) {
if ( substr( $value, 0, 1 ) !== '.' && strpos( $value, '.' ) === false ) {
$json_data = @file_get_contents( SP()->plugin_path() . '/presets/' . $value . '/' . $id . '.json', true );
if ( $json_data ) return json_decode( $json_data, true );
if ( $json_data ) {
return json_decode( $json_data, true );
}
}
}
}
@@ -99,19 +105,21 @@ class SP_Admin_Sports {
// Positions
$positions = sp_array_value( $preset, 'positions', array() );
$i = 0;
$i = 0;
foreach ( $positions as $position ) {
if ( is_string( $position ) ) {
$name = $position;
$name = $position;
$sections = array( 0, 1 );
} else {
$name = sp_array_value( $position, 'name', __( 'Position', 'sportspress' ) );
$name = sp_array_value( $position, 'name', __( 'Position', 'sportspress' ) );
$sections = sp_array_value( $position, 'sections', array( 0, 1 ) );
}
$term = wp_insert_term( $name, 'sp_position' );
if ( is_wp_error( $term ) ) continue;
$t_id = $term['term_id'];
$term_meta = get_option( "taxonomy_$t_id" );
if ( is_wp_error( $term ) ) {
continue;
}
$t_id = $term['term_id'];
$term_meta = get_option( "taxonomy_$t_id" );
$term_meta['sp_sections'] = $sections;
update_option( "taxonomy_$t_id", $term_meta );
update_term_meta( $t_id, 'sp_order', $i + 1 );
@@ -120,11 +128,13 @@ class SP_Admin_Sports {
// Outcomes
$post_type = 'sp_outcome';
$outcomes = sp_array_value( $preset, 'outcomes', array() );
$outcomes = sp_array_value( $preset, 'outcomes', array() );
self::delete_preset_posts( $post_type );
foreach ( $outcomes as $index => $outcome ) {
$post = self::get_post_array( $outcome, $post_type );
if ( empty( $post ) ) continue;
if ( empty( $post ) ) {
continue;
}
$id = self::insert_preset_post( $post, $index );
update_post_meta( $id, 'sp_abbreviation', sp_array_value( $outcome, 'abbreviation', null ) );
update_post_meta( $id, 'sp_condition', sp_array_value( $outcome, 'condition', null ) );
@@ -132,14 +142,18 @@ class SP_Admin_Sports {
// Results
$post_type = 'sp_result';
$results = sp_array_value( $preset, 'results', array() );
$results = sp_array_value( $preset, 'results', array() );
self::delete_preset_posts( $post_type );
$primary_result = 0;
foreach ( $results as $index => $result ) {
$post = self::get_post_array( $result, $post_type );
if ( empty( $post ) ) continue;
if ( empty( $post ) ) {
continue;
}
$id = self::insert_preset_post( $post, $index );
if ( is_array( $result ) && array_key_exists( 'primary', $result ) ) $primary_result = $post['post_name'];
if ( is_array( $result ) && array_key_exists( 'primary', $result ) ) {
$primary_result = $post['post_name'];
}
update_post_meta( $id, 'sp_equation', sp_array_value( $result, 'equation', null ) );
}
@@ -147,12 +161,14 @@ class SP_Admin_Sports {
$i = 0;
// Performance
$post_type = 'sp_performance';
$post_type = 'sp_performance';
$performances = sp_array_value( $preset, 'performance', array() );
self::delete_preset_posts( $post_type );
foreach ( $performances as $index => $performance ) {
$post = self::get_post_array( $performance, $post_type );
if ( empty( $post ) ) continue;
if ( empty( $post ) ) {
continue;
}
$id = self::insert_preset_post( $post, $index );
if ( isset( $performance['position'] ) ) {
wp_set_object_terms( $id, $performance['position'], 'sp_position', false );
@@ -170,11 +186,13 @@ class SP_Admin_Sports {
// Columns
$post_type = 'sp_column';
$columns = sp_array_value( $preset, 'columns', array() );
$columns = sp_array_value( $preset, 'columns', array() );
self::delete_preset_posts( $post_type );
foreach ( $columns as $index => $column ) {
$post = self::get_post_array( $column, $post_type );
if ( empty( $post ) ) continue;
if ( empty( $post ) ) {
continue;
}
$id = self::insert_preset_post( $post, $index );
update_post_meta( $id, 'sp_equation', sp_array_value( $column, 'equation', null ) );
update_post_meta( $id, 'sp_precision', sp_array_value( $column, 'precision', 0 ) );
@@ -184,40 +202,45 @@ class SP_Admin_Sports {
// Metrics
$post_type = 'sp_metric';
$metrics = sp_array_value( $preset, 'metrics', array() );
$metrics = sp_array_value( $preset, 'metrics', array() );
self::delete_preset_posts( $post_type );
foreach ( $metrics as $index => $metric ) {
$post = self::get_post_array( $metric, $post_type );
if ( empty( $post ) ) continue;
if ( empty( $post ) ) {
continue;
}
$id = self::insert_preset_post( $post, $i + $index );
$i ++;
}
// Event Specs
$post_type = 'sp_spec';
$specs = sp_array_value( $preset, 'specs', array() );
$specs = sp_array_value( $preset, 'specs', array() );
self::delete_preset_posts( $post_type );
foreach ( $specs as $index => $spec ) {
$post = self::get_post_array( $spec, $post_type );
if ( empty( $post ) ) continue;
if ( empty( $post ) ) {
continue;
}
$id = self::insert_preset_post( $post, $i + $index );
$i ++;
}
// Statistics
$post_type = 'sp_statistic';
$post_type = 'sp_statistic';
$statistics = sp_array_value( $preset, 'statistics', array() );
self::delete_preset_posts( $post_type );
foreach ( $statistics as $index => $statistic ) {
$post = self::get_post_array( $statistic, $post_type );
if ( empty( $post ) ) continue;
if ( empty( $post ) ) {
continue;
}
$id = self::insert_preset_post( $post, $i + $index );
update_post_meta( $id, 'sp_equation', sp_array_value( $statistic, 'equation', null ) );
update_post_meta( $id, 'sp_precision', sp_array_value( $statistic, 'precision', 0 ) );
update_post_meta( $id, 'sp_type', sp_array_value( $statistic, 'type', 'total' ) );
}
// Options
$options = sp_array_value( $preset, 'options', array() );
foreach ( $options as $option => $value ) {
@@ -230,20 +253,20 @@ class SP_Admin_Sports {
public static function delete_preset_posts( $post_type = null ) {
$args = array(
'post_type' => $post_type,
'post_type' => $post_type,
'posts_per_page' => -1,
'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ),
'meta_query' => array(
'post_status' => array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ),
'meta_query' => array(
array(
'key' => '_sp_preset',
'value' => 1
)
)
'key' => '_sp_preset',
'value' => 1,
),
),
);
// Delete posts
$old_posts = get_posts( $args );
foreach( $old_posts as $post ):
foreach ( $old_posts as $post ) :
wp_delete_post( $post->ID, true );
endforeach;
}
@@ -252,15 +275,19 @@ class SP_Admin_Sports {
$post_array = array();
if ( is_string( $post ) ) {
$post_array['post_title'] = $post;
$post_array['post_name'] = sp_get_eos_safe_slug( $post_array['post_title'] );
$post_array['post_name'] = sp_get_eos_safe_slug( $post_array['post_title'] );
} elseif ( is_array( $post ) ) {
if ( ! array_key_exists( 'name', $post ) ) $post_array = array();
if ( ! array_key_exists( 'name', $post ) ) {
$post_array = array();
}
$post_array['post_title'] = $post['name'];
$post_array['post_name'] = sp_array_value( $post, 'id', sp_get_eos_safe_slug( $post_array['post_title'] ) );
$post_array['post_name'] = sp_array_value( $post, 'id', sp_get_eos_safe_slug( $post_array['post_title'] ) );
}
// Return empty array if post with same slug already exists
if ( get_page_by_path( $post_array['post_name'], OBJECT, $post_type ) ) return array();
if ( get_page_by_path( $post_array['post_name'], OBJECT, $post_type ) ) {
return array();
}
// Set post type
$post_array['post_type'] = $post_type;
@@ -275,9 +302,9 @@ class SP_Admin_Sports {
public static function insert_preset_post( $post, $index = 0 ) {
// Increment menu order by 10 and publish post
$post['menu_order'] = $index * 10 + 10;
$post['menu_order'] = $index * 10 + 10;
$post['post_status'] = 'publish';
$id = wp_insert_post( $post );
$id = wp_insert_post( $post );
// Flag as preset
update_post_meta( $id, '_sp_preset', 1 );
@@ -287,21 +314,26 @@ class SP_Admin_Sports {
/**
* Sport category names
*
* @return null
*/
public static function sport_category_names() {
return apply_filters( 'sportspress_sport_categories', array(
'team-sports' => __( 'Team Sports', 'sportspress' ),
'racket-sports' => __( 'Racket Sports', 'sportspress' ),
'water-sports' => __( 'Water Sports', 'sportspress' ),
'target-sports' => __( 'Target Sports', 'sportspress' ),
'esports' => __( 'Esports', 'sportspress' ),
'other' => __( 'Other', 'sportspress' ),
) );
return apply_filters(
'sportspress_sport_categories',
array(
'team-sports' => __( 'Team Sports', 'sportspress' ),
'racket-sports' => __( 'Racket Sports', 'sportspress' ),
'water-sports' => __( 'Water Sports', 'sportspress' ),
'target-sports' => __( 'Target Sports', 'sportspress' ),
'esports' => __( 'Esports', 'sportspress' ),
'other' => __( 'Other', 'sportspress' ),
)
);
}
/**
* Sport preset names for localization
*
* @return null
*/
public static function sport_preset_names() {

View File

@@ -2,75 +2,78 @@
/**
* Debug/Status page
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 1.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Admin_Status' ) ) :
/**
* SP_Admin_Status Class
*/
class SP_Admin_Status {
/**
* Retrieve metadata from a file. Based on WP Core's get_file_data function
*
* @since 0.8
* @param string $file Path to the file
* @param array $all_headers List of headers, in the format array('HeaderKey' => 'Header Name')
* SP_Admin_Status Class
*/
public function get_file_version( $file ) {
// We don't need to write to the file, so just open for reading.
$fp = fopen( $file, 'r' );
class SP_Admin_Status {
// Pull only the first 8kiB of the file in.
$file_data = fread( $fp, 8192 );
/**
* Retrieve metadata from a file. Based on WP Core's get_file_data function
*
* @since 0.8
* @param string $file Path to the file
* @param array $all_headers List of headers, in the format array('HeaderKey' => 'Header Name')
*/
public function get_file_version( $file ) {
// We don't need to write to the file, so just open for reading.
$fp = fopen( $file, 'r' );
// PHP will close file handle, but we are good citizens.
fclose( $fp );
// Pull only the first 8kiB of the file in.
$file_data = fread( $fp, 8192 );
// Make sure we catch CR-only line endings.
$file_data = str_replace( "\r", "\n", $file_data );
$version = '';
// PHP will close file handle, but we are good citizens.
fclose( $fp );
if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] )
$version = _cleanup_header_comment( $match[1] );
// Make sure we catch CR-only line endings.
$file_data = str_replace( "\r", "\n", $file_data );
$version = '';
return $version ;
}
/**
* Scan the template files
*
* @access public
* @param string $template_path
* @return array
*/
public function scan_template_files( $template_path ) {
$files = scandir( $template_path );
$result = array();
if ( $files ) {
foreach ( $files as $key => $value ) {
if ( ! in_array( $value, array( ".",".." ) ) ) {
if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) {
$sub_files = $this->scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value );
foreach ( $sub_files as $sub_file ) {
$result[] = $value . DIRECTORY_SEPARATOR . $sub_file;
if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] ) {
$version = _cleanup_header_comment( $match[1] );
}
return $version;
}
/**
* Scan the template files
*
* @access public
* @param string $template_path
* @return array
*/
public function scan_template_files( $template_path ) {
$files = scandir( $template_path );
$result = array();
if ( $files ) {
foreach ( $files as $key => $value ) {
if ( ! in_array( $value, array( '.', '..' ) ) ) {
if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) {
$sub_files = $this->scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value );
foreach ( $sub_files as $sub_file ) {
$result[] = $value . DIRECTORY_SEPARATOR . $sub_file;
}
} else {
$result[] = $value;
}
} else {
$result[] = $value;
}
}
}
return $result;
}
return $result;
}
}
endif;

View File

@@ -6,11 +6,11 @@ if ( ! defined( 'ABSPATH' ) ) {
/**
* Handles taxonomies in admin
*
* @class SP_Admin_Taxonomies
* @version 2.7.9
* @package SportsPress/Admin
* @category Class
* @author ThemeBoy
* @class SP_Admin_Taxonomies
* @version 2.7.9
* @package SportsPress/Admin
* @category Class
* @author ThemeBoy
*/
class SP_Admin_Taxonomies {
@@ -71,7 +71,7 @@ class SP_Admin_Taxonomies {
* @param mixed $term Term (category) being edited
*/
public function edit_taxonomy_fields( $term ) {
$t_id = $term->term_id;
$t_id = $term->term_id;
?>
<?php if ( function_exists( 'get_term_meta' ) ) { ?>
<?php $order = get_term_meta( $t_id, 'sp_order', true ); ?>
@@ -80,7 +80,7 @@ class SP_Admin_Taxonomies {
<td><input name="sp_order" class="sp-number-input" type="text" step="1" size="4" id="sp_order" value="<?php echo (int) $order; ?>"></td>
</tr>
<?php } ?>
<?php
<?php
}
/**
@@ -91,25 +91,25 @@ class SP_Admin_Taxonomies {
*/
public function add_venue_fields() {
$args = array(
'orderby' => 'id',
'order' => 'DESC',
'orderby' => 'id',
'order' => 'DESC',
'hide_empty' => false,
'number' => 1,
'number' => 1,
);
// Get latitude and longitude from the last added venue
$terms = get_terms( 'sp_venue', $args );
if ( $terms && array_key_exists( 0, $terms) && is_object( reset( $terms ) ) ):
$term = reset( $terms );
$t_id = $term->term_id;
if ( $terms && array_key_exists( 0, $terms ) && is_object( reset( $terms ) ) ) :
$term = reset( $terms );
$t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$latitude = sp_array_value( $term_meta, 'sp_latitude', '-37.8165647' );
$latitude = sp_array_value( $term_meta, 'sp_latitude', '-37.8165647' );
$longitude = sp_array_value( $term_meta, 'sp_longitude', '144.9475055' );
$address = sp_array_value( $term_meta, 'sp_address', '' );
$address = sp_array_value( $term_meta, 'sp_address', '' );
endif;
// Sanitize latitude and longitude, fallback to default.
if( ! is_numeric( $latitude) || ! is_numeric( $longitude) ):
$latitude = '-37.8165647';
if ( ! is_numeric( $latitude ) || ! is_numeric( $longitude ) ) :
$latitude = '-37.8165647';
$longitude = '144.9475055';
endif;
?>
@@ -129,7 +129,7 @@ class SP_Admin_Taxonomies {
<label for="term_meta[sp_longitude]"><?php _e( 'Longitude', 'sportspress' ); ?></label>
<input type="text" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo esc_attr( $longitude ); ?>">
</div>
<?php
<?php
do_action( 'sp_admin_geocoder_scripts' );
}
@@ -140,11 +140,11 @@ class SP_Admin_Taxonomies {
* @param mixed $term Term (category) being edited
*/
public function edit_venue_fields( $term ) {
$t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$latitude = is_numeric( $term_meta['sp_latitude'] ) ? $term_meta['sp_latitude'] : '';
$t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$latitude = is_numeric( $term_meta['sp_latitude'] ) ? $term_meta['sp_latitude'] : '';
$longitude = is_numeric( $term_meta['sp_longitude'] ) ? $term_meta['sp_longitude'] : '';
$address = $term_meta['sp_address'] ? $term_meta['sp_address'] : '';
$address = $term_meta['sp_address'] ? $term_meta['sp_address'] : '';
?>
<tr class="form-field">
<td colspan="2">
@@ -170,7 +170,7 @@ class SP_Admin_Taxonomies {
<input type="text" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo esc_attr( $longitude ); ?>">
</td>
</tr>
<?php
<?php
do_action( 'sp_admin_geocoder_scripts' );
}
@@ -184,16 +184,29 @@ class SP_Admin_Taxonomies {
?>
<div class="form-field">
<label><?php _e( 'Statistics', 'sportspress' ); ?></label>
<select name="term_meta[sp_sections][]" id="term_meta[sp_sections][]" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>" multiple="multiple">
<select name="term_meta[sp_sections][]" id="term_meta[sp_sections][]" class="widefat chosen-select
<?php
if ( is_rtl() ) :
?>
chosen-rtl<?php endif; ?>" multiple="multiple">
<?php
$options = apply_filters( 'sportspress_performance_sections', array( 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
foreach ( $options as $key => $value ):
$options = apply_filters(
'sportspress_performance_sections',
array(
0 => __( 'Offense', 'sportspress' ),
1 => __(
'Defense',
'sportspress'
),
)
);
foreach ( $options as $key => $value ) :
printf( '<option value="%s" %s>%s</option>', $key, selected( true ), $value );
endforeach;
?>
</select>
</div>
<?php
<?php
}
/**
@@ -203,17 +216,30 @@ class SP_Admin_Taxonomies {
* @param mixed $term Term (category) being edited
*/
public function edit_position_fields( $term ) {
$t_id = $term->term_id;
$t_id = $term->term_id;
$sections = sp_get_term_sections( $t_id );
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[sp_sections]"><?php _e( 'Statistics', 'sportspress' ); ?></label></th>
<input type="hidden" name="term_meta[sp_sections]" value="">
<td>
<select name="term_meta[sp_sections][]" id="term_meta[sp_sections][]" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>" multiple="multiple">
<select name="term_meta[sp_sections][]" id="term_meta[sp_sections][]" class="widefat chosen-select
<?php
if ( is_rtl() ) :
?>
chosen-rtl<?php endif; ?>" multiple="multiple">
<?php
$options = apply_filters( 'sportspress_performance_sections', array( 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
foreach ( $options as $key => $value ):
$options = apply_filters(
'sportspress_performance_sections',
array(
0 => __( 'Offense', 'sportspress' ),
1 => __(
'Defense',
'sportspress'
),
)
);
foreach ( $options as $key => $value ) :
printf( '<option value="%s" %s>%s</option>', $key, selected( in_array( $key, $sections ), true, false ), $value );
endforeach;
?>
@@ -227,7 +253,7 @@ class SP_Admin_Taxonomies {
<td><input name="sp_order" class="sp-number-input" type="text" step="1" size="4" id="sp_order" value="<?php echo (int) $order; ?>"></td>
</tr>
<?php } ?>
<?php
<?php
}
/**
@@ -239,12 +265,12 @@ class SP_Admin_Taxonomies {
*/
public function save_fields( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) {
$t_id = $term_id;
$t_id = $term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$cat_keys = array_keys( $_POST['term_meta'] );
$cat_keys = array_keys( $_POST['term_meta'] );
foreach ( $cat_keys as $key ) {
if ( isset ( $_POST['term_meta'][ $key ] ) ) {
$term_meta[$key] = sanitize_text_field( $_POST['term_meta'][ $key ] );
if ( isset( $_POST['term_meta'][ $key ] ) ) {
$term_meta[ $key ] = sanitize_text_field( $_POST['term_meta'][ $key ] );
}
}
update_option( "taxonomy_$t_id", $term_meta );
@@ -263,13 +289,15 @@ class SP_Admin_Taxonomies {
*/
public function taxonomy_columns( $columns ) {
$new_columns = array();
if ( function_exists( 'get_term_meta' ) ) $new_columns['sp_order'] = __( 'Order', 'sportspress' );
if ( array_key_exists('posts', $columns) ) {
$new_columns['posts'] = $columns['posts'];
if ( function_exists( 'get_term_meta' ) ) {
$new_columns['sp_order'] = __( 'Order', 'sportspress' );
}
unset( $columns['posts'] );
if ( array_key_exists( 'posts', $columns ) ) {
$new_columns['posts'] = $columns['posts'];
unset( $columns['posts'] );
}
return array_merge( $columns, $new_columns );
@@ -283,12 +311,12 @@ class SP_Admin_Taxonomies {
* @return array
*/
public function venue_columns( $columns ) {
$new_columns = array();
$new_columns = array();
$new_columns['sp_address'] = __( 'Address', 'sportspress' );
if ( array_key_exists('posts', $columns) ) {
$new_columns['posts'] = $columns['posts'];
unset( $columns['posts'] );
if ( array_key_exists( 'posts', $columns ) ) {
$new_columns['posts'] = $columns['posts'];
unset( $columns['posts'] );
}
unset( $columns['description'] );
@@ -305,14 +333,16 @@ class SP_Admin_Taxonomies {
* @return array
*/
public function position_columns( $columns ) {
$new_columns = array();
$new_columns = array();
$new_columns['sp_sections'] = __( 'Statistics', 'sportspress' );
if ( function_exists( 'get_term_meta' ) ) $new_columns['sp_order'] = __( 'Order', 'sportspress' );
if ( array_key_exists('posts', $columns) ) {
$new_columns['posts'] = $columns['posts'];
unset( $columns['posts'] );
if ( function_exists( 'get_term_meta' ) ) {
$new_columns['sp_order'] = __( 'Order', 'sportspress' );
}
if ( array_key_exists( 'posts', $columns ) ) {
$new_columns['posts'] = $columns['posts'];
unset( $columns['posts'] );
}
unset( $columns['description'] );
@@ -341,13 +371,22 @@ class SP_Admin_Taxonomies {
$columns .= $address;
} elseif ( $column == 'sp_sections' ) {
$options = apply_filters( 'sportspress_performance_sections', array( 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
$options = apply_filters(
'sportspress_performance_sections',
array(
0 => __( 'Offense', 'sportspress' ),
1 => __(
'Defense',
'sportspress'
),
)
);
$sections = sp_get_term_sections( $id );
$section_names = array();
if ( is_array( $sections ) ) {
foreach ( $sections as $section ) {
if ( array_key_exists( $section, $options ) ) {
@@ -355,7 +394,7 @@ class SP_Admin_Taxonomies {
}
}
}
$columns .= implode( ', ', $section_names );
} elseif ( $column == 'sp_order' ) {

View File

@@ -10,404 +10,447 @@
* @category Admin
* @package SportsPress/Admin
* @version 2.7.9
*/
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Admin_Welcome class.
*/
class SP_Admin_Welcome {
private $plugin;
private $plugin;
/**
* __construct function.
*
* @access public
* @return void
*/
public function __construct() {
$this->plugin = 'sportspress/sportspress.php';
/**
* __construct function.
*
* @access public
* @return void
*/
public function __construct() {
$this->plugin = 'sportspress/sportspress.php';
add_action( 'admin_menu', array( $this, 'admin_menus') );
add_action( 'admin_head', array( $this, 'admin_head' ) );
add_action( 'admin_init', array( $this, 'welcome' ) );
}
add_action( 'admin_menu', array( $this, 'admin_menus' ) );
add_action( 'admin_head', array( $this, 'admin_head' ) );
add_action( 'admin_init', array( $this, 'welcome' ) );
}
/**
* Add admin menus/screens
*
* @access public
* @return void
*/
public function admin_menus() {
if ( empty( $_GET['page'] ) ) {
return;
}
/**
* Add admin menus/screens
*
* @access public
* @return void
*/
public function admin_menus() {
if ( empty( $_GET['page'] ) ) {
return;
}
$welcome_page_name = __( 'About SportsPress', 'sportspress' );
$welcome_page_title = __( 'Welcome to SportsPress', 'sportspress' );
$welcome_page_name = __( 'About SportsPress', 'sportspress' );
$welcome_page_title = __( 'Welcome to SportsPress', 'sportspress' );
switch ( $_GET['page'] ) {
case 'sp-about' :
$page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-about', array( $this, 'about_screen' ) );
add_action( 'admin_print_styles-'. $page, array( $this, 'admin_css' ) );
break;
case 'sp-credits' :
$page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-credits', array( $this, 'credits_screen' ) );
add_action( 'admin_print_styles-'. $page, array( $this, 'admin_css' ) );
break;
case 'sp-translators' :
$page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-translators', array( $this, 'translators_screen' ) );
add_action( 'admin_print_styles-'. $page, array( $this, 'admin_css' ) );
break;
}
}
switch ( $_GET['page'] ) {
case 'sp-about':
$page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-about', array( $this, 'about_screen' ) );
add_action( 'admin_print_styles-' . $page, array( $this, 'admin_css' ) );
break;
case 'sp-credits':
$page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-credits', array( $this, 'credits_screen' ) );
add_action( 'admin_print_styles-' . $page, array( $this, 'admin_css' ) );
break;
case 'sp-translators':
$page = add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sp-translators', array( $this, 'translators_screen' ) );
add_action( 'admin_print_styles-' . $page, array( $this, 'admin_css' ) );
break;
}
}
/**
* admin_css function.
*
* @access public
* @return void
*/
public function admin_css() {
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ), array(), SP_VERSION );
}
/**
* admin_css function.
*
* @access public
* @return void
*/
public function admin_css() {
wp_enqueue_style( 'sportspress-activation', plugins_url( '/assets/css/activation.css', SP_PLUGIN_FILE ), array(), SP_VERSION );
}
/**
* Add styles just for this page, and remove dashboard page links.
*
* @access public
* @return void
*/
public function admin_head() {
remove_submenu_page( 'index.php', 'sp-about' );
remove_submenu_page( 'index.php', 'sp-credits' );
remove_submenu_page( 'index.php', 'sp-translators' );
}
/**
* Add styles just for this page, and remove dashboard page links.
*
* @access public
* @return void
*/
public function admin_head() {
remove_submenu_page( 'index.php', 'sp-about' );
remove_submenu_page( 'index.php', 'sp-credits' );
remove_submenu_page( 'index.php', 'sp-translators' );
}
/**
* Into text/links shown on all about pages.
*
* @access private
* @return void
*/
private function intro() {
/**
* Into text/links shown on all about pages.
*
* @access private
* @return void
*/
private function intro() {
// Flush after upgrades
if ( ! empty( $_GET['sp-updated'] ) || ! empty( $_GET['sp-installed'] ) )
flush_rewrite_rules();
// Flush after upgrades
if ( ! empty( $_GET['sp-updated'] ) || ! empty( $_GET['sp-installed'] ) ) {
flush_rewrite_rules();
}
// Get major version number
$version = explode( '.', SP()->version, 3 );
unset( $version[2] );
$display_version = implode( '.', $version );
?>
<h1 class="sp-welcome-logo"><?php echo apply_filters( 'sportspress_logo', '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/welcome/sportspress' . ( class_exists( 'SportsPress_Pro' ) ? '-pro' : '' ) . '.png" alt="' . __( 'SportsPress', 'sportspress' ) . '">' ); ?></h1>
// Get major version number
$version = explode( '.', SP()->version, 3 );
unset( $version[2] );
$display_version = implode( '.', $version );
?>
<h1 class="sp-welcome-logo"><?php echo apply_filters( 'sportspress_logo', '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/welcome/sportspress' . ( class_exists( 'SportsPress_Pro' ) ? '-pro' : '' ) . '.png" alt="' . __( 'SportsPress', 'sportspress' ) . '">' ); ?></h1>
<div class="sp-badge"><?php printf( __( 'Version %s', 'sportspress' ), SP()->version ); ?></div>
<div class="sp-badge"><?php printf( __( 'Version %s', 'sportspress' ), SP()->version ); ?></div>
<div class="about-text sp-about-text">
<?php
if ( ! empty( $_GET['sp-installed'] ) )
$message = __( 'Thanks, all done!', 'sportspress' );
elseif ( ! empty( $_GET['sp-updated'] ) )
$message = __( 'Thank you for updating to the latest version!', 'sportspress' );
else
$message = __( 'Thanks for installing!', 'sportspress' );
<div class="about-text sp-about-text">
<?php
if ( ! empty( $_GET['sp-installed'] ) ) {
$message = __( 'Thanks, all done!', 'sportspress' );
} elseif ( ! empty( $_GET['sp-updated'] ) ) {
$message = __( 'Thank you for updating to the latest version!', 'sportspress' );
} else {
$message = __( 'Thanks for installing!', 'sportspress' );
}
printf( __( '%s SportsPress %s has lots of refinements we think you&#8217;ll love.', 'sportspress' ), $message, $display_version );
?>
</div>
printf( __( '%1$s SportsPress %2$s has lots of refinements we think you&#8217;ll love.', 'sportspress' ), $message, $display_version );
?>
</div>
<p class="sportspress-actions">
<a href="<?php echo admin_url( add_query_arg( array( 'page' => 'sportspress', 'tab' => 'general' ), 'admin.php' ) ); ?>" class="button button-primary"><?php _e( 'Settings', 'sportspress' ); ?></a>
<a href="<?php echo esc_url( apply_filters( 'sportspress_docs_url', 'http://tboy.co/docs', 'sportspress' ) ); ?>" class="docs button button-primary"><?php _e( 'Docs', 'sportspress' ); ?></a>
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://wordpress.org/plugins/sportspress" data-text="An open-source (free) #WordPress plugin that helps you build professional league websites" data-via="ThemeBoy" data-size="large" data-hashtags="SportsPress">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</p>
<a href="
<?php
echo admin_url(
add_query_arg(
array(
'page' => 'sportspress',
'tab' => 'general',
),
'admin.php'
)
);
?>
" class="button button-primary"><?php _e( 'Settings', 'sportspress' ); ?></a>
<a href="<?php echo esc_url( apply_filters( 'sportspress_docs_url', 'http://tboy.co/docs', 'sportspress' ) ); ?>" class="docs button button-primary"><?php _e( 'Docs', 'sportspress' ); ?></a>
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://wordpress.org/plugins/sportspress" data-text="An open-source (free) #WordPress plugin that helps you build professional league websites" data-via="ThemeBoy" data-size="large" data-hashtags="SportsPress">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</p>
<h2 class="nav-tab-wrapper">
<a class="nav-tab <?php if ( $_GET['page'] == 'sp-about' ) echo 'nav-tab-active'; ?>" href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'sp-about' ), 'index.php' ) ) ); ?>">
<?php _e( 'Welcome', 'sportspress' ); ?>
</a><a class="nav-tab <?php if ( $_GET['page'] == 'sp-credits' ) echo 'nav-tab-active'; ?>" href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'sp-credits' ), 'index.php' ) ) ); ?>">
<?php _e( 'Credits', 'sportspress' ); ?>
</a>
</h2>
<?php
}
<h2 class="nav-tab-wrapper">
<a class="nav-tab
<?php
if ( $_GET['page'] == 'sp-about' ) {
echo 'nav-tab-active';}
?>
" href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'sp-about' ), 'index.php' ) ) ); ?>">
<?php _e( 'Welcome', 'sportspress' ); ?>
</a><a class="nav-tab
<?php
if ( $_GET['page'] == 'sp-credits' ) {
echo 'nav-tab-active';}
?>
" href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'sp-credits' ), 'index.php' ) ) ); ?>">
<?php _e( 'Credits', 'sportspress' ); ?>
</a>
</h2>
<?php
}
/**
* Output the about screen.
*/
public function about_screen() {
include_once( 'class-sp-admin-settings.php' );
$class = 'chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' );
?>
<div class="wrap about-wrap about-sportspress-wrap">
/**
* Output the about screen.
*/
public function about_screen() {
include_once 'class-sp-admin-settings.php';
$class = 'chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' );
?>
<div class="wrap about-wrap about-sportspress-wrap">
<?php $this->intro(); ?>
<?php $this->intro(); ?>
<?php
// Save settings
if ( isset( $_POST['timezone_string'] ) ):
update_option( 'timezone_string', sanitize_text_field( $_POST['timezone_string'] ) );
update_option( 'sportspress_basic_setup', 1 );
endif;
if ( isset( $_POST['sportspress_sport'] ) && ! empty( $_POST['sportspress_sport'] ) ):
$sport = sanitize_text_field( $_POST['sportspress_sport'] );
SP_Admin_Sports::apply_preset( $sport );
update_option( 'sportspress_sport', $sport );
delete_option( '_sp_needs_welcome' );
update_option( 'sportspress_installed', 1 );
?>
<div id="message" class="updated sportspress-message">
<p><strong><?php _e( 'Your settings have been saved.', 'sportspress' ); ?></strong></p>
</div>
<?php
endif;
if ( isset( $_POST['add_sample_data'] ) ):
SP_Admin_Sample_Data::delete_posts();
SP_Admin_Sample_Data::insert_posts();
endif;
<?php
// Save settings
if ( isset( $_POST['timezone_string'] ) ) :
update_option( 'timezone_string', sanitize_text_field( $_POST['timezone_string'] ) );
update_option( 'sportspress_basic_setup', 1 );
endif;
if ( isset( $_POST['sportspress_sport'] ) && ! empty( $_POST['sportspress_sport'] ) ) :
$sport = sanitize_text_field( $_POST['sportspress_sport'] );
SP_Admin_Sports::apply_preset( $sport );
update_option( 'sportspress_sport', $sport );
delete_option( '_sp_needs_welcome' );
update_option( 'sportspress_installed', 1 );
?>
<div id="message" class="updated sportspress-message">
<p><strong><?php _e( 'Your settings have been saved.', 'sportspress' ); ?></strong></p>
</div>
<?php
endif;
if ( isset( $_POST['add_sample_data'] ) ) :
SP_Admin_Sample_Data::delete_posts();
SP_Admin_Sample_Data::insert_posts();
endif;
do_action( 'sportspress_before_welcome_features' );
?>
<div class="feature-section one-col">
<div class="col">
<h2>New Features 🌟</h2>
</div>
</div>
do_action( 'sportspress_before_welcome_features' );
?>
<div class="feature-section one-col">
<div class="col">
<h2>New Features 🌟</h2>
</div>
</div>
<div class="feature-section three-col">
<div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-conditional-equations.png" alt="Screenshot">
<h3>Conditional Equations</h3>
<p>Use the newly introduced conditional operators <strong>&gt;</strong>, <strong>&lt;</strong>, <strong>&equiv;</strong>, <strong>&ne;</strong>, <strong>&ge;</strong>, and <strong>&le;</strong> to calculate the relationship between variables, then insert that calculation into more complex equations. Visit the <a href="<?php echo add_query_arg( array( 'page' => 'sportspress-config' ), admin_url( 'admin.php' ) ); ?>">Configure</a> page to edit variables and equations.</p>
</div>
<div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-event-specs.png" alt="Screenshot">
<h3>Event Specs</h3>
<p>Measure and display additional details per event using the new <strong>Event Specs</strong> variables. They are customizable and can be useful for keeping track of information like player of the match, attendance, and venue weather.
</div>
<div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-next-team.png" alt="Screenshot">
<h3>Next Team Column</h3>
<p>Provide a quick overview of who each team is playing next using the new <strong>Next Team</strong> preset for <a href="<?php echo add_query_arg( array( 'post_type' => 'sp_column' ), admin_url( 'edit.php' ) ); ?>">league table columns</a>. This will automatically display the next team's name or logo that links to the next match for each team in the table.<p>
</div>
</div>
<div class="feature-section three-col">
<div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-conditional-equations.png" alt="Screenshot">
<h3>Conditional Equations</h3>
<p>Use the newly introduced conditional operators <strong>&gt;</strong>, <strong>&lt;</strong>, <strong>&equiv;</strong>, <strong>&ne;</strong>, <strong>&ge;</strong>, and <strong>&le;</strong> to calculate the relationship between variables, then insert that calculation into more complex equations. Visit the <a href="<?php echo add_query_arg( array( 'page' => 'sportspress-config' ), admin_url( 'admin.php' ) ); ?>">Configure</a> page to edit variables and equations.</p>
</div>
<div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-event-specs.png" alt="Screenshot">
<h3>Event Specs</h3>
<p>Measure and display additional details per event using the new <strong>Event Specs</strong> variables. They are customizable and can be useful for keeping track of information like player of the match, attendance, and venue weather.
</div>
<div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-next-team.png" alt="Screenshot">
<h3>Next Team Column</h3>
<p>Provide a quick overview of who each team is playing next using the new <strong>Next Team</strong> preset for <a href="<?php echo add_query_arg( array( 'post_type' => 'sp_column' ), admin_url( 'edit.php' ) ); ?>">league table columns</a>. This will automatically display the next team's name or logo that links to the next match for each team in the table.<p>
</div>
</div>
<?php if ( ! class_exists( 'SportsPress_Pro' ) ) { ?>
<hr>
<?php if ( ! class_exists( 'SportsPress_Pro' ) ) { ?>
<hr>
<div class="feature-section one-col">
<div class="col">
<h2>SportsPress Pro Updates 🏆</h2>
</div>
</div>
<div class="feature-section one-col">
<div class="col">
<h2>SportsPress Pro Updates 🏆</h2>
</div>
</div>
<div class="feature-section three-col">
<div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-results-matrix.png" alt="Results Matrix">
<h3>Results Matrix</h3>
<p>Display matches between home and away team in a grid. Create or select an existing calendar and select the <strong>Matrix</strong> layout to convert the calendar to an interactive results matrix!</p>
</div>
<div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-midseason-transfers.png" alt="Midseason Transfers">
<h3>Midseason Transfers</h3>
<p>Keep track of players that switched teams during a season by adding one or more extra rows to their statistics table. Display the team and partial statistics before and after the transfer.<p>
</div>
<div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-vertical-timelines.png" alt="Vertical Timelines">
<h3>Vertical Timelines</h3>
<p>Display a match commentary style play-by-play timeline within events. <a href="<?php echo esc_url( apply_filters( 'sportspress_pro_url', 'http://tboy.co/pro' ) ); ?>">Upgrade to SportsPress Pro</a> to get access to <strong>Timelines</strong> and other pro features.<p>
</div>
</div>
<div class="feature-section three-col">
<div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-results-matrix.png" alt="Results Matrix">
<h3>Results Matrix</h3>
<p>Display matches between home and away team in a grid. Create or select an existing calendar and select the <strong>Matrix</strong> layout to convert the calendar to an interactive results matrix!</p>
</div>
<div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-midseason-transfers.png" alt="Midseason Transfers">
<h3>Midseason Transfers</h3>
<p>Keep track of players that switched teams during a season by adding one or more extra rows to their statistics table. Display the team and partial statistics before and after the transfer.<p>
</div>
<div class="col">
<img src="<?php echo plugin_dir_url( SP_PLUGIN_FILE ); ?>assets/images/welcome/screenshot-vertical-timelines.png" alt="Vertical Timelines">
<h3>Vertical Timelines</h3>
<p>Display a match commentary style play-by-play timeline within events. <a href="<?php echo esc_url( apply_filters( 'sportspress_pro_url', 'http://tboy.co/pro' ) ); ?>">Upgrade to SportsPress Pro</a> to get access to <strong>Timelines</strong> and other pro features.<p>
</div>
</div>
<a class="button button-primary button-hero" href="<?php echo esc_url( apply_filters( 'sportspress_pro_url', 'http://tboy.co/pro' ) ); ?>"><?php _e( 'Upgrade to Pro', 'sportspress' ); ?></a>
<a class="button button-primary button-hero" href="<?php echo esc_url( apply_filters( 'sportspress_pro_url', 'http://tboy.co/pro' ) ); ?>"><?php _e( 'Upgrade to Pro', 'sportspress' ); ?></a>
<p><?php _e( 'Get SportsPress Pro to get access to all modules. You can upgrade any time without losing any of your data.','sportspress' ); ?></p>
<?php } ?>
<p><?php _e( 'Get SportsPress Pro to get access to all modules. You can upgrade any time without losing any of your data.', 'sportspress' ); ?></p>
<?php } ?>
<hr>
<hr>
<div class="feature-section one-col">
<div class="col">
<h2>Player Data Improvements</h2>
</div>
</div>
<div class="feature-section one-col">
<div class="col">
<h2>Player Data Improvements</h2>
</div>
</div>
<div class="feature-section three-col">
<div class="col">
<h3>Player Assignments</h3>
<p>Players will now be saved using a new data format that allows them to belong to multiple leagues, seasons, and teams and be accurately selected in <a href="<?php echo add_query_arg( array( 'post_type' => 'sp_list' ), admin_url( 'edit.php' ) ); ?>">player lists</a>.</p>
</div>
<div class="col">
<h3>Current Team Column</h3>
<p>The <strong>Team</strong> column in player lists will now display only the current team that player belongs to, determined by the <strong>Current Team</strong> setting of each player.</p>
</div>
<div class="col">
<h3>Squad Number Zero</h3>
<p>It's now possible to import players with the squad number <strong>0 (zero)</strong> or any other value that would previously be interpreted as empty.</p>
</div>
</div>
<div class="feature-section three-col">
<div class="col">
<h3>Player Assignments</h3>
<p>Players will now be saved using a new data format that allows them to belong to multiple leagues, seasons, and teams and be accurately selected in <a href="<?php echo add_query_arg( array( 'post_type' => 'sp_list' ), admin_url( 'edit.php' ) ); ?>">player lists</a>.</p>
</div>
<div class="col">
<h3>Current Team Column</h3>
<p>The <strong>Team</strong> column in player lists will now display only the current team that player belongs to, determined by the <strong>Current Team</strong> setting of each player.</p>
</div>
<div class="col">
<h3>Squad Number Zero</h3>
<p>It's now possible to import players with the squad number <strong>0 (zero)</strong> or any other value that would previously be interpreted as empty.</p>
</div>
</div>
<hr>
<hr>
<div class="feature-section one-col">
<div class="col">
<h2>Other Notes</h2>
</div>
</div>
<div class="feature-section one-col">
<div class="col">
<h2>Other Notes</h2>
</div>
</div>
<div class="feature-section three-col">
<div class="col">
<h3>Countdown Images</h3>
<p>A new option has been added to the <strong>Countdown</strong> widget, allowing you to display a featured image from the next event.</p>
</div>
<div class="col">
<h3>Relative Date in Shortcodes</h3>
<p>You'll now be able to select a relative date range when inserting calendar-related shortcodes from the visual editor.</p>
</div>
<div class="col">
<h3>Short Names</h3>
<p>Teams have been given a <strong>Short Name</strong> setting in addition to the existing <strong>Abbreviation</strong> for added customizability.</p>
</div>
</div>
<div class="feature-section three-col">
<div class="col">
<h3>Countdown Images</h3>
<p>A new option has been added to the <strong>Countdown</strong> widget, allowing you to display a featured image from the next event.</p>
</div>
<div class="col">
<h3>Relative Date in Shortcodes</h3>
<p>You'll now be able to select a relative date range when inserting calendar-related shortcodes from the visual editor.</p>
</div>
<div class="col">
<h3>Short Names</h3>
<p>Teams have been given a <strong>Short Name</strong> setting in addition to the existing <strong>Abbreviation</strong> for added customizability.</p>
</div>
</div>
<?php do_action( 'sportspress_after_welcome_features' ); ?>
<?php do_action( 'sportspress_after_welcome_features' ); ?>
<a href="
<?php
echo esc_url(
admin_url(
add_query_arg(
array(
'page' => 'sportspress',
'tab' => 'general',
),
'admin.php'
)
)
);
?>
"><?php _e( 'Go to SportsPress Settings', 'sportspress' ); ?></a>
</div>
<?php
}
<a href="<?php echo esc_url( admin_url( add_query_arg( array( 'page' => 'sportspress', 'tab' => 'general' ), 'admin.php' ) ) ); ?>"><?php _e( 'Go to SportsPress Settings', 'sportspress' ); ?></a>
</div>
<?php
}
/**
* Output the credits.
*/
public function credits_screen() {
?>
<div class="wrap about-wrap about-sportspress-wrap">
<?php $this->intro(); ?>
<p class="about-description"><?php printf( __( 'SportsPress is developed and maintained by a worldwide team of passionate individuals and backed by an awesome developer community. Want to see your name? <a href="%s">Contribute to SportsPress</a>.', 'sportspress' ), 'https://github.com/ThemeBoy/SportsPress/blob/master/CONTRIBUTING.md' ); ?></p>
/**
* Output the credits.
*/
public function credits_screen() {
?>
<div class="wrap about-wrap about-sportspress-wrap">
<?php $this->intro(); ?>
<p class="about-description"><?php printf( __( 'SportsPress is developed and maintained by a worldwide team of passionate individuals and backed by an awesome developer community. Want to see your name? <a href="%s">Contribute to SportsPress</a>.', 'sportspress' ), 'https://github.com/ThemeBoy/SportsPress/blob/master/CONTRIBUTING.md' ); ?></p>
<div class="sp-feature feature-section col one-col">
<?php echo wp_kses_post( $this->contributors() ); ?>
</div>
</div>
<?php
}
<div class="sp-feature feature-section col one-col">
<?php echo wp_kses_post( $this->contributors() ); ?>
</div>
</div>
<?php
}
/**
* Output the translators screen
*/
public function translators_screen() {
?>
<div class="wrap about-wrap about-sportspress-wrap">
/**
* Output the translators screen
*/
public function translators_screen() {
?>
<div class="wrap about-wrap about-sportspress-wrap">
<?php $this->intro(); ?>
<?php $this->intro(); ?>
<p class="about-description"><?php printf( __( 'SportsPress has been kindly translated into several other languages thanks to our translation team. Want to see your name? <a href="%s">Translate SportsPress</a>.', 'sportspress' ), 'https://translate.wordpress.org/projects/wp-plugins/sportspress' ); ?></p>
</div>
<?php
}
<p class="about-description"><?php printf( __( 'SportsPress has been kindly translated into several other languages thanks to our translation team. Want to see your name? <a href="%s">Translate SportsPress</a>.', 'sportspress' ), 'https://translate.wordpress.org/projects/wp-plugins/sportspress' ); ?></p>
</div>
<?php
}
/**
* Render Contributors List
*
* @access public
* @return string $contributor_list HTML formatted list of contributors.
*/
public function contributors() {
$contributors = $this->get_contributors();
/**
* Render Contributors List
*
* @access public
* @return string $contributor_list HTML formatted list of contributors.
*/
public function contributors() {
$contributors = $this->get_contributors();
if ( empty( $contributors ) ) {
return '';
}
if ( empty( $contributors ) ) {
return '';
}
$contributor_list = '<ul class="wp-people-group">';
$contributor_list = '<ul class="wp-people-group">';
foreach ( $contributors as $contributor ) {
$contributor_list .= '<li class="wp-person">';
$contributor_list .= sprintf(
'<a href="%s" title="%s">',
esc_url( 'https://github.com/' . $contributor->login ),
esc_html( sprintf( __( 'View %s', 'sportspress' ), $contributor->login ) )
);
$contributor_list .= sprintf( '<img src="%s" width="64" height="64" class="gravatar" alt="%s" />', esc_url( $contributor->avatar_url ), esc_html( $contributor->login ) );
$contributor_list .= '</a>';
$contributor_list .= sprintf( '<a class="web" href="%s">%s</a>', esc_url( 'https://github.com/' . $contributor->login ), esc_html( $contributor->login ) );
$contributor_list .= '</a>';
$contributor_list .= '</li>';
}
foreach ( $contributors as $contributor ) {
$contributor_list .= '<li class="wp-person">';
$contributor_list .= sprintf( '<a href="%s" title="%s">',
esc_url( 'https://github.com/' . $contributor->login ),
esc_html( sprintf( __( 'View %s', 'sportspress' ), $contributor->login ) )
);
$contributor_list .= sprintf( '<img src="%s" width="64" height="64" class="gravatar" alt="%s" />', esc_url( $contributor->avatar_url ), esc_html( $contributor->login ) );
$contributor_list .= '</a>';
$contributor_list .= sprintf( '<a class="web" href="%s">%s</a>', esc_url( 'https://github.com/' . $contributor->login ), esc_html( $contributor->login ) );
$contributor_list .= '</a>';
$contributor_list .= '</li>';
}
$contributor_list .= '</ul>';
$contributor_list .= '</ul>';
return $contributor_list;
}
return $contributor_list;
}
/**
* Retrieve list of contributors from GitHub.
*
* @access public
* @return mixed
*/
public function get_contributors() {
$contributors = get_transient( 'sportspress_contributors' );
/**
* Retrieve list of contributors from GitHub.
*
* @access public
* @return mixed
*/
public function get_contributors() {
$contributors = get_transient( 'sportspress_contributors' );
if ( false !== $contributors ) {
return $contributors;
}
if ( false !== $contributors ) {
return $contributors;
}
$response = wp_remote_get( 'https://api.github.com/repos/ThemeBoy/SportsPress/contributors', array( 'sslverify' => false ) );
$response = wp_remote_get( 'https://api.github.com/repos/ThemeBoy/SportsPress/contributors', array( 'sslverify' => false ) );
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
return array();
}
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
return array();
}
$contributors = json_decode( wp_remote_retrieve_body( $response ) );
$contributors = json_decode( wp_remote_retrieve_body( $response ) );
if ( ! is_array( $contributors ) ) {
return array();
}
if ( ! is_array( $contributors ) ) {
return array();
}
set_transient( 'sportspress_contributors', $contributors, HOUR_IN_SECONDS );
set_transient( 'sportspress_contributors', $contributors, HOUR_IN_SECONDS );
return $contributors;
}
return $contributors;
}
/**
* Sends user to the welcome page on first activation
*/
public function welcome() {
/**
* Sends user to the welcome page on first activation
*/
public function welcome() {
// Bail if no activation redirect transient is set
if ( ! get_transient( '_sp_activation_redirect' ) ) {
return;
}
// Bail if no activation redirect transient is set
if ( ! get_transient( '_sp_activation_redirect' ) )
return;
// Delete the redirect transient
delete_transient( '_sp_activation_redirect' );
// Delete the redirect transient
delete_transient( '_sp_activation_redirect' );
// Bail if we are waiting to install or update via the interface update/install links
if ( get_option( '_sp_needs_update' ) == 1 || get_option( '_sp_needs_pages' ) == 1 ) {
return;
}
// Bail if we are waiting to install or update via the interface update/install links
if ( get_option( '_sp_needs_update' ) == 1 || get_option( '_sp_needs_pages' ) == 1 )
return;
// Bail if activating from network, or bulk, or within an iFrame
if ( is_network_admin() || isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) ) {
return;
}
// Bail if activating from network, or bulk, or within an iFrame
if ( is_network_admin() || isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) )
return;
if ( ( isset( $_GET['action'] ) && 'upgrade-plugin' == $_GET['action'] ) && ( isset( $_GET['plugin'] ) && strstr( $_GET['plugin'], 'sportspress.php' ) ) ) {
return;
}
if ( ( isset( $_GET['action'] ) && 'upgrade-plugin' == $_GET['action'] ) && ( isset( $_GET['plugin'] ) && strstr( $_GET['plugin'], 'sportspress.php' ) ) )
return;
if ( ! get_option( 'sportspress_completed_setup' ) ) {
wp_redirect( admin_url( 'admin.php?page=sp-setup' ) );
exit;
}
if ( ! get_option( 'sportspress_completed_setup' ) ) {
wp_redirect( admin_url( 'admin.php?page=sp-setup' ) );
exit;
}
wp_redirect( admin_url( 'index.php?page=sp-about' ) );
exit;
}
wp_redirect( admin_url( 'index.php?page=sp-about' ) );
exit;
}
}
new SP_Admin_Welcome();

View File

@@ -6,11 +6,11 @@ if ( ! defined( 'ABSPATH' ) ) {
/**
* SportsPress Admin.
*
* @class SP_Admin
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.5.1
* @class SP_Admin
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.5.1
*/
class SP_Admin {
@@ -36,32 +36,32 @@ class SP_Admin {
*/
public function includes() {
// Functions
include_once( 'sp-admin-functions.php' );
include_once 'sp-admin-functions.php';
// Classes
include_once( 'class-sp-admin-post-types.php' );
include_once( 'class-sp-admin-taxonomies.php' );
include_once( 'class-sp-admin-ajax.php' );
include_once 'class-sp-admin-post-types.php';
include_once 'class-sp-admin-taxonomies.php';
include_once 'class-sp-admin-ajax.php';
// Classes we only need if the ajax is not-ajax
if ( ! is_ajax() ) {
include( 'class-sp-admin-menus.php' );
include( 'class-sp-admin-welcome.php' );
include( 'class-sp-admin-notices.php' );
include( 'class-sp-admin-assets.php' );
include( 'class-sp-admin-permalink-settings.php' );
include 'class-sp-admin-menus.php';
include 'class-sp-admin-welcome.php';
include 'class-sp-admin-notices.php';
include 'class-sp-admin-assets.php';
include 'class-sp-admin-permalink-settings.php';
if ( 'yes' == get_option( 'sportspress_rich_editing', 'yes' ) ):
include( 'class-sp-admin-editor.php' );
if ( 'yes' == get_option( 'sportspress_rich_editing', 'yes' ) ) :
include 'class-sp-admin-editor.php';
endif;
}
// Setup/welcome
if ( ! empty( $_GET['page'] ) ) {
switch ( $_GET['page'] ) {
case 'sp-setup' :
include_once( 'class-sp-admin-setup-wizard.php' );
break;
case 'sp-setup':
include_once 'class-sp-admin-setup-wizard.php';
break;
}
}
}
@@ -73,8 +73,8 @@ class SP_Admin {
$screen = get_current_screen();
switch ( $screen->id ) {
case 'dashboard' :
include( 'class-sp-admin-dashboard.php' );
case 'dashboard':
include 'class-sp-admin-dashboard.php';
break;
}
}
@@ -85,7 +85,7 @@ class SP_Admin {
public function prevent_admin_access() {
$prevent_access = false;
if ( 'yes' == get_option( 'sportspress_lock_down_admin' ) && ! is_ajax() && ! ( current_user_can( 'edit_posts' ) || current_user_can( 'manage_sportspress' ) ) && basename( $_SERVER["SCRIPT_FILENAME"] ) !== 'admin-post.php' ) {
if ( 'yes' == get_option( 'sportspress_lock_down_admin' ) && ! is_ajax() && ! ( current_user_can( 'edit_posts' ) || current_user_can( 'manage_sportspress' ) ) && basename( $_SERVER['SCRIPT_FILENAME'] ) !== 'admin-post.php' ) {
$prevent_access = true;
}
@@ -134,4 +134,4 @@ class SP_Admin {
}
}
return new SP_Admin();
return new SP_Admin();

View File

@@ -2,13 +2,15 @@
/**
* Event importer - import events into SportsPress.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) {
class SP_Event_Importer extends SP_Importer {
@@ -20,20 +22,21 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void
*/
public function __construct() {
$this->import_page = 'sp_event_csv';
$this->import_page = 'sp_event_csv';
$this->import_label = __( 'Import Events', 'sportspress' );
$this->columns = array(
'post_date' => __( 'Date', 'sportspress' ),
'post_time' => __( 'Time', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
$this->columns = array(
'post_date' => __( 'Date', 'sportspress' ),
'post_time' => __( 'Time', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_results' => __( 'Results', 'sportspress' ),
'sp_outcome' => __( 'Outcome', 'sportspress' ),
'sp_player' => __( 'Players', 'sportspress' ),
'sp_player' => __( 'Players', 'sportspress' ),
);
$performance_labels = sp_get_var_labels( 'sp_performance' );
if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) )
if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) ) {
$this->columns = array_merge( $this->columns, $performance_labels );
}
}
/**
@@ -47,7 +50,7 @@ if ( class_exists( 'WP_Importer' ) ) {
function import( $array = array(), $columns = array( 'post_title' ) ) {
$this->imported = $this->skipped = 0;
if ( ! is_array( $array ) || ! sizeof( $array ) ):
if ( ! is_array( $array ) || ! sizeof( $array ) ) :
$this->footer();
die();
endif;
@@ -56,29 +59,31 @@ if ( class_exists( 'WP_Importer' ) ) {
// Get event format, league, and season from post vars
$event_format = ( empty( $_POST['sp_format'] ) ? false : sanitize_text_field( $_POST['sp_format'] ) );
$league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_league'] ) );
$season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_season'] ) );
$date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : sanitize_text_field( $_POST['sp_date_format'] ) );
$league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_league'] ) );
$season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : sanitize_text_field( $_POST['sp_season'] ) );
$date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : sanitize_text_field( $_POST['sp_date_format'] ) );
// Get labels from result and performance post types
$result_labels = sp_get_var_labels( 'sp_result' );
$result_labels = sp_get_var_labels( 'sp_result' );
$performance_labels = sp_get_var_labels( 'sp_performance' );
foreach ( $rows as $row ):
foreach ( $rows as $row ) :
$row = array_filter( $row );
if ( empty( $row ) ) continue;
if ( empty( $row ) ) {
continue;
}
$meta = array();
foreach ( $columns as $index => $key ):
foreach ( $columns as $index => $key ) :
$meta[ $key ] = sp_array_value( $row, $index );
endforeach;
// Slice array into event, team, and player
$event = array_slice( $row, 0, 3 );
$team = array_slice( $row, 3, 3 );
$event = array_slice( $row, 0, 3 );
$team = array_slice( $row, 3, 3 );
$player = array_slice( $row, 6 );
// Get event details
@@ -105,16 +110,16 @@ if ( class_exists( 'WP_Importer' ) ) {
$player = array(
sp_array_value( $meta, 'sp_player' ),
);
unset( $meta['sp_player' ] );
foreach ( $performance_labels as $key => $label ):
unset( $meta['sp_player'] );
foreach ( $performance_labels as $key => $label ) :
$player[] = sp_array_value( $meta, $key, '' );
endforeach;
// Add new event if date is given
if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ):
if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ) :
// Add player performance to last event if available
if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ):
if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ) :
update_post_meta( $id, 'sp_players', $players );
endif;
@@ -122,9 +127,9 @@ if ( class_exists( 'WP_Importer' ) ) {
list( $date, $time, $venue ) = $event;
// Format date
$date = str_replace( '/', '-', trim( $date ) );
$date = str_replace( '/', '-', trim( $date ) );
$date_array = explode( '-', $date );
switch ( $date_format ):
switch ( $date_format ) :
case 'dd/mm/yyyy':
$date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' .
substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' .
@@ -142,12 +147,17 @@ if ( class_exists( 'WP_Importer' ) ) {
endswitch;
// Add time to date if given
if ( ! empty( $time ) ):
if ( ! empty( $time ) ) :
$date .= ' ' . trim( $time );
endif;
// Define post type args
$args = array( 'post_type' => 'sp_event', 'post_status' => 'publish', 'post_date' => $date, 'post_title' => __( 'Event', 'sportspress' ) );
$args = array(
'post_type' => 'sp_event',
'post_status' => 'publish',
'post_date' => $date,
'post_title' => __( 'Event', 'sportspress' ),
);
// Insert event
$id = wp_insert_post( $args );
@@ -159,17 +169,17 @@ if ( class_exists( 'WP_Importer' ) ) {
update_post_meta( $id, '_sp_import', 1 );
// Update event format
if ( $event_format ):
if ( $event_format ) :
update_post_meta( $id, 'sp_format', $event_format );
endif;
// Update league
if ( $league ):
if ( $league ) :
wp_set_object_terms( $id, $league, 'sp_league', false );
endif;
// Update season
if ( $season ):
if ( $season ) :
wp_set_object_terms( $id, $season, 'sp_season', false );
endif;
@@ -182,7 +192,7 @@ if ( class_exists( 'WP_Importer' ) ) {
endif;
// Add new team if team name is given
if ( sizeof( $team ) > 0 && ! empty( $team[0] ) ):
if ( sizeof( $team ) > 0 && ! empty( $team[0] ) ) :
// List team columns
list( $team_name, $result, $outcome ) = $team;
@@ -191,20 +201,31 @@ if ( class_exists( 'WP_Importer' ) ) {
$team_object = get_page_by_title( stripslashes( $team_name ), OBJECT, 'sp_team' );
// Get or insert team
if ( $team_object ):
if ( $team_object ) :
// Make sure team is published
if ( $team_object->post_status != 'publish' ):
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
if ( $team_object->post_status != 'publish' ) :
wp_update_post(
array(
'ID' => $team_object->ID,
'post_status' => 'publish',
)
);
endif;
// Get team ID
$team_id = $team_object->ID;
else:
else :
// Insert team
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $team_name ) ) );
$team_id = wp_insert_post(
array(
'post_type' => 'sp_team',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $team_name ),
)
);
// Flag as import
update_post_meta( $team_id, '_sp_import', 1 );
@@ -212,17 +233,17 @@ if ( class_exists( 'WP_Importer' ) ) {
endif;
// Update league
if ( $league ):
if ( $league ) :
wp_set_object_terms( $team_id, $league, 'sp_league', true );
endif;
// Update season
if ( $season ):
if ( $season ) :
wp_set_object_terms( $team_id, $season, 'sp_season', true );
endif;
// Add to event if exists
if ( isset( $id ) ):
if ( isset( $id ) ) :
// Add team to event
add_post_meta( $id, 'sp_team', $team_id );
@@ -235,21 +256,21 @@ if ( class_exists( 'WP_Importer' ) ) {
// Create team results array from result keys
$team_results = array();
if ( sizeof( $result_labels ) > 0 ):
foreach( $result_labels as $key => $label ):
if ( sizeof( $result_labels ) > 0 ) :
foreach ( $result_labels as $key => $label ) :
$team_results[ $key ] = trim( array_shift( $results ) );
endforeach;
$team_results[ 'outcome' ] = array();
$team_results['outcome'] = array();
endif;
// Explode outcomes into array
$outcomes = explode( '|', $outcome );
// Add outcome slugs to team outcomes array
foreach ( $outcomes as $outcome ):
foreach ( $outcomes as $outcome ) :
// Continue if outcome doesn't exist
if ( $outcome == null ):
if ( $outcome == null ) :
continue;
endif;
@@ -259,24 +280,35 @@ if ( class_exists( 'WP_Importer' ) ) {
// Get or insert outcome
$outcome_object = get_page_by_title( stripslashes( $outcome ), OBJECT, 'sp_outcome' );
if ( $outcome_object ):
if ( $outcome_object ) :
// Make sure outcome is published
if ( $outcome_object->post_status != 'publish' ):
wp_update_post( array( 'ID' => $outcome_object->ID, 'post_status' => 'publish' ) );
if ( $outcome_object->post_status != 'publish' ) :
wp_update_post(
array(
'ID' => $outcome_object->ID,
'post_status' => 'publish',
)
);
endif;
// Get outcome slug
$outcome_slug = $outcome_object->post_name;
else:
else :
// Insert outcome
$outcome_id = wp_insert_post( array( 'post_type' => 'sp_outcome', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $outcome ) ) );
$outcome_id = wp_insert_post(
array(
'post_type' => 'sp_outcome',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $outcome ),
)
);
// Get outcome slug
$post_data = get_post( $outcome_id, ARRAY_A );
$outcome_slug = $post_data['post_name'];
$post_data = get_post( $outcome_id, ARRAY_A );
$outcome_slug = $post_data['post_name'];
// Flag as import
update_post_meta( $outcome_id, '_sp_import', 1 );
@@ -284,7 +316,7 @@ if ( class_exists( 'WP_Importer' ) ) {
endif;
// Add to team results array
$team_results[ 'outcome' ][] = $outcome_slug;
$team_results['outcome'][] = $outcome_slug;
endforeach;
@@ -292,7 +324,7 @@ if ( class_exists( 'WP_Importer' ) ) {
$event_results = get_post_meta( $id, 'sp_results', true );
// Create new array if results not exists
if ( ! $event_results ):
if ( ! $event_results ) :
$event_results = array();
endif;
@@ -317,9 +349,9 @@ if ( class_exists( 'WP_Importer' ) ) {
// Update event with new name
$post = array(
'ID' => $id,
'ID' => $id,
'post_title' => $title,
'post_name' => $id,
'post_name' => $id,
);
wp_update_post( $post );
@@ -328,7 +360,7 @@ if ( class_exists( 'WP_Importer' ) ) {
endif;
// Add new player if player name is given
if ( sizeof( $player ) > 0 && ! empty( $player[0] ) ):
if ( sizeof( $player ) > 0 && ! empty( $player[0] ) ) :
// Get and unset player name leaving us with the performance
$player_name = $player[0];
@@ -338,11 +370,16 @@ if ( class_exists( 'WP_Importer' ) ) {
$player_object = get_page_by_title( stripslashes( $player_name ), OBJECT, 'sp_player' );
// Get or insert player
if ( $player_object ):
if ( $player_object ) :
// Make sure player is published
if ( $player_object->post_status != 'publish' ):
wp_update_post( array( 'ID' => $player_object->ID, 'post_status' => 'publish' ) );
if ( $player_object->post_status != 'publish' ) :
wp_update_post(
array(
'ID' => $player_object->ID,
'post_status' => 'publish',
)
);
endif;
// Get player ID
@@ -351,10 +388,16 @@ if ( class_exists( 'WP_Importer' ) ) {
// Get player number
$player_number = get_post_meta( $player_id, 'sp_number', true );
else:
else :
// Insert player
$player_id = wp_insert_post( array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $player_name ) ) );
$player_id = wp_insert_post(
array(
'post_type' => 'sp_player',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $player_name ),
)
);
// Flag as import
update_post_meta( $player_id, '_sp_import', 1 );
@@ -368,29 +411,29 @@ if ( class_exists( 'WP_Importer' ) ) {
endif;
// Update league
if ( $league ):
if ( $league ) :
wp_set_object_terms( $player_id, $league, 'sp_league', true );
endif;
// Update season
if ( $season ):
if ( $season ) :
wp_set_object_terms( $player_id, $season, 'sp_season', true );
endif;
// Add to event if exists
if ( isset( $id ) ):
if ( isset( $id ) ) :
// Add player to event
add_post_meta( $id, 'sp_player', $player_id );
// Add player performance to array if team is available
if ( isset( $team_id ) ):
if ( isset( $team_id ) ) :
// Initialize performance array
$performance = array( 'number' => $player_number );
// Map keys to player performance
foreach ( $performance_labels as $key => $label ):
foreach ( $performance_labels as $key => $label ) :
$performance[ $key ] = array_shift( $player );
endforeach;
$players[ $team_id ][ $player_id ] = $performance;
@@ -398,17 +441,17 @@ if ( class_exists( 'WP_Importer' ) ) {
// Get player teams
$player_teams = get_post_meta( $player_id, 'sp_team', false );
$current_team = get_post_meta( $player_id, 'sp_current_team', true );
$past_teams = get_post_meta( $player_id, 'sp_past_team', false );
$past_teams = get_post_meta( $player_id, 'sp_past_team', false );
// Add team if not exists in player
if ( ! in_array( $team_id, $player_teams ) ):
if ( ! in_array( $team_id, $player_teams ) ) :
add_post_meta( $player_id, 'sp_team', $team_id );
endif;
// Add as past team or set current team if not set
if ( ! $current_team ):
if ( ! $current_team ) :
update_post_meta( $player_id, 'sp_current_team', $team_id );
elseif ( $current_team != $team_id && ! in_array( $team_id, $past_teams ) ):
elseif ( $current_team != $team_id && ! in_array( $team_id, $past_teams ) ) :
add_post_meta( $player_id, 'sp_past_team', $team_id );
endif;
@@ -421,13 +464,13 @@ if ( class_exists( 'WP_Importer' ) ) {
endforeach;
// Add player performance to last event if available
if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ):
if ( isset( $id ) && isset( $players ) && sizeof( $players ) > 0 ) :
update_post_meta( $id, 'sp_players', $players );
endif;
// Show Result
echo '<div class="updated settings-error below-h2"><p>
'.sprintf( __( 'Import complete - imported <strong>%s</strong> events and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).'
' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> events and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
</p></div>';
$this->import_end();
@@ -437,7 +480,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* Performs post-import cleanup of files and the cache
*/
function import_end() {
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_event') . '">' . __( 'View Events', 'sportspress' ) . '</a>' . '</p>';
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_event' ) . '">' . __( 'View Events', 'sportspress' ) . '</a>' . '</p>';
do_action( 'import_end' );
}
@@ -450,7 +493,7 @@ if ( class_exists( 'WP_Importer' ) ) {
*/
function greet() {
echo '<div class="narrow">';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
echo '<p>' . sprintf( __( 'Events need to be defined with columns in a specific order (3+ columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/events-sample.csv' ) . '</p>';
echo '<p>' . sprintf( __( 'Supports CSV files generated by <a href="%s">LeagueLobster</a>.', 'sportspress' ), 'http://tboy.co/leaguelobster' ) . '</p>';
wp_import_upload_form( 'admin.php?import=sp_event_csv&step=1' );
@@ -473,11 +516,11 @@ if ( class_exists( 'WP_Importer' ) ) {
<fieldset id="post-formats-select">
<ul>
<?php
foreach( (new SP_Formats)->event as $name => $title ) {
?>
foreach ( ( new SP_Formats() )->event as $name => $title ) {
?>
<li><input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $name ); ?>" checked="checked"> <label for="post-format-<?php echo esc_attr( $name ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $name ); ?>"><?php echo esc_html( $title ); ?></label></li>
<?php
}
}
?>
</ul>
</fieldset>
@@ -485,56 +528,60 @@ if ( class_exists( 'WP_Importer' ) ) {
</tr>
<tr>
<th scope="row"><label><?php _e( 'League', 'sportspress' ); ?></label><br/></th>
<td><?php
<td>
<?php
$args = array(
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'values' => 'slug',
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'values' => 'slug',
'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ),
);
if ( ! sp_dropdown_taxonomies( $args ) ):
if ( ! sp_dropdown_taxonomies( $args ) ) :
echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?></td>
?>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Season', 'sportspress' ); ?></label><br/></th>
<td><?php
<td>
<?php
$args = array(
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'values' => 'slug',
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'values' => 'slug',
'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ),
);
if ( ! sp_dropdown_taxonomies( $args ) ):
if ( ! sp_dropdown_taxonomies( $args ) ) :
echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?></td>
?>
</td>
</tr>
<tr>
<th scope="row" class="titledesc">
<?php _e( 'Date Format', 'sportspress' ); ?>
</th>
<td class="forminp forminp-radio">
<fieldset>
<ul>
<td class="forminp forminp-radio">
<fieldset>
<ul>
<li>
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
</li>
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
</li>
<li>
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
</li>
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
</li>
<li>
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
</li>
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
</li>
</ul>
</fieldset>
</td>
</tr>
</tbody>
</table>
</fieldset>
</td>
</tr>
</tbody>
</table>
<?php
}
}

View File

@@ -2,13 +2,15 @@
/**
* Event Performance importer - import box scores into SportsPress.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) {
class SP_Event_Performance_Importer extends SP_Importer {
@@ -20,14 +22,15 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void
*/
public function __construct() {
$this->import_page = 'sp_event_performance_csv';
$this->import_page = 'sp_event_performance_csv';
$this->import_label = __( 'Import Box Score', 'sportspress' );
$this->columns = array(
$this->columns = array(
'sp_player' => __( 'Player', 'sportspress' ),
);
$performance_labels = sp_get_var_labels( 'sp_performance' );
if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) )
if ( $performance_labels && is_array( $performance_labels ) && sizeof( $performance_labels ) ) {
$this->columns = array_merge( $this->columns, $performance_labels );
}
}
/**
@@ -41,7 +44,7 @@ if ( class_exists( 'WP_Importer' ) ) {
function import( $array = array(), $columns = array( 'sp_player' ) ) {
$this->imported = $this->skipped = 0;
if ( ! is_array( $array ) || ! sizeof( $array ) ):
if ( ! is_array( $array ) || ! sizeof( $array ) ) :
$this->footer();
die();
endif;
@@ -52,36 +55,44 @@ if ( class_exists( 'WP_Importer' ) ) {
$event = ( empty( $_POST['sp_event'] ) ? false : sanitize_text_field( $_POST['sp_event'] ) );
$teams = ( empty( $_POST['sp_teams'] ) ? false : sanitize_text_field( $_POST['sp_teams'] ) );
$index = ( empty( $_POST['sp_index'] ) ? false : sanitize_text_field( $_POST['sp_index'] ) );
$team = ( empty( $_POST['sp_team'] ) ? false : sanitize_text_field( $_POST['sp_team'] ) );
$team = ( empty( $_POST['sp_team'] ) ? false : sanitize_text_field( $_POST['sp_team'] ) );
$team_players = array( 0 );
$team_players = array( 0 );
$team_performance = array();
$name_index = (int) array_search( 'sp_player', $columns );
$name_index = (int) array_search( 'sp_player', $columns );
foreach ( $rows as $row ):
foreach ( $rows as $row ) :
$row = array_filter( $row );
if ( empty( $row ) ) continue;
if ( empty( $row ) ) {
continue;
}
$player_name = sp_array_value( $row, $name_index );
if ( ! $player_name ):
if ( ! $player_name ) :
$this->skipped ++;
continue;
endif;
$player_object = get_page_by_title( stripslashes( $player_name ), OBJECT, 'sp_player' );
if ( $player_object ):
if ( $player_object ) :
// Get player ID
$player_id = $player_object->ID;
else:
else :
// Insert player
$player_id = wp_insert_post( array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $player_name ) ) );
$player_id = wp_insert_post(
array(
'post_type' => 'sp_player',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $player_name ),
)
);
// Flag as import
update_post_meta( $player_id, '_sp_import', 1 );
@@ -89,10 +100,12 @@ if ( class_exists( 'WP_Importer' ) ) {
endif;
$team_players[] = $player_id;
$player = array();
$player = array();
foreach ( $columns as $i => $key ):
if ( 'sp_player' === $key ) continue;
foreach ( $columns as $i => $key ) :
if ( 'sp_player' === $key ) {
continue;
}
$player[ $key ] = sp_array_value( $row, $i, '' );
endforeach;
@@ -100,13 +113,13 @@ if ( class_exists( 'WP_Importer' ) ) {
endforeach;
if ( $event && $team ):
if ( $event && $team ) :
$the_players = get_post_meta( $event, 'sp_player', false );
$players = array();
for ( $i = 0; $i < $teams; $i++ ):
if ( $index == $i ):
$players = array();
for ( $i = 0; $i < $teams; $i++ ) :
if ( $index == $i ) :
array_push( $players, $team_players );
else:
else :
array_push( $players, sp_array_between( $the_players, 0, $i ) );
endif;
endfor;
@@ -114,15 +127,15 @@ if ( class_exists( 'WP_Importer' ) ) {
$this->imported = sizeof( $team_players ) - 1;
$performance = (array) get_post_meta( $event, 'sp_players', true );
$performance = array_filter( $performance );
$performance = (array) get_post_meta( $event, 'sp_players', true );
$performance = array_filter( $performance );
$performance[ $team ] = $team_performance;
update_post_meta( $event, 'sp_players', $performance );
endif;
// Show Result
echo '<div class="updated settings-error below-h2"><p>
'.sprintf( __( 'Import complete - imported <strong>%s</strong> rows and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).'
' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> rows and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
</p></div>';
$this->import_end( $event );
@@ -132,7 +145,15 @@ if ( class_exists( 'WP_Importer' ) ) {
* Performs post-import cleanup of files and the cache
*/
function import_end( $event = 0 ) {
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( add_query_arg( array( 'post' => $event, 'action' => 'edit' ), 'post.php' ) ) . '">' . __( 'View Event', 'sportspress' ) . '</a>' . '</p>';
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url(
add_query_arg(
array(
'post' => $event,
'action' => 'edit',
),
'post.php'
)
) . '">' . __( 'View Event', 'sportspress' ) . '</a>' . '</p>';
do_action( 'import_end' );
}
@@ -149,8 +170,14 @@ if ( class_exists( 'WP_Importer' ) ) {
echo '<div class="narrow">';
if ( $event ) {
$args = array_merge( $_REQUEST, array( 'import' => 'sp_event_performance_csv', 'step' => '1' ) );
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
$args = array_merge(
$_REQUEST,
array(
'import' => 'sp_event_performance_csv',
'step' => '1',
)
);
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
echo '<p>' . sprintf( __( 'Box scores need to be defined with columns in a specific order. <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/event-performance-sample.csv' ) . '</p>';
wp_import_upload_form( add_query_arg( $args, 'admin.php' ) );
} else {
@@ -167,10 +194,10 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void
*/
function options() {
$event = sp_array_value( $_REQUEST, 'event', 0, 'key' );
$teams = sp_array_value( $_REQUEST, 'teams', 0, 'key' );
$index = sp_array_value( $_REQUEST, 'index', 0, 'key' );
$team = sp_array_value( $_REQUEST, 'team', 0, 'key' );
$event = sp_array_value( $_REQUEST, 'event', 0, 'key' );
$teams = sp_array_value( $_REQUEST, 'teams', 0, 'key' );
$index = sp_array_value( $_REQUEST, 'index', 0, 'key' );
$team = sp_array_value( $_REQUEST, 'team', 0, 'key' );
$include = get_post_meta( $event, 'sp_team', false );
?>
<table class="form-table">
@@ -192,10 +219,10 @@ if ( class_exists( 'WP_Importer' ) ) {
<?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_team',
'values' => 'ID',
'selected' => $team,
'include' => $include,
'name' => 'sp_team',
'values' => 'ID',
'selected' => $team,
'include' => $include,
);
sp_dropdown_pages( $args );
?>

View File

@@ -2,13 +2,15 @@
/**
* Fixture importer - import fixtures into SportsPress.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @version 2.7
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @version 2.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) {
class SP_Fixture_Importer extends SP_Importer {
@@ -20,17 +22,17 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void
*/
public function __construct() {
$this->import_page = 'sp_fixture_csv';
$this->import_page = 'sp_fixture_csv';
$this->import_label = __( 'Import Fixtures', 'sportspress' );
$this->columns = array(
$this->columns = array(
'post_date' => __( 'Date', 'sportspress' ),
'post_time' => __( 'Time', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_home' => __( 'Home', 'sportspress' ),
'sp_away' => __( 'Away', 'sportspress' ),
'sp_day' => __( 'Match Day', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_home' => __( 'Home', 'sportspress' ),
'sp_away' => __( 'Away', 'sportspress' ),
'sp_day' => __( 'Match Day', 'sportspress' ),
);
$this->optionals = array( 'sp_day' );
$this->optionals = array( 'sp_day' );
}
/**
@@ -44,7 +46,7 @@ if ( class_exists( 'WP_Importer' ) ) {
function import( $array = array(), $columns = array( 'post_title' ) ) {
$this->imported = $this->skipped = 0;
if ( ! is_array( $array ) || ! sizeof( $array ) ):
if ( ! is_array( $array ) || ! sizeof( $array ) ) :
$this->footer();
die();
endif;
@@ -53,19 +55,21 @@ if ( class_exists( 'WP_Importer' ) ) {
// Get event format, league, and season from post vars
$event_format = ( empty( $_POST['sp_format'] ) ? false : $_POST['sp_format'] );
$league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : $_POST['sp_league'] );
$season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : $_POST['sp_season'] );
$date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : $_POST['sp_date_format'] );
$league = ( sp_array_value( $_POST, 'sp_league', '-1' ) == '-1' ? false : $_POST['sp_league'] );
$season = ( sp_array_value( $_POST, 'sp_season', '-1' ) == '-1' ? false : $_POST['sp_season'] );
$date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : $_POST['sp_date_format'] );
foreach ( $rows as $row ):
foreach ( $rows as $row ) :
$row = array_filter( $row );
if ( empty( $row ) ) continue;
if ( empty( $row ) ) {
continue;
}
$meta = array();
foreach ( $columns as $index => $key ):
foreach ( $columns as $index => $key ) :
$meta[ $key ] = sp_array_value( $row, $index );
endforeach;
@@ -83,15 +87,15 @@ if ( class_exists( 'WP_Importer' ) ) {
);
// Add new event if date is given
if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ):
if ( sizeof( $event ) > 0 && ! empty( $event[0] ) ) :
// List event columns
list( $date, $time, $venue, $day ) = $event;
// Format date
$date = str_replace( '/', '-', trim( $date ) );
$date = str_replace( '/', '-', trim( $date ) );
$date_array = explode( '-', $date );
switch ( $date_format ):
switch ( $date_format ) :
case 'dd/mm/yyyy':
$date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' .
substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' .
@@ -109,12 +113,17 @@ if ( class_exists( 'WP_Importer' ) ) {
endswitch;
// Add time to date if given
if ( ! empty( $time ) ):
if ( ! empty( $time ) ) :
$date .= ' ' . trim( $time );
endif;
// Define post type args
$args = array( 'post_type' => 'sp_event', 'post_status' => 'publish', 'post_date' => $date, 'post_title' => __( 'Event', 'sportspress' ) );
$args = array(
'post_type' => 'sp_event',
'post_status' => 'publish',
'post_date' => $date,
'post_title' => __( 'Event', 'sportspress' ),
);
// Insert event
$id = wp_insert_post( $args );
@@ -123,25 +132,25 @@ if ( class_exists( 'WP_Importer' ) ) {
update_post_meta( $id, '_sp_import', 1 );
// Update event format
if ( $event_format ):
if ( $event_format ) :
update_post_meta( $id, 'sp_format', $event_format );
endif;
// Update league
if ( $league ):
if ( $league ) :
wp_set_object_terms( $id, $league, 'sp_league', false );
endif;
// Update season
if ( $season ):
if ( $season ) :
wp_set_object_terms( $id, $season, 'sp_season', false );
endif;
// Update venue
if ( $venue == '' ) {
$team = reset( $teams );
$team = reset( $teams );
$team_object = get_page_by_title( stripslashes( $team ), OBJECT, 'sp_team' );
$venue = sp_get_the_term_id( $team_object->ID, 'sp_venue' );
$venue = sp_get_the_term_id( $team_object->ID, 'sp_venue' );
}
wp_set_object_terms( $id, $venue, 'sp_venue', false );
@@ -156,30 +165,41 @@ if ( class_exists( 'WP_Importer' ) ) {
endif;
// Add teams to event
if ( sizeof( $teams ) > 0 ):
if ( sizeof( $teams ) > 0 ) :
foreach ( $teams as $team_name ):
foreach ( $teams as $team_name ) :
if ( '' !== $team_name ):
if ( '' !== $team_name ) :
// Find out if team exists
$team_object = get_page_by_title( stripslashes( $team_name ), OBJECT, 'sp_team' );
// Get or insert team
if ( $team_object ):
if ( $team_object ) :
// Make sure team is published
if ( $team_object->post_status != 'publish' ):
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
if ( $team_object->post_status != 'publish' ) :
wp_update_post(
array(
'ID' => $team_object->ID,
'post_status' => 'publish',
)
);
endif;
// Get team ID
$team_id = $team_object->ID;
else:
else :
// Insert team
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $team_name ) ) );
$team_id = wp_insert_post(
array(
'post_type' => 'sp_team',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $team_name ),
)
);
// Flag as import
update_post_meta( $team_id, '_sp_import', 1 );
@@ -187,17 +207,17 @@ if ( class_exists( 'WP_Importer' ) ) {
endif;
// Update league
if ( $league ):
if ( $league ) :
wp_set_object_terms( $team_id, $league, 'sp_league', true );
endif;
// Update season
if ( $season ):
if ( $season ) :
wp_set_object_terms( $team_id, $season, 'sp_season', true );
endif;
// Add to event if exists
if ( isset( $id ) ):
if ( isset( $id ) ) :
// Add team to event
add_post_meta( $id, 'sp_team', $team_id );
@@ -217,19 +237,19 @@ if ( class_exists( 'WP_Importer' ) ) {
// Update event with new name
$post = array(
'ID' => $id,
'ID' => $id,
'post_title' => $title,
'post_name' => $id,
'post_name' => $id,
);
wp_update_post( $post );
endif;
else:
else :
// Add empty team to event
add_post_meta( $id, 'sp_team', -1 );
endif;
endforeach;
@@ -240,7 +260,7 @@ if ( class_exists( 'WP_Importer' ) ) {
// Show Result
echo '<div class="updated settings-error below-h2"><p>
'.sprintf( __( 'Import complete - imported <strong>%s</strong> events and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).'
' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> events and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
</p></div>';
$this->import_end();
@@ -250,7 +270,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* Performs post-import cleanup of files and the cache
*/
function import_end() {
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_event') . '">' . __( 'View Fixtures', 'sportspress' ) . '</a>' . '</p>';
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_event' ) . '">' . __( 'View Fixtures', 'sportspress' ) . '</a>' . '</p>';
do_action( 'import_end' );
}
@@ -263,7 +283,7 @@ if ( class_exists( 'WP_Importer' ) ) {
*/
function greet() {
echo '<div class="narrow">';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
echo '<p>' . sprintf( __( 'Fixtures need to be defined with columns in a specific order (4+ columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/fixtures-sample.csv' ) . '</p>';
echo '<p>' . sprintf( __( 'Supports CSV files generated by <a href="%s">LeagueLobster</a>.', 'sportspress' ), 'http://tboy.co/leaguelobster' ) . '</p>';
wp_import_upload_form( 'admin.php?import=sp_fixture_csv&step=1' );
@@ -293,56 +313,60 @@ if ( class_exists( 'WP_Importer' ) ) {
</tr>
<tr>
<th scope="row"><label><?php _e( 'League', 'sportspress' ); ?></label><br/></th>
<td><?php
<td>
<?php
$args = array(
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'values' => 'slug',
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'values' => 'slug',
'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ),
);
if ( ! sp_dropdown_taxonomies( $args ) ):
if ( ! sp_dropdown_taxonomies( $args ) ) :
echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
sp_taxonomy_adder( 'sp_league', 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?></td>
?>
</td>
</tr>
<tr>
<th scope="row"><label><?php _e( 'Season', 'sportspress' ); ?></label><br/></th>
<td><?php
<td>
<?php
$args = array(
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'values' => 'slug',
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'values' => 'slug',
'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ),
);
if ( ! sp_dropdown_taxonomies( $args ) ):
if ( ! sp_dropdown_taxonomies( $args ) ) :
echo '<p>' . __( 'None', 'sportspress' ) . '</p>';
sp_taxonomy_adder( 'sp_season', 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?></td>
?>
</td>
</tr>
<tr>
<th scope="row" class="titledesc">
<?php _e( 'Date Format', 'sportspress' ); ?>
</th>
<td class="forminp forminp-radio">
<fieldset>
<ul>
<td class="forminp forminp-radio">
<fieldset>
<ul>
<li>
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
</li>
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
</li>
<li>
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
</li>
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
</li>
<li>
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
</li>
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
</li>
</ul>
</fieldset>
</td>
</tr>
</tbody>
</table>
</fieldset>
</td>
</tr>
</tbody>
</table>
<?php
}
}

View File

@@ -2,13 +2,15 @@
/**
* SportsPress Importer
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) {
class SP_Importer extends WP_Importer {
@@ -21,7 +23,7 @@ if ( class_exists( 'WP_Importer' ) ) {
var $imported;
var $skipped;
var $import_label;
var $columns = array();
var $columns = array();
var $optionals = array();
/**
@@ -35,7 +37,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* Enqueue scripts
*/
public function admin_scripts() {
wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret' ), SP_VERSION, true );
wp_enqueue_script( 'sportspress-admin', SP()->plugin_url() . '/assets/js/admin/sportspress-admin.js', array( 'jquery', 'chosen', 'jquery-ui-core', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-tiptip', 'jquery-caret' ), SP_VERSION, true );
}
/**
@@ -46,32 +48,36 @@ if ( class_exists( 'WP_Importer' ) ) {
function dispatch() {
$this->header();
if ( ! empty( $_POST['delimiter'] ) )
if ( ! empty( $_POST['delimiter'] ) ) {
$this->delimiter = stripslashes( trim( sanitize_text_field( $_POST['delimiter'] ) ) );
}
if ( ! $this->delimiter )
if ( ! $this->delimiter ) {
$this->delimiter = ',';
}
$step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
switch ( $step ):
switch ( $step ) :
case 0:
$this->greet();
break;
case 1:
check_admin_referer( 'import-upload' );
if ( $this->handle_upload() ):
if ( $this->handle_upload() ) :
if ( $this->id )
if ( $this->id ) {
$file = get_attached_file( $this->id );
else
} else {
$file = ABSPATH . $this->file_url;
}
add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
if ( function_exists( 'gc_enable' ) )
if ( function_exists( 'gc_enable' ) ) {
gc_enable();
}
@set_time_limit(0);
@set_time_limit( 0 );
@ob_flush();
@flush();
@@ -80,7 +86,7 @@ if ( class_exists( 'WP_Importer' ) ) {
break;
case 2:
check_admin_referer( 'import-upload' );
if ( isset( $_POST['sp_import'] ) ):
if ( isset( $_POST['sp_import'] ) ) :
$columns = array_filter( sp_array_value( $_POST, 'sp_columns', array( 'post_title' ) ) );
$this->import( $_POST['sp_import'], array_values( $columns ) );
endif;
@@ -100,7 +106,7 @@ if ( class_exists( 'WP_Importer' ) ) {
?>
<select name="sp_columns[]" data-index="<?php echo array_search( $selected, array_keys( $this->columns ) ); ?>">
<option value="0">&mdash; <?php _e( 'Disable', 'sportspress' ); ?> &mdash;</option>
<?php foreach ( $this->columns as $key => $label ): ?>
<?php foreach ( $this->columns as $key => $label ) : ?>
<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $selected, $key ); ?>><?php echo esc_html( $label ); ?></option>
<?php endforeach; ?>
</select>
@@ -119,26 +125,26 @@ if ( class_exists( 'WP_Importer' ) ) {
$this->imported = $this->skipped = 0;
if ( ! is_file($file) ):
if ( ! is_file( $file ) ) :
$this->footer();
die();
endif;
ini_set( 'auto_detect_line_endings', '1' );
if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ):
if ( ( $handle = fopen( $file, 'r' ) ) !== false ) :
$header = fgetcsv( $handle, 0, $this->delimiter );
if ( sizeof( $header ) >= 1 ):
if ( sizeof( $header ) >= 1 ) :
$action = 'admin.php?import=' . $this->import_page . '&step=2';
?>
<form enctype="multipart/form-data" id="import-upload-form" class="sportspress" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
<form enctype="multipart/form-data" id="import-upload-form" class="sportspress" method="post" action="<?php echo esc_attr( wp_nonce_url( $action, 'import-upload' ) ); ?>">
<?php $this->options(); ?>
<table class="wp-list-table sp-data-table sp-import-table widefat fixed pages">
<thead>
<tr>
<?php foreach ( $this->columns as $key => $label ): ?>
<?php foreach ( $this->columns as $key => $label ) : ?>
<th scope="col" class="manage-column">
<?php $this->dropdown( $key ); ?>
</th>
@@ -149,21 +155,35 @@ if ( class_exists( 'WP_Importer' ) ) {
</tr>
</thead>
<tbody>
<?php while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ): ?>
<?php while ( ( $row = fgetcsv( $handle, 0, $this->delimiter ) ) !== false ) : ?>
<tr>
<?php $index = 0; foreach ( $this->columns as $key => $label ): $value = sp_array_value( $row, $index ); ?>
<?php
$index = 0;
foreach ( $this->columns as $key => $label ) :
$value = sp_array_value( $row, $index );
?>
<td>
<input type="text" class="widefat" value="<?php echo esc_attr( $value ); ?>" name="sp_import[]"<?php if ( in_array( $key, $this->optionals ) ) { ?> placeholder="<?php _e( 'Default', 'sportspress' ); ?>"<?php } ?>>
<input type="text" class="widefat" value="<?php echo esc_attr( $value ); ?>" name="sp_import[]"
<?php
if ( in_array( $key, $this->optionals ) ) {
?>
placeholder="<?php _e( 'Default', 'sportspress' ); ?>"<?php } ?>>
</td>
<?php $index ++; endforeach; ?>
<?php
$index ++;
endforeach;
?>
<td class="sp-actions-column">
<a href="#" title="<?php _e( 'Delete row', 'sportspress' ); ?>" class="dashicons dashicons-dismiss sp-delete-row"></a>
<a href="#" title="<?php _e( 'Insert row after', 'sportspress' ); ?>" class="dashicons dashicons-plus-alt sp-add-row"></a>
</td>
</tr>
<?php $this->imported++; endwhile; ?>
<?php
$this->imported++;
endwhile;
?>
<tr>
<?php foreach ( $this->columns as $key => $label ): ?>
<?php foreach ( $this->columns as $key => $label ) : ?>
<td>
<input type="text" class="widefat" name="sp_import[]">
</td>
@@ -172,17 +192,17 @@ if ( class_exists( 'WP_Importer' ) ) {
<a href="#" title="<?php _e( 'Insert row after', 'sportspress' ); ?>" class="dashicons dashicons-plus-alt sp-add-row"></a>
</td>
</tr>
</tbody>
</tbody>
</table>
<p class="sp-post-count alignright">
<?php printf( __( 'Displaying %s&#8211;%s of %s', 'sportspress' ), 1, $this->imported+1, $this->imported+1 ); ?>
<?php printf( __( 'Displaying %1$s&#8211;%2$s of %3$s', 'sportspress' ), 1, $this->imported + 1, $this->imported + 1 ); ?>
</p>
<p class="submit">
<input type="submit" class="button button-primary button-hero" value="<?php echo esc_attr( $this->import_label ); ?>" />
</p>
</form>
<?php
else:
else :
echo '<p><strong>' . __( 'Sorry, there has been an error.', 'sportspress' ) . '</strong><br />';
_e( 'The CSV is invalid.', 'sportspress' ) . '</p>';
@@ -191,7 +211,7 @@ if ( class_exists( 'WP_Importer' ) ) {
endif;
fclose( $handle );
fclose( $handle );
endif;
}
@@ -199,7 +219,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* format_data_from_csv function.
*
* @access public
* @param mixed $data
* @param mixed $data
* @param string $enc
* @return string
*/
@@ -239,7 +259,6 @@ if ( class_exists( 'WP_Importer' ) ) {
return false;
}
}
return true;
@@ -276,6 +295,7 @@ if ( class_exists( 'WP_Importer' ) ) {
/**
* Added to http_request_timeout filter to force timeout at 60 seconds during import
*
* @param int $val
* @return int 60
*/

View File

@@ -2,13 +2,15 @@
/**
* Official importer - import officials into SportsPress.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @version 2.5.1
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @version 2.5.1
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) {
class SP_Official_Importer extends SP_Importer {
@@ -20,9 +22,9 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void
*/
public function __construct() {
$this->import_page = 'sp_official_csv';
$this->import_page = 'sp_official_csv';
$this->import_label = __( 'Import Officials', 'sportspress' );
$this->columns = array(
$this->columns = array(
'post_title' => __( 'Name', 'sportspress' ),
);
parent::__construct();
@@ -39,33 +41,39 @@ if ( class_exists( 'WP_Importer' ) ) {
function import( $array = array(), $columns = array( 'post_title' ) ) {
$this->imported = $this->skipped = 0;
if ( ! is_array( $array ) || ! sizeof( $array ) ):
if ( ! is_array( $array ) || ! sizeof( $array ) ) :
$this->footer();
die();
endif;
$rows = array_chunk( $array, sizeof( $columns ) );
foreach ( $rows as $row ):
foreach ( $rows as $row ) :
$row = array_filter( $row );
if ( empty( $row ) ) continue;
if ( empty( $row ) ) {
continue;
}
$meta = array();
foreach ( $columns as $index => $key ):
foreach ( $columns as $index => $key ) :
$meta[ $key ] = sp_array_value( $row, $index );
endforeach;
$name = sp_array_value( $meta, 'post_title' );
if ( ! $name ):
if ( ! $name ) :
$this->skipped++;
continue;
endif;
$args = array( 'post_type' => 'sp_official', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) );
$args = array(
'post_type' => 'sp_official',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $name ),
);
$id = wp_insert_post( $args );
@@ -75,7 +83,7 @@ if ( class_exists( 'WP_Importer' ) ) {
// Show Result
echo '<div class="updated settings-error below-h2"><p>
'.sprintf( __( 'Import complete - imported <strong>%s</strong> officials and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).'
' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> officials and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
</p></div>';
$this->import_end();
@@ -85,7 +93,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* Performs post-import cleanup of files and the cache
*/
function import_end() {
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_official') . '">' . __( 'View Officials', 'sportspress' ) . '</a>' . '</p>';
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_official' ) . '">' . __( 'View Officials', 'sportspress' ) . '</a>' . '</p>';
do_action( 'import_end' );
}
@@ -108,7 +116,7 @@ if ( class_exists( 'WP_Importer' ) ) {
*/
function greet() {
echo '<div class="narrow">';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
echo '<p>' . sprintf( __( 'Officials need to be defined with columns in a specific order. <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/officials-sample.csv' ) . '</p>';
wp_import_upload_form( 'admin.php?import=sp_official_csv&step=1' );
echo '</div>';

View File

@@ -2,13 +2,15 @@
/**
* Player importer - import players into SportsPress.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @version 2.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) {
class SP_Player_Importer extends SP_Importer {
@@ -20,17 +22,17 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void
*/
public function __construct() {
$this->import_page = 'sp_player_csv';
$this->import_page = 'sp_player_csv';
$this->import_label = __( 'Import Players', 'sportspress' );
$this->columns = array(
'sp_number' => __( 'Squad Number', 'sportspress' ),
'post_title' => __( 'Name', 'sportspress' ),
'sp_position' => __( 'Positions', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
$this->columns = array(
'sp_number' => __( 'Squad Number', 'sportspress' ),
'post_title' => __( 'Name', 'sportspress' ),
'sp_position' => __( 'Positions', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
'sp_nationality' => __( 'Nationality', 'sportspress' ),
'post_date' => __( 'Date of Birth', 'sportspress' ),
'post_date' => __( 'Date of Birth', 'sportspress' ),
);
parent::__construct();
}
@@ -46,21 +48,23 @@ if ( class_exists( 'WP_Importer' ) ) {
function import( $array = array(), $columns = array( 'post_title' ) ) {
$this->imported = $this->skipped = 0;
if ( ! is_array( $array ) || ! sizeof( $array ) ):
if ( ! is_array( $array ) || ! sizeof( $array ) ) :
$this->footer();
die();
endif;
$rows = array_chunk( $array, sizeof( $columns ) );
// Get Date of Birth format from post vars
$date_format = ( empty( $_POST['sp_date_format'] ) ? 'yyyy/mm/dd' : sanitize_text_field( $_POST['sp_date_format'] ) );
foreach ( $rows as $row ):
foreach ( $rows as $row ) :
$row = array_filter( $row, 'strlen' );
if ( empty( $row ) ) continue;
if ( empty( $row ) ) {
continue;
}
$meta = array();
@@ -76,17 +80,17 @@ if ( class_exists( 'WP_Importer' ) ) {
$meta[ $p ] = '';
}
foreach ( $columns as $index => $key ):
foreach ( $columns as $index => $key ) :
$meta[ $key ] = sp_array_value( $row, $index );
endforeach;
$name = sp_array_value( $meta, 'post_title' );
$date = sp_array_value( $meta, 'post_date' );
// Format date of birth
$date = str_replace( '/', '-', trim( $date ) );
$date = str_replace( '/', '-', trim( $date ) );
$date_array = explode( '-', $date );
switch ( $date_format ):
switch ( $date_format ) :
case 'dd/mm/yyyy':
$date = substr( str_pad( sp_array_value( $date_array, 2, '0000' ), 4, '0', STR_PAD_LEFT ), 0, 4 ) . '-' .
substr( str_pad( sp_array_value( $date_array, 1, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 ) . '-' .
@@ -103,28 +107,37 @@ if ( class_exists( 'WP_Importer' ) ) {
substr( str_pad( sp_array_value( $date_array, 2, '00' ), 2, '0', STR_PAD_LEFT ), 0, 2 );
endswitch;
if ( ! $name ):
if ( ! $name ) :
$this->skipped++;
continue;
endif;
// Get or insert player
$player_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_player' ) : false;
if ( $player_object ):
if ( $player_object->post_status != 'publish' ):
wp_update_post( array( 'ID' => $player_object->ID, 'post_status' => 'publish' ) );
if ( $player_object ) :
if ( $player_object->post_status != 'publish' ) :
wp_update_post(
array(
'ID' => $player_object->ID,
'post_status' => 'publish',
)
);
endif;
$id = $player_object->ID;
// Handle preservable data.
foreach ( $preservable_metas_keys as $p ) {
$terms = wp_get_object_terms( $id, $p, array( 'fields' => 'names' ) );
$terms = wp_get_object_terms( $id, $p, array( 'fields' => 'names' ) );
$meta[ $p ] .= '|' . implode( '|', $terms );
}
else:
$args = array( 'post_type' => 'sp_player', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) );
else :
$args = array(
'post_type' => 'sp_player',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $name ),
);
// Check if a DoB was set
if( '0000-00-00' !== $date ){
$args['post_date'] = $date;
if ( '0000-00-00' !== $date ) {
$args['post_date'] = $date;
}
$id = wp_insert_post( $args );
@@ -148,18 +161,29 @@ if ( class_exists( 'WP_Importer' ) ) {
wp_set_object_terms( $id, $seasons, 'sp_season', false );
// Update teams
$teams = (array)explode( '|', sp_array_value( $meta, 'sp_team' ) );
$i = 0;
foreach ( $teams as $team ):
$teams = (array) explode( '|', sp_array_value( $meta, 'sp_team' ) );
$i = 0;
foreach ( $teams as $team ) :
// Get or insert team
$team_object = get_page_by_title( stripslashes( $team ), OBJECT, 'sp_team' );
if ( $team_object ):
if ( $team_object->post_status != 'publish' ):
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
if ( $team_object ) :
if ( $team_object->post_status != 'publish' ) :
wp_update_post(
array(
'ID' => $team_object->ID,
'post_status' => 'publish',
)
);
endif;
$team_id = $team_object->ID;
else:
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $team ) ) );
else :
$team_id = wp_insert_post(
array(
'post_type' => 'sp_team',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $team ),
)
);
// Flag as import
update_post_meta( $team_id, '_sp_import', 1 );
wp_set_object_terms( $team_id, $leagues, 'sp_league', false );
@@ -170,7 +194,7 @@ if ( class_exists( 'WP_Importer' ) ) {
add_post_meta( $id, 'sp_team', $team_id );
// Update current team if first in array, otherwise use as past team
if ( $i == 0 ):
if ( $i == 0 ) :
update_post_meta( $id, 'sp_current_team', $team_id );
else :
add_post_meta( $id, 'sp_past_team', $team_id );
@@ -181,7 +205,9 @@ if ( class_exists( 'WP_Importer' ) ) {
// Update nationality
$nationality = trim( strtolower( sp_array_value( $meta, 'sp_nationality' ) ) );
if ( $nationality == '*' ) $nationality = '';
if ( $nationality == '*' ) {
$nationality = '';
}
update_post_meta( $id, 'sp_nationality', $nationality );
$this->imported++;
@@ -190,7 +216,7 @@ if ( class_exists( 'WP_Importer' ) ) {
// Show Result
echo '<div class="updated settings-error below-h2"><p>
'.sprintf( __( 'Import complete - imported <strong>%s</strong> players and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).'
' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> players and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
</p></div>';
$this->import_end();
@@ -200,7 +226,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* Performs post-import cleanup of files and the cache
*/
function import_end() {
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_player') . '">' . __( 'View Players', 'sportspress' ) . '</a>' . '</p>';
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_player' ) . '">' . __( 'View Players', 'sportspress' ) . '</a>' . '</p>';
do_action( 'import_end' );
}
@@ -223,7 +249,7 @@ if ( class_exists( 'WP_Importer' ) ) {
*/
function greet() {
echo '<div class="narrow">';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
echo '<p>' . sprintf( __( 'Players need to be defined with columns in a specific order (8 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/players-sample.csv' ) . '</p>';
wp_import_upload_form( 'admin.php?import=sp_player_csv&step=1' );
echo '</div>';
@@ -243,22 +269,22 @@ if ( class_exists( 'WP_Importer' ) ) {
<th scope="row" class="titledesc">
<?php _e( 'Date of Birth Format', 'sportspress' ); ?>
</th>
<td class="forminp forminp-radio">
<fieldset>
<ul>
<td class="forminp forminp-radio">
<fieldset>
<ul>
<li>
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
</li>
<label><input name="sp_date_format" value="yyyy/mm/dd" type="radio" checked> yyyy/mm/dd</label>
</li>
<li>
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
</li>
<label><input name="sp_date_format" value="dd/mm/yyyy" type="radio"> dd/mm/yyyy</label>
</li>
<li>
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
</li>
<label><input name="sp_date_format" value="mm/dd/yyyy" type="radio"> mm/dd/yyyy</label>
</li>
</ul>
</fieldset>
</td>
</tr>
</fieldset>
</td>
</tr>
<tr>
<td>
<label>

View File

@@ -2,13 +2,15 @@
/**
* Staff importer - import staff into SportsPress.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @version 2.5.5
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @version 2.5.5
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) {
class SP_Staff_Importer extends SP_Importer {
@@ -20,14 +22,14 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void
*/
public function __construct() {
$this->import_page = 'sp_staff_csv';
$this->import_page = 'sp_staff_csv';
$this->import_label = __( 'Import Staff', 'sportspress' );
$this->columns = array(
'post_title' => __( 'Name', 'sportspress' ),
'sp_role' => __( 'Jobs', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
$this->columns = array(
'post_title' => __( 'Name', 'sportspress' ),
'sp_role' => __( 'Jobs', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
'sp_nationality' => __( 'Nationality', 'sportspress' ),
);
parent::__construct();
@@ -44,42 +46,53 @@ if ( class_exists( 'WP_Importer' ) ) {
function import( $array = array(), $columns = array( 'post_title' ) ) {
$this->imported = $this->skipped = 0;
if ( ! is_array( $array ) || ! sizeof( $array ) ):
if ( ! is_array( $array ) || ! sizeof( $array ) ) :
$this->footer();
die();
endif;
$rows = array_chunk( $array, sizeof( $columns ) );
foreach ( $rows as $row ):
foreach ( $rows as $row ) :
$row = array_filter( $row );
if ( empty( $row ) ) continue;
if ( empty( $row ) ) {
continue;
}
$meta = array();
foreach ( $columns as $index => $key ):
foreach ( $columns as $index => $key ) :
$meta[ $key ] = sp_array_value( $row, $index );
endforeach;
$name = sp_array_value( $meta, 'post_title' );
if ( ! $name ):
if ( ! $name ) :
$this->skipped++;
continue;
endif;
// Get or insert staff
$staff_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_staff' ) : false;
if ( $staff_object ):
if ( $staff_object->post_status != 'publish' ):
wp_update_post( array( 'ID' => $staff_object->ID, 'post_status' => 'publish' ) );
if ( $staff_object ) :
if ( $staff_object->post_status != 'publish' ) :
wp_update_post(
array(
'ID' => $staff_object->ID,
'post_status' => 'publish',
)
);
endif;
$id = $staff_object->ID;
else:
$args = array( 'post_type' => 'sp_staff', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) );
$id = wp_insert_post( $args );
else :
$args = array(
'post_type' => 'sp_staff',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $name ),
);
$id = wp_insert_post( $args );
// Flag as import
update_post_meta( $id, '_sp_import', 1 );
@@ -98,18 +111,29 @@ if ( class_exists( 'WP_Importer' ) ) {
wp_set_object_terms( $id, $seasons, 'sp_season', false );
// Update teams
$teams = (array)explode( '|', sp_array_value( $meta, 'sp_team' ) );
$i = 0;
foreach ( $teams as $team ):
$teams = (array) explode( '|', sp_array_value( $meta, 'sp_team' ) );
$i = 0;
foreach ( $teams as $team ) :
// Get or insert team
$team_object = get_page_by_title( stripslashes( $team ), OBJECT, 'sp_team' );
if ( $team_object ):
if ( $team_object->post_status != 'publish' ):
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
if ( $team_object ) :
if ( $team_object->post_status != 'publish' ) :
wp_update_post(
array(
'ID' => $team_object->ID,
'post_status' => 'publish',
)
);
endif;
$team_id = $team_object->ID;
else:
$team_id = wp_insert_post( array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $team ) ) );
else :
$team_id = wp_insert_post(
array(
'post_type' => 'sp_team',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $team ),
)
);
// Flag as import
update_post_meta( $team_id, '_sp_import', 1 );
wp_set_object_terms( $team_id, $leagues, 'sp_league', false );
@@ -120,7 +144,7 @@ if ( class_exists( 'WP_Importer' ) ) {
add_post_meta( $id, 'sp_team', $team_id );
// Update current team if first in array
if ( $i == 0 ):
if ( $i == 0 ) :
update_post_meta( $id, 'sp_current_team', $team_id );
endif;
@@ -129,7 +153,9 @@ if ( class_exists( 'WP_Importer' ) ) {
// Update nationality
$nationality = trim( strtolower( sp_array_value( $meta, 'sp_nationality' ) ) );
if ( $nationality == '*' ) $nationality = '';
if ( $nationality == '*' ) {
$nationality = '';
}
update_post_meta( $id, 'sp_nationality', $nationality );
$this->imported++;
@@ -138,7 +164,7 @@ if ( class_exists( 'WP_Importer' ) ) {
// Show Result
echo '<div class="updated settings-error below-h2"><p>
'.sprintf( __( 'Import complete - imported <strong>%s</strong> staff and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).'
' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> staff and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
</p></div>';
$this->import_end();
@@ -148,7 +174,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* Performs post-import cleanup of files and the cache
*/
function import_end() {
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_staff') . '">' . __( 'View Staff', 'sportspress' ) . '</a>' . '</p>';
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_staff' ) . '">' . __( 'View Staff', 'sportspress' ) . '</a>' . '</p>';
do_action( 'import_end' );
}
@@ -171,7 +197,7 @@ if ( class_exists( 'WP_Importer' ) ) {
*/
function greet() {
echo '<div class="narrow">';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
echo '<p>' . sprintf( __( 'Staff need to be defined with columns in a specific order (6 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/staff-sample.csv' ) . '</p>';
wp_import_upload_form( 'admin.php?import=sp_staff_csv&step=1' );
echo '</div>';

View File

@@ -2,13 +2,15 @@
/**
* Team importer - import teams into SportsPress.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @version 2.5.5
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Importers
* @version 2.5.5
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( class_exists( 'WP_Importer' ) ) {
class SP_Team_Importer extends SP_Importer {
@@ -20,15 +22,15 @@ if ( class_exists( 'WP_Importer' ) ) {
* @return void
*/
public function __construct() {
$this->import_page = 'sp_team_csv';
$this->import_page = 'sp_team_csv';
$this->import_label = __( 'Import Teams', 'sportspress' );
$this->columns = array(
'post_title' => __( 'Name', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
'sp_url' => __( 'Site URL', 'sportspress' ),
$this->columns = array(
'post_title' => __( 'Name', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
'sp_url' => __( 'Site URL', 'sportspress' ),
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
'sp_venue' => __( 'Home', 'sportspress' ),
'sp_venue' => __( 'Home', 'sportspress' ),
);
parent::__construct();
}
@@ -44,42 +46,53 @@ if ( class_exists( 'WP_Importer' ) ) {
function import( $array = array(), $columns = array( 'post_title' ) ) {
$this->imported = $this->skipped = 0;
if ( ! is_array( $array ) || ! sizeof( $array ) ):
if ( ! is_array( $array ) || ! sizeof( $array ) ) :
$this->footer();
die();
endif;
$rows = array_chunk( $array, sizeof( $columns ) );
foreach ( $rows as $row ):
foreach ( $rows as $row ) :
$row = array_filter( $row );
if ( empty( $row ) ) continue;
if ( empty( $row ) ) {
continue;
}
$meta = array();
foreach ( $columns as $index => $key ):
foreach ( $columns as $index => $key ) :
$meta[ $key ] = sp_array_value( $row, $index );
endforeach;
$name = sp_array_value( $meta, 'post_title' );
if ( ! $name ):
if ( ! $name ) :
$this->skipped++;
continue;
endif;
// Get or insert team
$team_object = sp_array_value( $_POST, 'merge', 0 ) ? get_page_by_title( stripslashes( $name ), OBJECT, 'sp_team' ) : false;
if ( $team_object ):
if ( $team_object->post_status != 'publish' ):
wp_update_post( array( 'ID' => $team_object->ID, 'post_status' => 'publish' ) );
if ( $team_object ) :
if ( $team_object->post_status != 'publish' ) :
wp_update_post(
array(
'ID' => $team_object->ID,
'post_status' => 'publish',
)
);
endif;
$id = $team_object->ID;
else:
$args = array( 'post_type' => 'sp_team', 'post_status' => 'publish', 'post_title' => wp_strip_all_tags( $name ) );
$id = wp_insert_post( $args );
else :
$args = array(
'post_type' => 'sp_team',
'post_status' => 'publish',
'post_title' => wp_strip_all_tags( $name ),
);
$id = wp_insert_post( $args );
// Flag as import
update_post_meta( $id, '_sp_import', 1 );
@@ -107,7 +120,7 @@ if ( class_exists( 'WP_Importer' ) ) {
// Show Result
echo '<div class="updated settings-error below-h2"><p>
'.sprintf( __( 'Import complete - imported <strong>%s</strong> teams and skipped <strong>%s</strong>.', 'sportspress' ), $this->imported, $this->skipped ).'
' . sprintf( __( 'Import complete - imported <strong>%1$s</strong> teams and skipped <strong>%2$s</strong>.', 'sportspress' ), $this->imported, $this->skipped ) . '
</p></div>';
$this->import_end();
@@ -117,7 +130,7 @@ if ( class_exists( 'WP_Importer' ) ) {
* Performs post-import cleanup of files and the cache
*/
function import_end() {
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url('edit.php?post_type=sp_team') . '">' . __( 'View Teams', 'sportspress' ) . '</a>' . '</p>';
echo '<p>' . __( 'All done!', 'sportspress' ) . ' <a href="' . admin_url( 'edit.php?post_type=sp_team' ) . '">' . __( 'View Teams', 'sportspress' ) . '</a>' . '</p>';
do_action( 'import_end' );
}
@@ -130,7 +143,7 @@ if ( class_exists( 'WP_Importer' ) ) {
*/
function greet() {
echo '<div class="narrow">';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ).'</p>';
echo '<p>' . __( 'Hi there! Choose a .csv file to upload, then click "Upload file and import".', 'sportspress' ) . '</p>';
echo '<p>' . sprintf( __( 'Teams need to be defined with columns in a specific order (3 columns). <a href="%s">Click here to download a sample</a>.', 'sportspress' ), plugin_dir_url( SP_PLUGIN_FILE ) . 'dummy-data/teams-sample.csv' ) . '</p>';
wp_import_upload_form( 'admin.php?import=sp_team_csv&step=1' );
echo '</div>';

View File

@@ -2,160 +2,170 @@
/**
* Admin functions for the calendars post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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' ) ) {
require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Calendar' ) ) :
/**
* SP_Admin_CPT_Calendar Class
*/
class SP_Admin_CPT_Calendar extends SP_Admin_CPT {
/**
* Constructor
* SP_Admin_CPT_Calendar Class
*/
public function __construct() {
$this->type = 'sp_calendar';
class SP_Admin_CPT_Calendar extends SP_Admin_CPT {
// Admin Columns
add_filter( 'manage_edit-sp_calendar_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_calendar_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_calendar';
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
// Call SP_Admin_CPT constructor
parent::__construct();
}
// Admin Columns
add_filter( 'manage_edit-sp_calendar_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_calendar_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge( array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_team' => __( 'Team', 'sportspress' ),
'sp_events' => __( 'Events', 'sportspress' ),
'sp_layout' => __( 'Layout', 'sportspress' ),
), $existing_columns );
return apply_filters( 'sportspress_calendar_admin_columns', $columns );
}
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
/**
* 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' ) : __( 'All', 'sportspress' );
break;
case 'sp_season':
echo get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : __( 'All', 'sportspress' );
break;
case 'sp_venue':
echo get_the_terms ( $post_id, 'sp_venue' ) ? the_terms( $post_id, 'sp_venue' ) : __( 'All', 'sportspress' );
break;
case 'sp_team':
$teams = (array)get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
if ( empty( $teams ) ):
echo __( 'All', 'sportspress' );
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 esc_html( $team->post_title );
if ( $team_id == $current_team ):
echo '<span class="dashicons dashicons-yes" title="' . __( 'Current Team', 'sportspress' ) . '"></span>';
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge(
array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_team' => __( 'Team', 'sportspress' ),
'sp_events' => __( 'Events', 'sportspress' ),
'sp_layout' => __( 'Layout', 'sportspress' ),
),
$existing_columns
);
return apply_filters( 'sportspress_calendar_admin_columns', $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' ) : __( 'All', 'sportspress' );
break;
case 'sp_season':
echo get_the_terms( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : __( 'All', 'sportspress' );
break;
case 'sp_venue':
echo get_the_terms( $post_id, 'sp_venue' ) ? the_terms( $post_id, 'sp_venue' ) : __( 'All', 'sportspress' );
break;
case 'sp_team':
$teams = (array) get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
if ( empty( $teams ) ) :
echo __( 'All', 'sportspress' );
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 esc_html( $team->post_title );
if ( $team_id == $current_team ) :
echo '<span class="dashicons dashicons-yes" title="' . __( 'Current Team', 'sportspress' ) . '"></span>';
endif;
echo '<br>';
endif;
echo '<br>';
endif;
endforeach;
endif;
break;
case 'sp_events':
$calendar = new SP_Calendar( $post_id );
echo sizeof( $calendar->data() );
break;
case 'sp_layout':
echo esc_html( sp_array_value( SP()->formats->calendar, get_post_meta( $post_id, 'sp_format', true ), '&mdash;' ) );
break;
endswitch;
}
endforeach;
endif;
break;
case 'sp_events':
$calendar = new SP_Calendar( $post_id );
echo sizeof( $calendar->data() );
break;
case 'sp_layout':
echo esc_html( sp_array_value( SP()->formats->calendar, get_post_meta( $post_id, 'sp_format', true ), '&mdash;' ) );
break;
endswitch;
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_calendar' )
return;
if ( $typenow != 'sp_calendar' ) {
return;
}
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_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['team'] ) ? sanitize_key( $_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 );
}
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
if ( $typenow == 'sp_calendar' ) {
if ( $typenow == 'sp_calendar' ) {
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team';
}
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team';
}
}
}
}
}
endif;

View File

@@ -2,80 +2,84 @@
/**
* Admin functions for the columns post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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' ) ) {
require '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
* SP_Admin_CPT_Column Class
*/
public function __construct() {
$this->type = 'sp_column';
class SP_Admin_CPT_Column extends SP_Admin_CPT {
// 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();
}
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_column';
/**
* 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' => __( 'Decimal Places', 'sportspress' ),
'sp_order' => __( 'Sort Order', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_column_admin_columns', $columns );
}
// 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 );
/**
* 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_equation':
echo wp_kses_post( sp_get_post_equation( $post_id ) );
break;
case 'sp_precision':
echo esc_html( sp_get_post_precision( $post_id ) );
break;
case 'sp_order':
echo esc_html( sp_get_post_order( $post_id ) );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
// 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' => __( 'Decimal Places', 'sportspress' ),
'sp_order' => __( 'Sort Order', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_column_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_equation':
echo wp_kses_post( sp_get_post_equation( $post_id ) );
break;
case 'sp_precision':
echo esc_html( sp_get_post_precision( $post_id ) );
break;
case 'sp_order':
echo esc_html( sp_get_post_order( $post_id ) );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
}
}
}
endif;

View File

@@ -2,217 +2,235 @@
/**
* Admin functions for the events post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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' ) ) {
require '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
* SP_Admin_CPT_Event Class
*/
public function __construct() {
$this->type = 'sp_event';
class SP_Admin_CPT_Event extends SP_Admin_CPT {
// Post title fields
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_event';
// Empty data filter
add_filter( 'wp_insert_post_empty_content', array( $this, 'wp_insert_post_empty_content' ), 99, 2 );
// 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 );
// Empty data filter
add_filter( 'wp_insert_post_empty_content', array( $this, 'wp_insert_post_empty_content' ), 99, 2 );
// Admin Columns
add_filter( 'manage_edit-sp_event_columns', array( $this, 'edit_columns' ) );
add_filter( 'manage_edit-sp_event_sortable_columns', array( $this, 'sortable_columns' ) );
add_action( 'pre_get_posts', array( $this, 'orderby_columns' ) );
add_action( 'manage_sp_event_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Before data updates
add_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ), 99, 2 );
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
// Admin Columns
add_filter( 'manage_edit-sp_event_columns', array( $this, 'edit_columns' ) );
add_filter( 'manage_edit-sp_event_sortable_columns', array( $this, 'sortable_columns' ) );
add_action( 'pre_get_posts', array( $this, 'orderby_columns' ) );
add_action( 'manage_sp_event_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Post states
add_filter( 'display_post_states', array( $this, 'post_states' ), 10, 2 );
// Call SP_Admin_CPT constructor
parent::__construct();
}
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
/**
* 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' );
// Post states
add_filter( 'display_post_states', array( $this, 'post_states' ), 10, 2 );
return $text;
}
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Mark as not empty when saving event if teams are selected for auto title.
*
* @param array $maybe_empty
* @param array $postarr
* @return bool
*/
public function wp_insert_post_empty_content( $maybe_empty, $postarr ) {
if ( $maybe_empty && 'sp_event' === sp_array_value( $postarr, 'post_type' ) ):
$teams = sp_array_value( $postarr, 'sp_team', array() );
$teams = array_filter( $teams );
if ( sizeof( $teams ) ) return false;
endif;
return $maybe_empty;
}
/**
* Auto-generate an event title based on the team playing if left blank.
*
* @param array $data
* @param array $postarr
* @return array
*/
public function wp_insert_post_data( $data, $postarr ) {
if ( $data['post_type'] == 'sp_event' && $data['post_title'] == '' ):
$teams = sp_array_value( $postarr, 'sp_team', array() );
$teams = array_filter( $teams );
$team_names = array();
foreach ( $teams as $team ):
while ( is_array( $team ) ) {
$team = array_shift( array_filter( $team ) );
}
if ( $team > 0 ) $team_names[] = sp_team_short_name( $team );
endforeach;
$team_names = array_unique( $team_names );
$reverse_teams = get_option( 'sportspress_event_reverse_teams', 'no' ) === 'yes' ? true : false;
if ( $reverse_teams ) {
$team_names = array_reverse( $team_names );
/**
* 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' );
}
$data['post_title'] = implode( ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ', $team_names );
endif;
return $data;
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['comments'] );
$columns = array_merge( array(
'cb' => '<input type="checkbox" />',
'sp_format' => '<span class="dashicons sp-icon-calendar sp-tip" title="' . __( 'Format', 'sportspress' ) . '"></span>',
'title' => null,
'date' => __( 'Date', 'sportspress' ),
'sp_time' => __( 'Time', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_day' => __( 'Match Day', 'sportspress' ),
), $existing_columns, array(
'title' => __( 'Event', 'sportspress' ),
) );
return apply_filters( 'sportspress_event_admin_columns', $columns );
}
/**
* Change the sortable columns in admin.
*/
public function sortable_columns( $columns ) {
$columns['sp_day'] = 'sp_day';
return $columns;
}
/**
* Define the sortable columns in admin.
*/
public function orderby_columns( $query ) {
if ( ! is_admin() ) return;
$orderby = $query->get( 'orderby');
if ( 'sp_day' == $orderby ) {
$query->set( 'meta_key','sp_day' );
$query->set( 'orderby','meta_value_num' );
return $text;
}
}
/**
* 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 );
$formats = new SP_Formats();
$event_formats = $formats->event;
if ( array_key_exists( $format, $event_formats ) ):
echo '<span class="dashicons sp-icon-' . $format . ' sp-tip" title="' . $event_formats[ $format ] . '"></span>';
endif;
break;
case 'sp_time':
echo apply_filters( 'sportspress_event_time_admin', get_post_time( 'H:i', false, $post_id, true ) );
break;
case 'sp_team':
$teams = (array)get_post_meta( $post_id, 'sp_team', false );
/**
* Mark as not empty when saving event if teams are selected for auto title.
*
* @param array $maybe_empty
* @param array $postarr
* @return bool
*/
public function wp_insert_post_empty_content( $maybe_empty, $postarr ) {
if ( $maybe_empty && 'sp_event' === sp_array_value( $postarr, 'post_type' ) ) :
$teams = sp_array_value( $postarr, 'sp_team', array() );
$teams = array_filter( $teams );
$teams = array_unique( $teams );
if ( sizeof( $teams ) ) {
return false;
}
endif;
return $maybe_empty;
}
/**
* Auto-generate an event title based on the team playing if left blank.
*
* @param array $data
* @param array $postarr
* @return array
*/
public function wp_insert_post_data( $data, $postarr ) {
if ( $data['post_type'] == 'sp_event' && $data['post_title'] == '' ) :
$teams = sp_array_value( $postarr, 'sp_team', array() );
$teams = array_filter( $teams );
$team_names = array();
foreach ( $teams as $team ) :
while ( is_array( $team ) ) {
$team = array_shift( array_filter( $team ) );
}
if ( $team > 0 ) {
$team_names[] = sp_team_short_name( $team );
}
endforeach;
$team_names = array_unique( $team_names );
$reverse_teams = get_option( 'sportspress_event_reverse_teams', 'no' ) === 'yes' ? true : false;
if ( $reverse_teams ) {
$teams = array_reverse( $teams , true );
$team_names = array_reverse( $team_names );
}
if ( empty( $teams ) ):
echo '&mdash;';
else:
$results = get_post_meta( $post_id, 'sp_results', true );
$main_result = get_option( 'sportspress_primary_result', null );
echo '<input type="hidden" name="sp_post_id" value="' . $post_id . '">';
echo '<div class="sp-results">';
foreach( $teams as $team_id ):
if ( ! $team_id ) continue;
$data['post_title'] = implode( ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ', $team_names );
endif;
return $data;
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['comments'] );
$columns = array_merge(
array(
'cb' => '<input type="checkbox" />',
'sp_format' => '<span class="dashicons sp-icon-calendar sp-tip" title="' . __( 'Format', 'sportspress' ) . '"></span>',
'title' => null,
'date' => __( 'Date', 'sportspress' ),
'sp_time' => __( 'Time', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_day' => __( 'Match Day', 'sportspress' ),
),
$existing_columns,
array(
'title' => __( 'Event', 'sportspress' ),
)
);
return apply_filters( 'sportspress_event_admin_columns', $columns );
}
/**
* Change the sortable columns in admin.
*/
public function sortable_columns( $columns ) {
$columns['sp_day'] = 'sp_day';
return $columns;
}
/**
* Define the sortable columns in admin.
*/
public function orderby_columns( $query ) {
if ( ! is_admin() ) {
return;
}
$orderby = $query->get( 'orderby' );
if ( 'sp_day' == $orderby ) {
$query->set( 'meta_key', 'sp_day' );
$query->set( 'orderby', 'meta_value_num' );
}
}
/**
* 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 );
$formats = new SP_Formats();
$event_formats = $formats->event;
if ( array_key_exists( $format, $event_formats ) ) :
echo '<span class="dashicons sp-icon-' . $format . ' sp-tip" title="' . $event_formats[ $format ] . '"></span>';
endif;
break;
case 'sp_time':
echo apply_filters( 'sportspress_event_time_admin', get_post_time( 'H:i', false, $post_id, true ) );
break;
case 'sp_team':
$teams = (array) get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
$teams = array_unique( $teams );
$reverse_teams = get_option( 'sportspress_event_reverse_teams', 'no' ) === 'yes' ? true : false;
if ( $reverse_teams ) {
$teams = array_reverse( $teams, true );
}
if ( empty( $teams ) ) :
echo '&mdash;';
else :
$results = get_post_meta( $post_id, 'sp_results', true );
$main_result = get_option( 'sportspress_primary_result', null );
echo '<input type="hidden" name="sp_post_id" value="' . $post_id . '">';
echo '<div class="sp-results">';
foreach ( $teams as $team_id ) :
if ( ! $team_id ) {
continue;
}
$team = get_post( $team_id );
if ( $team ):
if ( $team ) :
$team_results = sportspress_array_value( $results, $team_id, null );
if ( $main_result ):
if ( $main_result ) :
$team_result = sportspress_array_value( $team_results, $main_result, null );
else:
if ( is_array( $team_results ) ):
else :
if ( is_array( $team_results ) ) :
end( $team_results );
$team_result = prev( $team_results );
$main_result = key( $team_results );
else:
else :
$team_result = null;
endif;
endif;
if ( is_array( $team_results ) ):
if ( is_array( $team_results ) ) :
unset( $team_results['outcome'] );
$team_results = array_filter( $team_results, 'sp_filter_non_empty' );
$team_results = implode( ' | ', $team_results );
@@ -223,129 +241,134 @@ class SP_Admin_CPT_Event extends SP_Admin_CPT {
echo esc_html( $team->post_title );
echo '<br>';
endif;
endforeach;
echo '</div>';
if ( current_user_can( 'edit_others_sp_events' ) ) {
?>
endforeach;
echo '</div>';
if ( current_user_can( 'edit_others_sp_events' ) ) {
?>
<div class="row-actions sp-row-actions"><span class="inline hide-if-no-js"><a href="#" class="sp-edit-results"><?php _e( 'Edit Results', 'sportspress' ); ?></a></span></div>
<p class="inline-edit-save sp-inline-edit-save hidden">
<a href="#inline-edit" class="button-secondary cancel alignleft"><?php _e( 'Cancel' ); ?></a>
<a href="#inline-edit" class="button-primary save alignright"><?php _e( 'Update' ); ?></a>
</p>
<?php
<?php
}
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_day':
$day = get_post_meta( $post_id, 'sp_day', true );
if ( '' === $day ) {
$day = __( 'Default', 'sportspress' );
}
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_day':
$day = get_post_meta ( $post_id, 'sp_day', true );
if ( '' === $day ) $day = __( 'Default', 'sportspress' );
echo esc_html( $day );
break;
endswitch;
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_event' )
return;
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_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'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['match_day'] ) ? sanitize_text_field( $_REQUEST['match_day'] ) : null;
echo '<input name="match_day" type="text" class="sp-tablenav-input" placeholder="' . __( 'Match Day', 'sportspress' ) . '" value="' . $selected . '">';
if ( current_user_can( 'edit_others_sp_events' ) )
wp_nonce_field( 'sp-save-inline-results', 'sp-inline-nonce', false );
}
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
if ( $typenow == 'sp_event' ) {
//Avoid overriding relation operator if already set
if ( !isset( $query->query_vars['meta_query']['relation'] ) )
$query->query_vars['meta_query']['relation'] = 'AND';
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_query'][] = array(
'key' => 'sp_team',
'value' => $_GET['team'],
);
echo esc_html( $day );
break;
endswitch;
}
if ( ! empty( $_GET['match_day'] ) ) {
$query->query_vars['meta_query'][] = array(
'key' => 'sp_day',
'value' => $_GET['match_day'],
);
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_event' ) {
return;
}
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_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'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['match_day'] ) ? sanitize_text_field( $_REQUEST['match_day'] ) : null;
echo '<input name="match_day" type="text" class="sp-tablenav-input" placeholder="' . __( 'Match Day', 'sportspress' ) . '" value="' . $selected . '">';
if ( current_user_can( 'edit_others_sp_events' ) ) {
wp_nonce_field( 'sp-save-inline-results', 'sp-inline-nonce', false );
}
}
}
}
/**
* Replace displayed post state for events
*
* @param array $post_states
* @param object $post
*/
public function post_states( $post_states, $post ) {
$status = get_post_meta( $post->ID, 'sp_status', true );
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
if ( 'postponed' == $status ) {
$post_states = array( __( 'Postponed', 'sportspress' ) );
} elseif ( 'cancelled' == $status ) {
$post_states = array( __( 'Canceled', 'sportspress' ) );
} elseif ( 'tbd' == $status ) {
$post_states = array( __( 'TBD', 'sportspress' ) );
}
if ( $typenow == 'sp_event' ) {
// Avoid overriding relation operator if already set
if ( ! isset( $query->query_vars['meta_query']['relation'] ) ) {
$query->query_vars['meta_query']['relation'] = 'AND';
}
return $post_states;
}
}
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_query'][] = array(
'key' => 'sp_team',
'value' => $_GET['team'],
);
}
if ( ! empty( $_GET['match_day'] ) ) {
$query->query_vars['meta_query'][] = array(
'key' => 'sp_day',
'value' => $_GET['match_day'],
);
}
}
}
/**
* Replace displayed post state for events
*
* @param array $post_states
* @param object $post
*/
public function post_states( $post_states, $post ) {
$status = get_post_meta( $post->ID, 'sp_status', true );
if ( 'postponed' == $status ) {
$post_states = array( __( 'Postponed', 'sportspress' ) );
} elseif ( 'cancelled' == $status ) {
$post_states = array( __( 'Canceled', 'sportspress' ) );
} elseif ( 'tbd' == $status ) {
$post_states = array( __( 'TBD', 'sportspress' ) );
}
return $post_states;
}
}
endif;

View File

@@ -2,154 +2,166 @@
/**
* Admin functions for the player lists post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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' ) ) {
require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_List' ) ) :
/**
* SP_Admin_CPT_List Class
*/
class SP_Admin_CPT_List extends SP_Admin_CPT {
/**
* Constructor
* SP_Admin_CPT_List Class
*/
public function __construct() {
$this->type = 'sp_list';
class SP_Admin_CPT_List extends SP_Admin_CPT {
// Admin Columns
add_filter( 'manage_edit-sp_list_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_list_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_list';
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
// Call SP_Admin_CPT constructor
parent::__construct();
}
// Admin Columns
add_filter( 'manage_edit-sp_list_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_list_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge( array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_team' => __( 'Team', 'sportspress' ),
'sp_player' => __( 'Players', 'sportspress' ),
'sp_layout' => __( 'Layout', 'sportspress' ),
), $existing_columns );
return apply_filters( 'sportspress_list_admin_columns', $columns );
}
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_player':
$select = get_post_meta( $post_id, 'sp_select', true );
if ( 'manual' == $select ):
$players = array_filter( get_post_meta( $post_id, 'sp_player' ) );
echo sizeof( $players );
else:
_e( 'Auto', 'sportspress' );
endif;
break;
case 'sp_league':
echo get_the_terms ( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : __( 'All', 'sportspress' );
break;
case 'sp_season':
echo get_the_terms ( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : __( 'All', 'sportspress' );
break;
case 'sp_team':
$teams = (array)get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
if ( empty( $teams ) ):
echo __( 'All', 'sportspress' );
else:
foreach( $teams as $team_id ):
if ( ! $team_id ) continue;
$team = get_post( $team_id );
if ( $team ) echo esc_html( $team->post_title ) . '<br>';
endforeach;
endif;
break;
case 'sp_layout':
echo esc_html( sp_array_value( SP()->formats->list, get_post_meta( $post_id, 'sp_format', true ), '&mdash;' ) );
break;
endswitch;
}
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge(
array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_team' => __( 'Team', 'sportspress' ),
'sp_player' => __( 'Players', 'sportspress' ),
'sp_layout' => __( 'Layout', 'sportspress' ),
),
$existing_columns
);
return apply_filters( 'sportspress_list_admin_columns', $columns );
}
if ( $typenow != 'sp_list' )
return;
/**
* Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_player':
$select = get_post_meta( $post_id, 'sp_select', true );
if ( 'manual' == $select ) :
$players = array_filter( get_post_meta( $post_id, 'sp_player' ) );
echo sizeof( $players );
else :
_e( 'Auto', 'sportspress' );
endif;
break;
case 'sp_league':
echo get_the_terms( $post_id, 'sp_league' ) ? the_terms( $post_id, 'sp_league' ) : __( 'All', 'sportspress' );
break;
case 'sp_season':
echo get_the_terms( $post_id, 'sp_season' ) ? the_terms( $post_id, 'sp_season' ) : __( 'All', 'sportspress' );
break;
case 'sp_team':
$teams = (array) get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
if ( empty( $teams ) ) :
echo __( 'All', 'sportspress' );
else :
foreach ( $teams as $team_id ) :
if ( ! $team_id ) {
continue;
}
$team = get_post( $team_id );
if ( $team ) {
echo esc_html( $team->post_title ) . '<br>';
}
endforeach;
endif;
break;
case 'sp_layout':
echo esc_html( sp_array_value( SP()->formats->list, get_post_meta( $post_id, 'sp_format', true ), '&mdash;' ) );
break;
endswitch;
}
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
if ( $typenow != 'sp_list' ) {
return;
}
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_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'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
if ( $typenow == 'sp_list' ) {
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_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 );
}
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team';
}
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
if ( $typenow == 'sp_list' ) {
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team';
}
}
}
}
}
endif;

View File

@@ -2,68 +2,72 @@
/**
* Admin functions for the columns post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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' ) ) {
require '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
* SP_Admin_CPT_Metric Class
*/
public function __construct() {
$this->type = 'sp_metric';
class SP_Admin_CPT_Metric extends SP_Admin_CPT {
// 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();
}
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_metric';
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Variable', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_metric_admin_columns', $columns );
}
// 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 );
/**
* 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;
// 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' => __( 'Variable', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_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;

View File

@@ -2,51 +2,56 @@
/**
* Admin functions for the officials post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.5.1
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.5.1
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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' ) ) {
require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Official' ) ) :
/**
* SP_Admin_CPT_Official Class
*/
class SP_Admin_CPT_Official extends SP_Admin_CPT {
/**
* Constructor
* SP_Admin_CPT_Official Class
*/
public function __construct() {
$this->type = 'sp_official';
class SP_Admin_CPT_Official extends SP_Admin_CPT {
// Post title fields
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_official';
// Call SP_Admin_CPT constructor
parent::__construct();
// Post title fields
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* 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_official' ) {
return __( 'Name', 'sportspress' );
}
return $text;
}
}
/**
* 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_official' )
return __( 'Name', 'sportspress' );
return $text;
}
}
endif;
return new SP_Admin_CPT_Official();

View File

@@ -2,73 +2,77 @@
/**
* Admin functions for the outcomes post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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' ) ) {
require '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
* SP_Admin_CPT_Outcome Class
*/
public function __construct() {
$this->type = 'sp_outcome';
class SP_Admin_CPT_Outcome extends SP_Admin_CPT {
// 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();
}
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_outcome';
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Variable', 'sportspress' ),
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_outcome_admin_columns', $columns );
}
// 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 );
/**
* 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_abbreviation':
global $post;
echo esc_html( sp_get_post_abbreviation( $post->ID ) );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
// 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' => __( 'Variable', 'sportspress' ),
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_outcome_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_abbreviation':
global $post;
echo esc_html( sp_get_post_abbreviation( $post->ID ) );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
}
}
}
endif;

View File

@@ -2,82 +2,86 @@
/**
* Admin functions for the performance post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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' ) ) {
require '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
* SP_Admin_CPT_Performance Class
*/
public function __construct() {
$this->type = 'sp_performance';
class SP_Admin_CPT_Performance extends SP_Admin_CPT {
// 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();
}
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_performance';
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'sp_icon' => __( 'Icon', 'sportspress' ),
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Variable', 'sportspress' ),
'sp_section' => __( 'Category', 'sportspress' ),
'sp_config_format' => __( 'Format', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_performance_admin_columns', $columns );
}
// 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 );
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_icon':
echo has_post_thumbnail( $post_id ) ? edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-fit-mini' ), '', '', $post_id ) : '';
break;
case 'sp_key':
global $post;
echo esc_html( $post->post_name );
break;
case 'sp_section':
global $post;
echo esc_html( sp_get_post_section( $post->ID ) );
break;
case 'sp_config_format':
global $post;
echo esc_html( sp_get_post_format( $post->ID ) );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
// 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" />',
'sp_icon' => __( 'Icon', 'sportspress' ),
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Variable', 'sportspress' ),
'sp_section' => __( 'Category', 'sportspress' ),
'sp_config_format' => __( 'Format', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_performance_admin_columns', $columns );
}
/**
* Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_icon':
echo has_post_thumbnail( $post_id ) ? edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-fit-mini' ), '', '', $post_id ) : '';
break;
case 'sp_key':
global $post;
echo esc_html( $post->post_name );
break;
case 'sp_section':
global $post;
echo esc_html( sp_get_post_section( $post->ID ) );
break;
case 'sp_config_format':
global $post;
echo esc_html( sp_get_post_format( $post->ID ) );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
}
}
}
endif;

View File

@@ -2,226 +2,245 @@
/**
* Admin functions for the players post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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' ) ) {
require '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
* SP_Admin_CPT_Player Class
*/
public function __construct() {
$this->type = 'sp_player';
class SP_Admin_CPT_Player extends SP_Admin_CPT {
// Post title fields
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_player';
// 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 );
// Post title fields
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
// 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 );
// Quick edit
add_action( 'quick_edit_custom_box', array( $this, 'quick_edit_number' ), 10, 2 );
add_action( 'quick_edit_custom_box', array( $this, 'quick_edit_teams' ), 10, 2 );
add_action( 'save_post', array( $this, 'quick_save' ) );
// Bulk edit
add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit_teams' ), 10, 2 );
add_action( 'wp_ajax_save_bulk_edit_sp_player', array( $this, 'bulk_save' ) );
// Call SP_Admin_CPT constructor
parent::__construct();
}
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
/**
* 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' );
// Quick edit
add_action( 'quick_edit_custom_box', array( $this, 'quick_edit_number' ), 10, 2 );
add_action( 'quick_edit_custom_box', array( $this, 'quick_edit_teams' ), 10, 2 );
add_action( 'save_post', array( $this, 'quick_save' ) );
return $text;
}
// Bulk edit
add_action( 'bulk_edit_custom_box', array( $this, 'bulk_edit_teams' ), 10, 2 );
add_action( 'wp_ajax_save_bulk_edit_sp_player', array( $this, 'bulk_save' ) );
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge( array(
'cb' => '<input type="checkbox" />',
'sp_number' => '<span class="dashicons sp-icon-tshirt sp-tip" title="' . __( 'Squad Number', 'sportspress' ) . '"></span>',
'title' => null,
'sp_position' => __( 'Positions', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
), $existing_columns, array(
'title' => __( 'Name', 'sportspress' )
) );
return apply_filters( 'sportspress_player_admin_columns', $columns );
}
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_number':
echo esc_html( get_post_meta ( $post_id, 'sp_number', true ) );
break;
case 'sp_position':
echo get_the_terms( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : '&mdash;';
break;
case 'sp_team':
$current_teams = get_post_meta( $post_id, 'sp_current_team', false );
$past_teams = get_post_meta( $post_id, 'sp_past_team', false );
$current_teams = array_filter( $current_teams );
$past_teams = array_filter( $past_teams );
echo '<span class="hidden sp-player-teams" data-current-teams="' . implode( ',', $current_teams ) . '" data-past-teams="' . implode( ',', $past_teams ) . '"></span>';
$teams = (array)get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
$teams = array_unique( $teams );
if ( empty( $teams ) ):
echo '&mdash;';
else:
foreach( $teams as $team_id ):
if ( ! $team_id ) continue;
$team = get_post( $team_id );
if ( $team ):
echo esc_html( $team->post_title );
if ( in_array( $team_id, $current_teams ) ):
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;
endswitch;
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_player' )
return;
if ( taxonomy_exists( 'sp_position' ) ):
$selected = isset( $_REQUEST['sp_position'] ) ? sanitize_key( $_REQUEST['sp_position'] ) : null;
$args = array(
'show_option_all' => __( 'Show all positions', 'sportspress' ),
'taxonomy' => 'sp_position',
'name' => 'sp_position',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
endif;
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_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 );
if ( taxonomy_exists( 'sp_league' ) ):
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
endif;
if ( taxonomy_exists( 'sp_season' ) ):
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
endif;
}
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
if ( empty ( $query->query_vars['post_type'] ) || $query->query_vars['post_type'] !== 'sp_player' ) return $query;
global $typenow, $wp_query;
if ( $typenow == 'sp_player' ) {
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team';
/**
* 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;
}
return $query;
}
/**
* Quick edit squad number
*
* @param string $column_name
* @param string $post_type
*/
public function quick_edit_number( $column_name, $post_type ) {
if ( $this->type !== $post_type ) return;
if ( 'sp_number' !== $column_name ) return;
static $print_nonce = true;
if ( $print_nonce ) {
$print_nonce = false;
wp_nonce_field( plugin_basename( __FILE__ ), 'sp_player_edit_nonce' );
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge(
array(
'cb' => '<input type="checkbox" />',
'sp_number' => '<span class="dashicons sp-icon-tshirt sp-tip" title="' . __( 'Squad Number', 'sportspress' ) . '"></span>',
'title' => null,
'sp_position' => __( 'Positions', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
),
$existing_columns,
array(
'title' => __( 'Name', 'sportspress' ),
)
);
return apply_filters( 'sportspress_player_admin_columns', $columns );
}
?>
/**
* Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_number':
echo esc_html( get_post_meta( $post_id, 'sp_number', true ) );
break;
case 'sp_position':
echo get_the_terms( $post_id, 'sp_position' ) ? the_terms( $post_id, 'sp_position' ) : '&mdash;';
break;
case 'sp_team':
$current_teams = get_post_meta( $post_id, 'sp_current_team', false );
$past_teams = get_post_meta( $post_id, 'sp_past_team', false );
$current_teams = array_filter( $current_teams );
$past_teams = array_filter( $past_teams );
echo '<span class="hidden sp-player-teams" data-current-teams="' . implode( ',', $current_teams ) . '" data-past-teams="' . implode( ',', $past_teams ) . '"></span>';
$teams = (array) get_post_meta( $post_id, 'sp_team', false );
$teams = array_filter( $teams );
$teams = array_unique( $teams );
if ( empty( $teams ) ) :
echo '&mdash;';
else :
foreach ( $teams as $team_id ) :
if ( ! $team_id ) {
continue;
}
$team = get_post( $team_id );
if ( $team ) :
echo esc_html( $team->post_title );
if ( in_array( $team_id, $current_teams ) ) :
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;
endswitch;
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_player' ) {
return;
}
if ( taxonomy_exists( 'sp_position' ) ) :
$selected = isset( $_REQUEST['sp_position'] ) ? sanitize_key( $_REQUEST['sp_position'] ) : null;
$args = array(
'show_option_all' => __( 'Show all positions', 'sportspress' ),
'taxonomy' => 'sp_position',
'name' => 'sp_position',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
endif;
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_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 );
if ( taxonomy_exists( 'sp_league' ) ) :
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
endif;
if ( taxonomy_exists( 'sp_season' ) ) :
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
endif;
}
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
if ( empty( $query->query_vars['post_type'] ) || $query->query_vars['post_type'] !== 'sp_player' ) {
return $query;
}
global $typenow, $wp_query;
if ( $typenow == 'sp_player' ) {
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team';
}
}
return $query;
}
/**
* Quick edit squad number
*
* @param string $column_name
* @param string $post_type
*/
public function quick_edit_number( $column_name, $post_type ) {
if ( $this->type !== $post_type ) {
return;
}
if ( 'sp_number' !== $column_name ) {
return;
}
static $print_nonce = true;
if ( $print_nonce ) {
$print_nonce = false;
wp_nonce_field( plugin_basename( __FILE__ ), 'sp_player_edit_nonce' );
}
?>
<fieldset class="inline-edit-col-right">
<div class="inline-edit-col">
<label>
@@ -230,27 +249,35 @@ class SP_Admin_CPT_Player extends SP_Admin_CPT {
</label>
</div>
</fieldset>
<?php
}
<?php
}
/**
* Quick edit teams
*
* @param string $column_name
* @param string $post_type
*/
public function quick_edit_teams( $column_name, $post_type ) {
if ( $this->type !== $post_type ) return;
if ( 'sp_team' !== $column_name ) return;
/**
* Quick edit teams
*
* @param string $column_name
* @param string $post_type
*/
public function quick_edit_teams( $column_name, $post_type ) {
if ( $this->type !== $post_type ) {
return;
}
if ( 'sp_team' !== $column_name ) {
return;
}
$teams = get_posts( array(
'post_type' => 'sp_team',
'numberposts' => -1,
'post_status' => 'publish',
) );
if ( ! $teams ) return;
?>
$teams = get_posts(
array(
'post_type' => 'sp_team',
'numberposts' => -1,
'post_status' => 'publish',
)
);
if ( ! $teams ) {
return;
}
?>
<fieldset class="inline-edit-col-right">
<div class="inline-edit-col">
<span class="title inline-edit-categories-label"><?php _e( 'Current Teams', 'sportspress' ); ?></span>
@@ -269,57 +296,75 @@ class SP_Admin_CPT_Player extends SP_Admin_CPT {
</ul>
</div>
</fieldset>
<?php
}
/**
* Save quick edit boxes
*
* @param int $post_id
*/
public function quick_save( $post_id ) {
if ( empty( $_POST ) ) return $post_id;
if ( ! current_user_can( 'edit_post', $post_id ) ) return $post_id;;
$_POST += array( "{$this->type}_edit_nonce" => '' );
if ( ! wp_verify_nonce( $_POST["{$this->type}_edit_nonce"], plugin_basename( __FILE__ ) ) ) return $post_id;;
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id;
if ( isset( $post->post_type ) && $post->post_type == 'revision' ) return $post_id;
if ( isset( $_POST[ 'sp_number' ] ) ) {
update_post_meta( $post_id, 'sp_number', $_POST[ 'sp_number' ] );
<?php
}
sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
}
/**
* Save quick edit boxes
*
* @param int $post_id
*/
public function quick_save( $post_id ) {
if ( empty( $_POST ) ) {
return $post_id;
}
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
/**
* Bulk edit teams
*
* @param string $column_name
* @param string $post_type
*/
public function bulk_edit_teams( $column_name, $post_type ) {
if ( $this->type !== $post_type ) return;
if ( 'sp_team' !== $column_name ) return;
$_POST += array( "{$this->type}_edit_nonce" => '' );
if ( ! wp_verify_nonce( $_POST[ "{$this->type}_edit_nonce" ], plugin_basename( __FILE__ ) ) ) {
return $post_id;
}
static $print_nonce = true;
if ( $print_nonce ) {
$print_nonce = false;
wp_nonce_field( plugin_basename( __FILE__ ), 'sp_player_edit_nonce' );
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
if ( isset( $post->post_type ) && $post->post_type == 'revision' ) {
return $post_id;
}
if ( isset( $_POST['sp_number'] ) ) {
update_post_meta( $post_id, 'sp_number', $_POST['sp_number'] );
}
sp_update_post_meta_recursive( $post_id, 'sp_current_team', sp_array_value( $_POST, 'sp_current_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
}
$teams = get_posts( array(
'post_type' => 'sp_team',
'numberposts' => -1,
'post_status' => 'publish',
) );
if ( ! $teams ) return;
?>
/**
* Bulk edit teams
*
* @param string $column_name
* @param string $post_type
*/
public function bulk_edit_teams( $column_name, $post_type ) {
if ( $this->type !== $post_type ) {
return;
}
if ( 'sp_team' !== $column_name ) {
return;
}
static $print_nonce = true;
if ( $print_nonce ) {
$print_nonce = false;
wp_nonce_field( plugin_basename( __FILE__ ), 'sp_player_edit_nonce' );
}
$teams = get_posts(
array(
'post_type' => 'sp_team',
'numberposts' => -1,
'post_status' => 'publish',
)
);
if ( ! $teams ) {
return;
}
?>
<fieldset class="inline-edit-col-right">
<div class="inline-edit-col">
<span class="title inline-edit-categories-label"><?php _e( 'Current Teams', 'sportspress' ); ?></span>
@@ -338,35 +383,39 @@ class SP_Admin_CPT_Player extends SP_Admin_CPT {
</ul>
</div>
</fieldset>
<?php
}
/**
* Save bulk edit boxes
*/
public function bulk_save() {
$_POST += array( "nonce" => '' );
if ( ! wp_verify_nonce( $_POST["nonce"], plugin_basename( __FILE__ ) ) ) return;
$post_ids = ( ! empty( $_POST[ 'post_ids' ] ) ) ? $_POST[ 'post_ids' ] : array();
$current_teams = sp_array_value( $_POST, 'current_teams', array() );
$past_teams = sp_array_value( $_POST, 'past_teams', array() );
$teams = array_merge( $current_teams, $past_teams );
if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
foreach ( $post_ids as $post_id ) {
if ( ! current_user_can( 'edit_post', $post_id ) ) continue;
sp_add_post_meta_recursive( $post_id, 'sp_current_team', $current_teams );
sp_add_post_meta_recursive( $post_id, 'sp_past_team', $past_teams );
sp_add_post_meta_recursive( $post_id, 'sp_team', $teams );
}
<?php
}
die();
/**
* Save bulk edit boxes
*/
public function bulk_save() {
$_POST += array( 'nonce' => '' );
if ( ! wp_verify_nonce( $_POST['nonce'], plugin_basename( __FILE__ ) ) ) {
return;
}
$post_ids = ( ! empty( $_POST['post_ids'] ) ) ? $_POST['post_ids'] : array();
$current_teams = sp_array_value( $_POST, 'current_teams', array() );
$past_teams = sp_array_value( $_POST, 'past_teams', array() );
$teams = array_merge( $current_teams, $past_teams );
if ( ! empty( $post_ids ) && is_array( $post_ids ) ) {
foreach ( $post_ids as $post_id ) {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
continue;
}
sp_add_post_meta_recursive( $post_id, 'sp_current_team', $current_teams );
sp_add_post_meta_recursive( $post_id, 'sp_past_team', $past_teams );
sp_add_post_meta_recursive( $post_id, 'sp_team', $teams );
}
}
die();
}
}
}
endif;

View File

@@ -2,68 +2,72 @@
/**
* Admin functions for the results post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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' ) ) {
require '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
* SP_Admin_CPT_Result Class
*/
public function __construct() {
$this->type = 'sp_result';
class SP_Admin_CPT_Result extends SP_Admin_CPT {
// 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();
}
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_result';
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Variable', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_result_admin_columns', $columns );
}
// 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 );
/**
* 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 ) . 'for, ' . esc_html( $post->post_name ) . 'against';
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
// 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' => __( 'Variable', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_result_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 ) . 'for, ' . esc_html( $post->post_name ) . 'against';
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
}
}
}
endif;

View File

@@ -2,68 +2,72 @@
/**
* Admin functions for the columns post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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' ) ) {
require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Spec' ) ) :
/**
* SP_Admin_CPT_Spec Class
*/
class SP_Admin_CPT_Spec extends SP_Admin_CPT {
/**
* Constructor
* SP_Admin_CPT_Spec Class
*/
public function __construct() {
$this->type = 'sp_spec';
class SP_Admin_CPT_Spec extends SP_Admin_CPT {
// Admin Columns
add_filter( 'manage_edit-sp_spec_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_spec_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_spec';
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Variable', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_spec_admin_columns', $columns );
}
// Admin Columns
add_filter( 'manage_edit-sp_spec_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_spec_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
/**
* 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;
// 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' => __( 'Variable', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_spec_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;

View File

@@ -2,169 +2,182 @@
/**
* Admin functions for the staff post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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' ) ) {
require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Staff' ) ) :
/**
* SP_Admin_CPT_Staff Class
*/
class SP_Admin_CPT_Staff extends SP_Admin_CPT {
/**
* Constructor
* SP_Admin_CPT_Staff Class
*/
public function __construct() {
$this->type = 'sp_staff';
class SP_Admin_CPT_Staff extends SP_Admin_CPT {
// Post title fields
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_staff';
// Admin Columns
add_filter( 'manage_edit-sp_staff_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_staff_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Post title fields
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
// Call SP_Admin_CPT constructor
parent::__construct();
}
// Admin Columns
add_filter( 'manage_edit-sp_staff_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_staff_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
/**
* 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_staff' )
return __( 'Name', 'sportspress' );
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
return $text;
}
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge( array(
'cb' => '<input type="checkbox" />',
'title' => null,
'sp_role' => __( 'Job', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
), $existing_columns, array(
'title' => __( 'Name', 'sportspress' )
) );
return apply_filters( 'sportspress_staff_admin_columns', $columns );
}
/**
* 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_staff' ) {
return __( 'Name', 'sportspress' );
}
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_role':
echo get_the_terms( $post_id, 'sp_role' ) ? the_terms( $post_id, 'sp_role' ) : '&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:
$current_teams = get_post_meta( $post_id, 'sp_current_team', false );
foreach( $teams as $team_id ):
if ( ! $team_id ) continue;
$team = get_post( $team_id );
if ( $team ):
echo esc_html( $team->post_title );
if ( in_array( $team_id, $current_teams ) ):
echo '<span class="dashicons dashicons-yes" title="' . __( 'Current Team', 'sportspress' ) . '"></span>';
return $text;
}
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge(
array(
'cb' => '<input type="checkbox" />',
'title' => null,
'sp_role' => __( 'Job', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
),
$existing_columns,
array(
'title' => __( 'Name', 'sportspress' ),
)
);
return apply_filters( 'sportspress_staff_admin_columns', $columns );
}
/**
* Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_role':
echo get_the_terms( $post_id, 'sp_role' ) ? the_terms( $post_id, 'sp_role' ) : '&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 :
$current_teams = get_post_meta( $post_id, 'sp_current_team', false );
foreach ( $teams as $team_id ) :
if ( ! $team_id ) {
continue;
}
$team = get_post( $team_id );
if ( $team ) :
echo esc_html( $team->post_title );
if ( in_array( $team_id, $current_teams ) ) :
echo '<span class="dashicons dashicons-yes" title="' . __( 'Current Team', 'sportspress' ) . '"></span>';
endif;
echo '<br>';
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;
endswitch;
}
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;
endswitch;
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_staff' )
return;
if ( $typenow != 'sp_staff' ) {
return;
}
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_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['team'] ) ? sanitize_key( $_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'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
}
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
}
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
if ( $typenow == 'sp_staff' ) {
if ( $typenow == 'sp_staff' ) {
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team';
}
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team';
}
}
}
}
}
endif;

View File

@@ -2,80 +2,84 @@
/**
* Admin functions for the statistics post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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' ) ) {
require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Statistic' ) ) :
/**
* SP_Admin_CPT_Statistic Class
*/
class SP_Admin_CPT_Statistic extends SP_Admin_CPT {
/**
* Constructor
* SP_Admin_CPT_Statistic Class
*/
public function __construct() {
$this->type = 'sp_statistic';
class SP_Admin_CPT_Statistic extends SP_Admin_CPT {
// Admin Columns
add_filter( 'manage_edit-sp_statistic_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_statistic_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_statistic';
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'sp_icon' => __( 'Icon', 'sportspress' ),
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Key', 'sportspress' ),
'sp_equation' => __( 'Equation', 'sportspress' ),
'sp_precision' => __( 'Decimal Places', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_statistic_admin_columns', $columns );
}
// Admin Columns
add_filter( 'manage_edit-sp_statistic_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_statistic_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_icon':
echo has_post_thumbnail( $post_id ) ? edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-fit-mini' ), '', '', $post_id ) : '';
break;
case 'sp_key':
global $post;
echo esc_html( $post->post_name );
break;
case 'sp_equation':
echo esc_html( sp_get_post_equation( $post_id ) );
break;
case 'sp_precision':
echo esc_html( sp_get_post_precision( $post_id ) );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
// 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" />',
'sp_icon' => __( 'Icon', 'sportspress' ),
'title' => __( 'Label', 'sportspress' ),
'sp_key' => __( 'Key', 'sportspress' ),
'sp_equation' => __( 'Equation', 'sportspress' ),
'sp_precision' => __( 'Decimal Places', 'sportspress' ),
'sp_description' => __( 'Description', 'sportspress' ),
);
return apply_filters( 'sportspress_statistic_admin_columns', $columns );
}
/**
* Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_icon':
echo has_post_thumbnail( $post_id ) ? edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-fit-mini' ), '', '', $post_id ) : '';
break;
case 'sp_key':
global $post;
echo esc_html( $post->post_name );
break;
case 'sp_equation':
echo esc_html( sp_get_post_equation( $post_id ) );
break;
case 'sp_precision':
echo esc_html( sp_get_post_precision( $post_id ) );
break;
case 'sp_description':
global $post;
echo '<span class="description">' . wp_kses_post( $post->post_excerpt ) . '</span>';
break;
endswitch;
}
}
}
endif;

View File

@@ -2,136 +2,144 @@
/**
* Admin functions for the league tables post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.5
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.5
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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' ) ) {
require 'class-sp-admin-cpt.php';
}
if ( ! class_exists( 'SP_Admin_CPT_Table' ) ) :
/**
* SP_Admin_CPT_Table Class
*/
class SP_Admin_CPT_Table extends SP_Admin_CPT {
/**
* Constructor
* SP_Admin_CPT_Table Class
*/
public function __construct() {
$this->type = 'sp_table';
class SP_Admin_CPT_Table extends SP_Admin_CPT {
// Admin Columns
add_filter( 'manage_edit-sp_table_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_table_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_table';
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
// Call SP_Admin_CPT constructor
parent::__construct();
}
// Admin Columns
add_filter( 'manage_edit-sp_table_columns', array( $this, 'edit_columns' ) );
add_action( 'manage_sp_table_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 );
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['date'] );
$columns = array_merge( array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
), $existing_columns );
return apply_filters( 'sportspress_table_admin_columns', $columns );
}
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
add_filter( 'parse_query', array( $this, 'filters_query' ) );
/**
* 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_team':
$select = get_post_meta( $post_id, 'sp_select', true );
if ( 'manual' == $select ):
$teams = array_filter( get_post_meta( $post_id, 'sp_team' ) );
echo sizeof( $teams );
else:
_e( 'Auto', 'sportspress' );
endif;
break;
endswitch;
}
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
/**
* Change the columns shown in admin.
*/
public function edit_columns( $existing_columns ) {
unset( $existing_columns['date'] );
$columns = array_merge(
array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title', 'sportspress' ),
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
),
$existing_columns
);
return apply_filters( 'sportspress_table_admin_columns', $columns );
}
if ( $typenow != 'sp_table' )
return;
/**
* 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_team':
$select = get_post_meta( $post_id, 'sp_select', true );
if ( 'manual' == $select ) :
$teams = array_filter( get_post_meta( $post_id, 'sp_team' ) );
echo sizeof( $teams );
else :
_e( 'Auto', 'sportspress' );
endif;
break;
endswitch;
}
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
if ( $typenow != 'sp_table' ) {
return;
}
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_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'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
if ( $typenow == 'sp_table' ) {
$selected = isset( $_REQUEST['team'] ) ? sanitize_key( $_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 );
}
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team';
}
/**
* Filter in admin based on options
*
* @param mixed $query
*/
public function filters_query( $query ) {
global $typenow, $wp_query;
if ( $typenow == 'sp_table' ) {
if ( ! empty( $_GET['team'] ) ) {
$query->query_vars['meta_value'] = sanitize_key( $_GET['team'] );
$query->query_vars['meta_key'] = 'sp_team';
}
}
}
}
}
endif;

View File

@@ -2,131 +2,142 @@
/**
* Admin functions for the teams post type
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.6
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 2.6
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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' ) ) {
require '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
* SP_Admin_CPT_Team Class
*/
public function __construct() {
$this->type = 'sp_team';
class SP_Admin_CPT_Team extends SP_Admin_CPT {
// Post title fields
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
/**
* Constructor
*/
public function __construct() {
$this->type = 'sp_team';
// 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 );
// Post title fields
add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 1, 2 );
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
// Call SP_Admin_CPT constructor
parent::__construct();
// 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 );
// Filtering
add_action( 'restrict_manage_posts', array( $this, 'filters' ) );
// Call SP_Admin_CPT constructor
parent::__construct();
}
/**
* 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 ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge(
array(
'cb' => '<input type="checkbox" />',
'sp_icon' => '<span class="dashicons sp-icon-shield sp-tip" title="' . __( 'Logo', 'sportspress' ) . '"></span>',
'title' => null,
'sp_short_name' => __( 'Short Name', 'sportspress' ),
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
),
$existing_columns,
array(
'title' => __( 'Team', 'sportspress' ),
)
);
return apply_filters( 'sportspress_team_admin_columns', $columns );
}
/**
* Define our custom columns shown in admin.
*
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ) :
case 'sp_icon':
echo has_post_thumbnail( $post_id ) ? edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-fit-mini' ), '', '', $post_id ) : '';
break;
case 'sp_short_name':
$short_name = get_post_meta( $post_id, 'sp_short_name', true );
echo $short_name ? esc_html( $short_name ) : '&mdash;';
break;
case 'sp_abbreviation':
$abbreviation = get_post_meta( $post_id, 'sp_abbreviation', true );
echo $abbreviation ? esc_html( $abbreviation ) : '&mdash;';
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;
endswitch;
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_team' ) {
return;
}
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected,
);
sp_dropdown_taxonomies( $args );
}
}
/**
* 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 ) {
unset( $existing_columns['author'], $existing_columns['date'] );
$columns = array_merge( array(
'cb' => '<input type="checkbox" />',
'sp_icon' => '<span class="dashicons sp-icon-shield sp-tip" title="' . __( 'Logo', 'sportspress' ) . '"></span>',
'title' => null,
'sp_short_name' => __( 'Short Name', 'sportspress' ),
'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ),
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
), $existing_columns, array(
'title' => __( 'Team', 'sportspress' ),
) );
return apply_filters( 'sportspress_team_admin_columns', $columns );
}
/**
* Define our custom columns shown in admin.
* @param string $column
*/
public function custom_columns( $column, $post_id ) {
switch ( $column ):
case 'sp_icon':
echo has_post_thumbnail( $post_id ) ? edit_post_link( get_the_post_thumbnail( $post_id, 'sportspress-fit-mini' ), '', '', $post_id ) : '';
break;
case 'sp_short_name':
$short_name = get_post_meta ( $post_id, 'sp_short_name', true );
echo $short_name ? esc_html( $short_name ) : '&mdash;';
break;
case 'sp_abbreviation':
$abbreviation = get_post_meta ( $post_id, 'sp_abbreviation', true );
echo $abbreviation ? esc_html( $abbreviation ) : '&mdash;';
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;
endswitch;
}
/**
* Show a category filter box
*/
public function filters() {
global $typenow, $wp_query;
if ( $typenow != 'sp_team' )
return;
$selected = isset( $_REQUEST['sp_league'] ) ? sanitize_key( $_REQUEST['sp_league'] ) : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
$selected = isset( $_REQUEST['sp_season'] ) ? sanitize_key( $_REQUEST['sp_season'] ) : null;
$args = array(
'show_option_all' => __( 'Show all seasons', 'sportspress' ),
'taxonomy' => 'sp_season',
'name' => 'sp_season',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
}
}
endif;
return new SP_Admin_CPT_Team();

View File

@@ -2,66 +2,70 @@
/**
* Admin functions for post types
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Post_Types
* @version 0.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
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
* SP_Admin_CPT Class
*/
public function __construct() {
// Insert into X media browser
add_filter( 'media_view_strings', array( $this, 'change_insert_into_post' ) );
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' ) );
}
/**
* 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', '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;
}
}
/**
* 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', '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;
}
}
endif;
endif;

View File

@@ -4,13 +4,15 @@
*
* Sets up the write panels used by custom post types
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.6.8
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.6.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Admin_Meta_Boxes
@@ -27,202 +29,202 @@ class SP_Admin_Meta_Boxes {
*/
public function __construct() {
$meta_boxes = array(
'sp_outcome' => array(
'sp_outcome' => array(
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Outcome_Details::save',
'output' => 'SP_Meta_Box_Outcome_Details::output',
'context' => 'normal',
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Outcome_Details::save',
'output' => 'SP_Meta_Box_Outcome_Details::output',
'context' => 'normal',
'priority' => 'high',
),
),
'sp_result' => array(
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Result_Details::save',
'output' => 'SP_Meta_Box_Result_Details::output',
'context' => 'side',
'sp_result' => array(
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Result_Details::save',
'output' => 'SP_Meta_Box_Result_Details::output',
'context' => 'side',
'priority' => 'default',
),
'equation' => array(
'title' => __( 'Equation', 'sportspress' ),
'save' => 'SP_Meta_Box_Result_Equation::save',
'output' => 'SP_Meta_Box_Result_Equation::output',
'context' => 'normal',
'title' => __( 'Equation', 'sportspress' ),
'save' => 'SP_Meta_Box_Result_Equation::save',
'output' => 'SP_Meta_Box_Result_Equation::output',
'context' => 'normal',
'priority' => 'high',
),
),
'sp_performance' => array(
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Performance_Details::save',
'output' => 'SP_Meta_Box_Performance_Details::output',
'context' => 'normal',
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Performance_Details::save',
'output' => 'SP_Meta_Box_Performance_Details::output',
'context' => 'normal',
'priority' => 'high',
),
'equation' => array(
'title' => __( 'Equation', 'sportspress' ),
'save' => 'SP_Meta_Box_Performance_Equation::save',
'output' => 'SP_Meta_Box_Performance_Equation::output',
'context' => 'normal',
'title' => __( 'Equation', 'sportspress' ),
'save' => 'SP_Meta_Box_Performance_Equation::save',
'output' => 'SP_Meta_Box_Performance_Equation::output',
'context' => 'normal',
'priority' => 'high',
),
),
'sp_column' => array(
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Column_Details::save',
'output' => 'SP_Meta_Box_Column_Details::output',
'context' => 'side',
'sp_column' => array(
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Column_Details::save',
'output' => 'SP_Meta_Box_Column_Details::output',
'context' => 'side',
'priority' => 'default',
),
'equation' => array(
'title' => __( 'Equation', 'sportspress' ),
'save' => 'SP_Meta_Box_Column_Equation::save',
'output' => 'SP_Meta_Box_Column_Equation::output',
'context' => 'normal',
'title' => __( 'Equation', 'sportspress' ),
'save' => 'SP_Meta_Box_Column_Equation::save',
'output' => 'SP_Meta_Box_Column_Equation::output',
'context' => 'normal',
'priority' => 'high',
),
),
'sp_metric' => array(
'sp_metric' => array(
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Metric_Details::save',
'output' => 'SP_Meta_Box_Metric_Details::output',
'context' => 'normal',
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Metric_Details::save',
'output' => 'SP_Meta_Box_Metric_Details::output',
'context' => 'normal',
'priority' => 'high',
),
),
'sp_statistic' => array(
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Statistic_Details::save',
'output' => 'SP_Meta_Box_Statistic_Details::output',
'context' => 'side',
'sp_statistic' => array(
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Statistic_Details::save',
'output' => 'SP_Meta_Box_Statistic_Details::output',
'context' => 'side',
'priority' => 'default',
),
'equation' => array(
'title' => __( 'Equation', 'sportspress' ),
'save' => 'SP_Meta_Box_Statistic_Equation::save',
'output' => 'SP_Meta_Box_Statistic_Equation::output',
'context' => 'normal',
'title' => __( 'Equation', 'sportspress' ),
'save' => 'SP_Meta_Box_Statistic_Equation::save',
'output' => 'SP_Meta_Box_Statistic_Equation::output',
'context' => 'normal',
'priority' => 'high',
),
),
'sp_event' => array(
'shortcode' => array(
'title' => __( 'Shortcodes', 'sportspress' ),
'output' => 'SP_Meta_Box_Event_Shortcode::output',
'context' => 'side',
'sp_event' => array(
'shortcode' => array(
'title' => __( 'Shortcodes', 'sportspress' ),
'output' => 'SP_Meta_Box_Event_Shortcode::output',
'context' => 'side',
'priority' => 'default',
),
'format' => array(
'title' => __( 'Format', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Format::save',
'output' => 'SP_Meta_Box_Event_Format::output',
'context' => 'side',
'format' => array(
'title' => __( 'Format', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Format::save',
'output' => 'SP_Meta_Box_Event_Format::output',
'context' => 'side',
'priority' => 'default',
),
'mode' => array(
'title' => __( 'Mode', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Mode::save',
'output' => 'SP_Meta_Box_Event_Mode::output',
'context' => 'side',
'mode' => array(
'title' => __( 'Mode', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Mode::save',
'output' => 'SP_Meta_Box_Event_Mode::output',
'context' => 'side',
'priority' => 'default',
),
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Details::save',
'output' => 'SP_Meta_Box_Event_Details::output',
'context' => 'side',
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Details::save',
'output' => 'SP_Meta_Box_Event_Details::output',
'context' => 'side',
'priority' => 'default',
),
'team' => array(
'title' => __( 'Teams', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Teams::save',
'output' => 'SP_Meta_Box_Event_Teams::output',
'context' => 'side',
'team' => array(
'title' => __( 'Teams', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Teams::save',
'output' => 'SP_Meta_Box_Event_Teams::output',
'context' => 'side',
'priority' => 'default',
),
'results' => array(
'title' => __( 'Results', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Results::save',
'output' => 'SP_Meta_Box_Event_Results::output',
'context' => 'normal',
'results' => array(
'title' => __( 'Results', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Results::save',
'output' => 'SP_Meta_Box_Event_Results::output',
'context' => 'normal',
'priority' => 'high',
),
'performance' => array(
'title' => __( 'Box Score', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Performance::save',
'output' => 'SP_Meta_Box_Event_Performance::output',
'context' => 'normal',
'title' => __( 'Box Score', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Performance::save',
'output' => 'SP_Meta_Box_Event_Performance::output',
'context' => 'normal',
'priority' => 'high',
),
),
'sp_team' => array(
'sp_team' => array(
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Team_Details::save',
'output' => 'SP_Meta_Box_Team_Details::output',
'context' => 'side',
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Team_Details::save',
'output' => 'SP_Meta_Box_Team_Details::output',
'context' => 'side',
'priority' => 'default',
),
'staff' => array(
'title' => __( 'Staff', 'sportspress' ),
'save' => 'SP_Meta_Box_Team_Staff::save',
'output' => 'SP_Meta_Box_Team_Staff::output',
'context' => 'normal',
'staff' => array(
'title' => __( 'Staff', 'sportspress' ),
'save' => 'SP_Meta_Box_Team_Staff::save',
'output' => 'SP_Meta_Box_Team_Staff::output',
'context' => 'normal',
'priority' => 'high',
),
),
'sp_player' => array(
'shortcode' => array(
'title' => __( 'Shortcodes', 'sportspress' ),
'output' => 'SP_Meta_Box_Player_Shortcode::output',
'context' => 'side',
'sp_player' => array(
'shortcode' => array(
'title' => __( 'Shortcodes', 'sportspress' ),
'output' => 'SP_Meta_Box_Player_Shortcode::output',
'context' => 'side',
'priority' => 'default',
),
'columns' => array(
'title' => __( 'Columns', 'sportspress' ),
'save' => 'SP_Meta_Box_Player_Columns::save',
'output' => 'SP_Meta_Box_Player_Columns::output',
'context' => 'side',
'columns' => array(
'title' => __( 'Columns', 'sportspress' ),
'save' => 'SP_Meta_Box_Player_Columns::save',
'output' => 'SP_Meta_Box_Player_Columns::output',
'context' => 'side',
'priority' => 'default',
),
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Player_Details::save',
'output' => 'SP_Meta_Box_Player_Details::output',
'context' => 'side',
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Player_Details::save',
'output' => 'SP_Meta_Box_Player_Details::output',
'context' => 'side',
'priority' => 'default',
),
'metrics' => array(
'title' => __( 'Metrics', 'sportspress' ),
'save' => 'SP_Meta_Box_Player_Metrics::save',
'output' => 'SP_Meta_Box_Player_Metrics::output',
'context' => 'side',
'metrics' => array(
'title' => __( 'Metrics', 'sportspress' ),
'save' => 'SP_Meta_Box_Player_Metrics::save',
'output' => 'SP_Meta_Box_Player_Metrics::output',
'context' => 'side',
'priority' => 'default',
),
'statistics' => array(
'title' => __( 'Statistics', 'sportspress' ),
'save' => 'SP_Meta_Box_Player_Statistics::save',
'output' => 'SP_Meta_Box_Player_Statistics::output',
'context' => 'normal',
'title' => __( 'Statistics', 'sportspress' ),
'save' => 'SP_Meta_Box_Player_Statistics::save',
'output' => 'SP_Meta_Box_Player_Statistics::output',
'context' => 'normal',
'priority' => 'high',
),
),
'sp_staff' => array(
'sp_staff' => array(
'shortcode' => array(
'title' => __( 'Shortcode', 'sportspress' ),
'output' => 'SP_Meta_Box_Staff_Shortcode::output',
'context' => 'side',
'title' => __( 'Shortcode', 'sportspress' ),
'output' => 'SP_Meta_Box_Staff_Shortcode::output',
'context' => 'side',
'priority' => 'default',
),
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Staff_Details::save',
'output' => 'SP_Meta_Box_Staff_Details::output',
'context' => 'side',
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Staff_Details::save',
'output' => 'SP_Meta_Box_Staff_Details::output',
'context' => 'side',
'priority' => 'default',
),
),
@@ -303,7 +305,7 @@ class SP_Admin_Meta_Boxes {
remove_meta_box( 'postimagediv', 'sp_performance', 'side' );
add_meta_box( 'postimagediv', __( 'Icon', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_performance', 'side', 'low' );
remove_meta_box( 'postimagediv', 'sp_statistic', 'side' );
add_meta_box( 'postimagediv', __( 'Icon', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_statistic', 'side', 'low' );
}
@@ -311,17 +313,31 @@ class SP_Admin_Meta_Boxes {
/**
* Check if we're saving, then trigger an action based on the post type
*
* @param int $post_id
* @param int $post_id
* @param object $post
*/
public function save_meta_boxes( $post_id, $post ) {
if ( empty( $post_id ) || empty( $post ) ) return;
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if ( is_int( wp_is_post_revision( $post ) ) ) return;
if ( is_int( wp_is_post_autosave( $post ) ) ) return;
if ( empty( $_POST['sportspress_meta_nonce'] ) || ! wp_verify_nonce( $_POST['sportspress_meta_nonce'], 'sportspress_save_data' ) ) return;
if ( ! apply_filters( 'sportspress_user_can', current_user_can( 'edit_post', $post_id ), $post_id ) ) return;
if ( ! is_sp_post_type( $post->post_type ) && ! is_sp_config_type( $post->post_type ) ) return;
if ( empty( $post_id ) || empty( $post ) ) {
return;
}
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
if ( is_int( wp_is_post_revision( $post ) ) ) {
return;
}
if ( is_int( wp_is_post_autosave( $post ) ) ) {
return;
}
if ( empty( $_POST['sportspress_meta_nonce'] ) || ! wp_verify_nonce( $_POST['sportspress_meta_nonce'], 'sportspress_save_data' ) ) {
return;
}
if ( ! apply_filters( 'sportspress_user_can', current_user_can( 'edit_post', $post_id ), $post_id ) ) {
return;
}
if ( ! is_sp_post_type( $post->post_type ) && ! is_sp_config_type( $post->post_type ) ) {
return;
}
do_action( 'sportspress_process_' . $post->post_type . '_meta', $post_id, $post );
}

View File

@@ -2,13 +2,15 @@
/**
* Calendar Columns
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Calendar_Columns
@@ -19,9 +21,9 @@ class SP_Meta_Box_Calendar_Columns {
* Output the metabox
*/
public static function output( $post ) {
$selected = (array) get_post_meta( $post->ID, 'sp_columns', true );
$selected = (array) get_post_meta( $post->ID, 'sp_columns', true );
$title_format = get_option( 'sportspress_event_list_title_format', 'title' );
$time_format = get_option( 'sportspress_event_list_time_format', 'combined' );
$time_format = get_option( 'sportspress_event_list_time_format', 'combined' );
if ( is_array( $selected ) ) {
$selected = array_filter( $selected );
@@ -30,11 +32,11 @@ class SP_Meta_Box_Calendar_Columns {
$columns = array();
if ( 'teams' === $title_format ) {
$columns[ 'event' ] = __( 'Home', 'sportspress' ) . ' | ' . __( 'Away', 'sportspress' );
$columns['event'] = __( 'Home', 'sportspress' ) . ' | ' . __( 'Away', 'sportspress' );
} elseif ( 'homeaway' === $title_format ) {
$columns[ 'event' ] = __( 'Teams', 'sportspress' );
$columns['event'] = __( 'Teams', 'sportspress' );
} else {
$columns[ 'event' ] = __( 'Title', 'sportspress' );
$columns['event'] = __( 'Title', 'sportspress' );
}
if ( 'time' === $time_format || 'separate' === $time_format ) {
@@ -47,27 +49,27 @@ class SP_Meta_Box_Calendar_Columns {
$columns['results'] = __( 'Results', 'sportspress' );
}
$columns['league'] = __( 'League', 'sportspress' );
$columns['season'] = __( 'Season', 'sportspress' );
$columns['venue'] = __( 'Venue', 'sportspress' );
$columns['league'] = __( 'League', 'sportspress' );
$columns['season'] = __( 'Season', 'sportspress' );
$columns['venue'] = __( 'Venue', 'sportspress' );
$columns['article'] = __( 'Article', 'sportspress' );
$columns['day'] = __( 'Match Day', 'sportspress' );
$columns['day'] = __( 'Match Day', 'sportspress' );
$columns = apply_filters( 'sportspress_calendar_columns', $columns );
?>
<div class="sp-instance">
<ul class="categorychecklist form-no-clear">
<?php
foreach ( $columns as $key => $label ) {
?>
foreach ( $columns as $key => $label ) {
?>
<li>
<label>
<input type="checkbox" name="sp_columns[]" value="<?php echo esc_attr( $key ); ?>" id="sp_columns_<?php echo esc_attr( $key ); ?>" <?php checked( ! is_array( $selected ) || in_array( $key, $selected ) ); ?>>
<?php echo esc_html( $label ); ?>
<?php echo esc_html( $label ); ?>
</label>
</li>
<?php
}
}
?>
</div>
<?php
@@ -79,4 +81,4 @@ class SP_Meta_Box_Calendar_Columns {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array(), 'text' ) );
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Calendar Events
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Calendar_Data
@@ -19,8 +21,8 @@ class SP_Meta_Box_Calendar_Data {
* Output the metabox
*/
public static function output( $post ) {
$calendar = new SP_Calendar( $post );
$data = $calendar->data();
$calendar = new SP_Calendar( $post );
$data = $calendar->data();
$usecolumns = $calendar->columns;
self::table( $data, $usecolumns );
}
@@ -37,11 +39,11 @@ class SP_Meta_Box_Calendar_Data {
*/
public static function table( $data = array(), $usecolumns = null ) {
$title_format = get_option( 'sportspress_event_list_title_format', 'title' );
$time_format = get_option( 'sportspress_event_list_time_format', 'combined' );
$time_format = get_option( 'sportspress_event_list_time_format', 'combined' );
if ( is_array( $usecolumns ) ) {
$usecolumns = array_filter( $usecolumns );
}else{
} else {
$usecolumns = array();
}
?>
@@ -57,7 +59,11 @@ class SP_Meta_Box_Calendar_Data {
<label for="sp_columns_event">
<?php
if ( 'teams' == $title_format ) {
_e( 'Home', 'sportspress' ); ?> | <?php _e( 'Away', 'sportspress' );
_e( 'Home', 'sportspress' );
?>
|
<?php
_e( 'Away', 'sportspress' );
} elseif ( 'homeaway' == $title_format ) {
_e( 'Teams', 'sportspress' );
} else {
@@ -127,50 +133,64 @@ class SP_Meta_Box_Calendar_Data {
</thead>
<tbody>
<?php
if ( is_array( $data ) ):
if ( sizeof( $data ) > 0 ):
if ( is_array( $data ) ) :
if ( sizeof( $data ) > 0 ) :
$main_result = get_option( 'sportspress_primary_result', null );
$i = 0;
foreach ( $data as $event ):
$teams = get_post_meta( $event->ID, 'sp_team' );
$results = get_post_meta( $event->ID, 'sp_results', true );
$video = get_post_meta( $event->ID, 'sp_video', true );
$i = 0;
foreach ( $data as $event ) :
$teams = get_post_meta( $event->ID, 'sp_team' );
$results = get_post_meta( $event->ID, 'sp_results', true );
$video = get_post_meta( $event->ID, 'sp_video', true );
$main_results = array();
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<tr class="sp-row sp-post
<?php
if ( $i % 2 == 0 ) {
echo ' alternate';}
?>
">
<td><?php echo get_post_time( get_option( 'date_format' ), false, $event, true ); ?></td>
<?php if ( is_array( $usecolumns ) && in_array( 'event', $usecolumns ) ) { ?>
<td>
<div class="sp-title-format sp-title-format-title<?php if ( $title_format && $title_format != 'title' ): ?> hidden<?php endif; ?>"><?php echo esc_html( $event->post_title ); ?></div>
<div class="sp-title-format sp-title-format-teams sp-title-format-homeaway<?php if ( ! in_array( $title_format, array( 'teams', 'homeaway' ) ) ): ?> hidden<?php endif; ?>">
<div class="sp-title-format sp-title-format-title
<?php
if ( $title_format && $title_format != 'title' ) :
?>
hidden<?php endif; ?>"><?php echo esc_html( $event->post_title ); ?></div>
<div class="sp-title-format sp-title-format-teams sp-title-format-homeaway
<?php
if ( ! in_array( $title_format, array( 'teams', 'homeaway' ) ) ) :
?>
hidden<?php endif; ?>">
<?php
if ( $teams ): foreach ( $teams as $team ):
$name = get_the_title( $team );
if ( $name ):
$team_results = sp_array_value( $results, $team, null );
if ( $teams ) :
foreach ( $teams as $team ) :
$name = get_the_title( $team );
if ( $name ) :
$team_results = sp_array_value( $results, $team, null );
if ( $main_result ):
$team_result = sp_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;
if ( $main_result ) :
$team_result = sp_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;
endif;
if ( $team_result != null ):
$team_result = apply_filters( 'sportspress_calendar_team_result_admin', $team_result, $event->ID, $team );
$main_results[] = $team_result;
unset( $team_results['outcome'] );
$team_results = implode( ' | ', $team_results );
echo '<a class="result sp-tip" title="' . $team_results . '" href="' . get_edit_post_link( $event->ID ) . '">' . $team_result . '</a> ';
endif;
if ( $team_result != null ) :
$team_result = apply_filters( 'sportspress_calendar_team_result_admin', $team_result, $event->ID, $team );
$main_results[] = $team_result;
unset( $team_results['outcome'] );
$team_results = implode( ' | ', $team_results );
echo '<a class="result sp-tip" title="' . $team_results . '" href="' . get_edit_post_link( $event->ID ) . '">' . $team_result . '</a> ';
endif;
echo esc_html( $name ) . '<br>';
endif;
endforeach; else:
echo esc_html( $name ) . '<br>';
endif;
endforeach; else :
echo '&mdash;';
endif;
?>
@@ -185,24 +205,24 @@ class SP_Meta_Box_Calendar_Data {
<?php } else { ?>
<td>
<?php
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
if ( ! empty( $main_results ) ) :
echo implode( ' - ', $main_results );
else :
echo apply_filters( 'sportspress_event_time_admin', get_post_time( get_option( 'time_format' ), false, $event, true ), $event->ID );
endif;
?>
?>
</td>
<?php } ?>
<?php } ?>
<?php if ( ( is_array( $usecolumns ) && in_array( 'results', $usecolumns ) ) && in_array( $time_format, array( 'separate', 'results' ) ) ) { ?>
<td>
<?php
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
if ( ! empty( $main_results ) ) :
echo implode( ' - ', $main_results );
else :
echo '-';
endif;
?>
?>
</td>
<?php } ?>
<?php if ( is_array( $usecolumns ) && in_array( 'league', $usecolumns ) ) { ?>
@@ -217,17 +237,17 @@ class SP_Meta_Box_Calendar_Data {
<?php if ( is_array( $usecolumns ) && in_array( 'article', $usecolumns ) ) { ?>
<td>
<a href="<?php echo get_edit_post_link( $event->ID ); ?>#sp_articlediv">
<?php if ( $video ): ?>
<?php if ( $video ) : ?>
<div class="dashicons dashicons-video-alt"></div>
<?php elseif ( has_post_thumbnail( $event->ID ) ): ?>
<?php elseif ( has_post_thumbnail( $event->ID ) ) : ?>
<div class="dashicons dashicons-camera"></div>
<?php endif; ?>
<?php
if ( $event->post_content == null ):
if ( $event->post_content == null ) :
_e( 'None', 'sportspress' );
elseif ( $event->post_status == 'publish' ):
elseif ( $event->post_status == 'publish' ) :
_e( 'Recap', 'sportspress' );
else:
else :
_e( 'Preview', 'sportspress' );
endif;
?>
@@ -251,7 +271,7 @@ class SP_Meta_Box_Calendar_Data {
<?php
$i++;
endforeach;
else:
else :
?>
<tr class="sp-row alternate">
<td colspan="<?php echo sizeof( $usecolumns ); ?>">
@@ -260,14 +280,14 @@ class SP_Meta_Box_Calendar_Data {
</tr>
<?php
endif;
else:
?>
else :
?>
<tr class="sp-row alternate">
<td colspan="<?php echo sizeof( $usecolumns ); ?>">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?>
</td>
</tr>
<?php
<?php
endif;
?>
</tbody>

View File

@@ -2,13 +2,15 @@
/**
* Calendar Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Calendar_Details
@@ -19,22 +21,22 @@ class SP_Meta_Box_Calendar_Details {
* Output the metabox
*/
public static function output( $post ) {
$taxonomies = get_object_taxonomies( 'sp_calendar' );
$caption = get_post_meta( $post->ID, 'sp_caption', true );
$status = get_post_meta( $post->ID, 'sp_status', true );
$date = get_post_meta( $post->ID, 'sp_date', true );
$date_from = get_post_meta( $post->ID, 'sp_date_from', true );
$date_to = get_post_meta( $post->ID, 'sp_date_to', true );
$date_past = get_post_meta( $post->ID, 'sp_date_past', true );
$date_future = get_post_meta( $post->ID, 'sp_date_future', true );
$taxonomies = get_object_taxonomies( 'sp_calendar' );
$caption = get_post_meta( $post->ID, 'sp_caption', true );
$status = get_post_meta( $post->ID, 'sp_status', true );
$date = get_post_meta( $post->ID, 'sp_date', true );
$date_from = get_post_meta( $post->ID, 'sp_date_from', true );
$date_to = get_post_meta( $post->ID, 'sp_date_to', true );
$date_past = get_post_meta( $post->ID, 'sp_date_past', true );
$date_future = get_post_meta( $post->ID, 'sp_date_future', true );
$date_relative = get_post_meta( $post->ID, 'sp_date_relative', true );
$event_format = get_post_meta( $post->ID, 'sp_event_format', true );
$day = get_post_meta( $post->ID, 'sp_day', true );
$teams = get_post_meta( $post->ID, 'sp_team', false );
$players = get_post_meta( $post->ID, 'sp_player', false );
$table_id = get_post_meta( $post->ID, 'sp_table', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
$order = get_post_meta( $post->ID, 'sp_order', true );
$event_format = get_post_meta( $post->ID, 'sp_event_format', true );
$day = get_post_meta( $post->ID, 'sp_day', true );
$teams = get_post_meta( $post->ID, 'sp_team', false );
$players = get_post_meta( $post->ID, 'sp_player', false );
$table_id = get_post_meta( $post->ID, 'sp_table', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
$order = get_post_meta( $post->ID, 'sp_order', true );
?>
<div>
<p><strong><?php _e( 'Heading', 'sportspress' ); ?></strong></p>
@@ -44,8 +46,8 @@ class SP_Meta_Box_Calendar_Details {
<p>
<?php
$args = array(
'name' => 'sp_status',
'id' => 'sp_status',
'name' => 'sp_status',
'id' => 'sp_status',
'selected' => $status,
);
sp_dropdown_statuses( $args );
@@ -55,7 +57,7 @@ class SP_Meta_Box_Calendar_Details {
<p>
<select name="sp_event_format" class="postform">
<option value="all">All</option>
<?php foreach ( SP()->formats->event as $key => $format ): ?>
<?php foreach ( SP()->formats->event as $key => $format ) : ?>
<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $event_format, $key ); ?>><?php echo esc_html( $format ); ?></option>
<?php endforeach; ?>
</select>
@@ -65,8 +67,8 @@ class SP_Meta_Box_Calendar_Details {
<p>
<?php
$args = array(
'name' => 'sp_date',
'id' => 'sp_date',
'name' => 'sp_date',
'id' => 'sp_date',
'selected' => $date,
);
sp_dropdown_dates( $args );
@@ -112,17 +114,17 @@ class SP_Meta_Box_Calendar_Details {
<p>
<?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_team[]',
'selected' => $teams,
'values' => 'ID',
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
'post_type' => 'sp_team',
'name' => 'sp_team[]',
'selected' => $teams,
'values' => 'ID',
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
'placeholder' => __( 'All', 'sportspress' ),
);
if ( ! sp_dropdown_pages( $args ) ):
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
if ( ! sp_dropdown_pages( $args ) ) :
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
@@ -130,17 +132,17 @@ class SP_Meta_Box_Calendar_Details {
<p>
<?php
$args = array(
'post_type' => 'sp_player',
'name' => 'sp_player[]',
'selected' => $players,
'values' => 'ID',
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
'post_type' => 'sp_player',
'name' => 'sp_player[]',
'selected' => $players,
'values' => 'ID',
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
'placeholder' => __( 'All', 'sportspress' ),
);
if ( ! sp_dropdown_pages( $args ) ):
sp_post_adder( 'sp_player', __( 'Add New', 'sportspress' ) );
if ( ! sp_dropdown_pages( $args ) ) :
sp_post_adder( 'sp_player', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
@@ -184,4 +186,4 @@ class SP_Meta_Box_Calendar_Details {
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array(), 'int' ) );
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array(), 'int' ) );
}
}
}

View File

@@ -4,13 +4,15 @@
*
* Based on a tutorial by Steve Thomas.
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Calendar_Feeds
@@ -21,7 +23,7 @@ class SP_Meta_Box_Calendar_Feeds {
* Output the metabox
*/
public static function output( $post ) {
$feeds = new SP_Feeds();
$feeds = new SP_Feeds();
$calendar_feeds = $feeds->calendar;
?>
<div>
@@ -52,4 +54,4 @@ class SP_Meta_Box_Calendar_Feeds {
</div>
<?php
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Calendar Format
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Calendar_Format
@@ -23,7 +25,7 @@ class SP_Meta_Box_Calendar_Format {
$the_format = get_post_meta( $post->ID, 'sp_format', true );
?>
<div id="post-formats-select">
<?php foreach ( SP()->formats->calendar as $key => $format ): ?>
<?php foreach ( SP()->formats->calendar as $key => $format ) : ?>
<input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( true, ( $key == 'calendar' && ! $the_format ) || $the_format == $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $format ); ?></label><br>
<?php endforeach; ?>
</div>
@@ -36,4 +38,4 @@ class SP_Meta_Box_Calendar_Format {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'calendar', 'text' ) );
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Calendar Shortcode
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.6.1
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Calendar_Shortcode
@@ -20,7 +22,9 @@ class SP_Meta_Box_Calendar_Shortcode {
*/
public static function output( $post ) {
$the_format = get_post_meta( $post->ID, 'sp_format', true );
if ( ! $the_format ) $the_format = 'calendar';
if ( ! $the_format ) {
$the_format = 'calendar';
}
?>
<p class="howto">
<?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?>
@@ -28,4 +32,4 @@ class SP_Meta_Box_Calendar_Shortcode {
<p><input type="text" value="<?php sp_shortcode_template( 'event_' . $the_format, $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
<?php
}
}
}

View File

@@ -2,16 +2,19 @@
/**
* Column Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Meta_Box_Config' ) )
include( 'class-sp-meta-box-config.php' );
if ( ! class_exists( 'SP_Meta_Box_Config' ) ) {
require 'class-sp-meta-box-config.php';
}
/**
* SP_Meta_Box_Column_Details
@@ -23,13 +26,15 @@ class SP_Meta_Box_Column_Details extends SP_Meta_Box_Config {
*/
public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
$order = get_post_meta( $post->ID, 'sp_order', true );
$priority = get_post_meta( $post->ID, 'sp_priority', true );
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
$order = get_post_meta( $post->ID, 'sp_order', true );
$priority = get_post_meta( $post->ID, 'sp_priority', true );
$precision = get_post_meta( $post->ID, 'sp_precision', true );
// Defaults
if ( $precision == '' ) $precision = 0;
if ( $precision == '' ) {
$precision = 0;
}
?>
<p><strong><?php _e( 'Key', 'sportspress' ); ?></strong></p>
<p>
@@ -45,19 +50,22 @@ class SP_Meta_Box_Column_Details extends SP_Meta_Box_Config {
<select name="sp_priority">
<?php
$options = array( '0' => __( 'Disable', 'sportspress' ) );
$count = wp_count_posts( 'sp_column' );
for( $i = 1; $i <= $count->publish; $i++ ):
$count = wp_count_posts( 'sp_column' );
for ( $i = 1; $i <= $count->publish; $i++ ) :
$options[ $i ] = $i;
endfor;
foreach ( $options as $key => $value ):
foreach ( $options as $key => $value ) :
printf( '<option value="%s" %s>%s</option>', $key, selected( true, $key == $priority, false ), $value );
endforeach;
?>
</select>
<select name="sp_order">
<?php
$options = array( 'DESC' => __( 'Descending', 'sportspress' ), 'ASC' => __( 'Ascending', 'sportspress' ) );
foreach ( $options as $key => $value ):
$options = array(
'DESC' => __( 'Descending', 'sportspress' ),
'ASC' => __( 'Ascending', 'sportspress' ),
);
foreach ( $options as $key => $value ) :
printf( '<option value="%s" %s>%s</option>', $key, selected( true, $key == $order, false ), $value );
endforeach;
?>
@@ -75,4 +83,4 @@ class SP_Meta_Box_Column_Details extends SP_Meta_Box_Config {
update_post_meta( $post_id, 'sp_priority', sp_array_value( $_POST, 'sp_priority', '0', 'int' ) );
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', 'DESC', 'text' ) );
}
}
}

View File

@@ -2,16 +2,19 @@
/**
* Column Equation
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.9.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Meta_Box_Equation' ) )
include( 'class-sp-meta-box-equation.php' );
if ( ! class_exists( 'SP_Meta_Box_Equation' ) ) {
require 'class-sp-meta-box-equation.php';
}
/**
* SP_Meta_Box_Column_Equation
@@ -25,4 +28,4 @@ class SP_Meta_Box_Column_Equation extends SP_Meta_Box_Equation {
$equation = get_post_meta( $post->ID, 'sp_equation', true );
self::builder( $post->post_title, $equation, array( 'team_event', 'outcome', 'result', 'subset', 'preset' ) );
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Config type meta box functions
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Config
@@ -26,14 +28,16 @@ class SP_Meta_Box_Config {
global $wpdb;
$key = isset( $post['sp_key'] ) ? $post['sp_key'] : null;
if ( ! $key ) $key = $post['post_title'];
$id = sp_array_value( $post, 'post_ID', 'var' );
if ( ! $key ) {
$key = $post['post_title'];
}
$id = sp_array_value( $post, 'post_ID', 'var' );
$title = sp_get_eos_safe_slug( $key, $id );
$check_sql = "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
$check_sql = "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $title, $post['post_type'], $id ) );
if ( $post_name_check ):
if ( $post_name_check ) :
wp_delete_post( $post_name_check, true );
$post['post_status'] = 'draft';
endif;

View File

@@ -2,13 +2,15 @@
/**
* Equation meta box functions
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Equation
@@ -23,88 +25,146 @@ class SP_Meta_Box_Equation {
}
public static function builder( $title = 'f(x)', $equation = '', $groups = array() ) {
if ( $title == '' ) $title = 'f(x)';
if ( $title == '' ) {
$title = 'f(x)';
}
$options = array(); // Multidimensional equation part options
$parts = array(); // Flattened equation part options
$parts = array(); // Flattened equation part options
// Add groups to options
foreach ( $groups as $group ):
switch ( $group ):
foreach ( $groups as $group ) :
switch ( $group ) :
case 'player_event':
$options[ 'Events' ] = array( '$eventsattended' => __( 'Attended', 'sportspress' ), '$eventsplayed' => __( 'Played', 'sportspress' ), '$eventsstarted' => __( 'Started', 'sportspress' ), '$eventssubbed' => __( 'Substituted', 'sportspress' ), '$eventminutes' => __( 'Minutes', 'sportspress' ) );
$options['Events'] = array(
'$eventsattended' => __( 'Attended', 'sportspress' ),
'$eventsplayed' => __( 'Played', 'sportspress' ),
'$eventsstarted' => __( 'Started', 'sportspress' ),
'$eventssubbed' => __( 'Substituted', 'sportspress' ),
'$eventminutes' => __( 'Minutes', 'sportspress' ),
);
break;
case 'team_event':
$options[ 'Events' ] = array( '$eventsplayed' => __( 'Played', 'sportspress' ), '$eventminutes' => __( 'Minutes', 'sportspress' ) );
$options['Events'] = array(
'$eventsplayed' => __( 'Played', 'sportspress' ),
'$eventminutes' => __( 'Minutes', 'sportspress' ),
);
break;
case 'result':
$options[ 'Results' ] = self::optgroup( 'sp_result', array( 'for' => '(' . __( 'for', 'sportspress' ) . ')', 'against' => '(' . __( 'against', 'sportspress' ) . ')' ), null, false );
$options['Results'] = self::optgroup(
'sp_result',
array(
'for' => '(' . __( 'for', 'sportspress' ) . ')',
'against' => '(' . __(
'against',
'sportspress'
) . ')',
),
null,
false
);
break;
case 'outcome':
$options[ 'Outcomes' ] = self::optgroup( 'sp_outcome' );
$options['Outcomes'] = self::optgroup( 'sp_outcome' );
break;
case 'preset':
$options[ 'Presets' ] = array( '$gamesback' => __( 'Games Back', 'sportspress' ), '$homerecord' => __( 'Home Record', 'sportspress' ), '$awayrecord' => __( 'Away Record', 'sportspress' ), '$streak' => __( 'Streak', 'sportspress' ), '$form' => __( 'Form', 'sportspress' ), '$last5' => __( 'Last 5', 'sportspress' ), '$last10' => __( 'Last 10', 'sportspress' ) );
$options['Presets'] = array(
'$gamesback' => __( 'Games Back', 'sportspress' ),
'$homerecord' => __( 'Home Record', 'sportspress' ),
'$awayrecord' => __( 'Away Record', 'sportspress' ),
'$streak' => __( 'Streak', 'sportspress' ),
'$form' => __( 'Form', 'sportspress' ),
'$last5' => __( 'Last 5', 'sportspress' ),
'$last10' => __( 'Last 10', 'sportspress' ),
);
break;
case 'subset':
$options[ 'Subsets' ] = array( '_home' => '@' . __( 'Home', 'sportspress' ), '_away' => '@' . __( 'Away', 'sportspress' ), '_venue' => '@' . __( 'Venue', 'sportspress' ) );
$options['Subsets'] = array(
'_home' => '@' . __( 'Home', 'sportspress' ),
'_away' => '@' . __( 'Away', 'sportspress' ),
'_venue' => '@' . __( 'Venue', 'sportspress' ),
);
break;
case 'performance':
$options[ 'Performance' ] = self::optgroup( 'sp_performance' );
$options['Performance'] = self::optgroup( 'sp_performance' );
break;
case 'metric':
$options[ 'Metrics' ] = self::optgroup( 'sp_metric' );
$options['Metrics'] = self::optgroup( 'sp_metric' );
break;
endswitch;
endforeach;
// Add operators to options
$options[ 'Operators' ] = array( '+' => '&#43;', '-' => '&minus;', '*' => '&times;', '/' => '&divide;', '(' => '(', ')' => ')' );
$options['Operators'] = array(
'+' => '&#43;',
'-' => '&minus;',
'*' => '&times;',
'/' => '&divide;',
'(' => '(',
')' => ')',
);
// Create array of constants
$max = 10;
$max = 10;
$constants = array();
for ( $i = 0; $i <= $max; $i ++ ):
$constants[$i] = $i;
for ( $i = 0; $i <= $max; $i ++ ) :
$constants[ $i ] = $i;
endfor;
// Add 100 to constants
$constants[100] = 100;
// Add constants to options
$options[ 'Constants' ] = (array) $constants;
$options['Constants'] = (array) $constants;
$options = apply_filters( 'sportspress_equation_options', $options );
?>
<div class="sp-equation-builder">
<div class="sp-data-table-container sp-equation-parts">
<table class="widefat sp-data-table">
<?php $i = 0; foreach ( $options as $label => $option ): ?>
<tr<?php if ( $i % 2 == 0 ): ?> class="alternate"<?php endif; ?>>
<?php $i = 0; foreach ( $options as $label => $option ) : ?>
<tr
<?php
if ( $i % 2 == 0 ) :
?>
class="alternate"<?php endif; ?>>
<th><?php _e( $label, 'sportspress' ); ?></th>
<td>
<?php foreach ( $option as $key => $value ): $parts[ $key ] = $value;
?><span class="button" data-variable="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value ); ?></span><?php
endforeach; ?>
<?php
foreach ( $option as $key => $value ) :
$parts[ $key ] = $value;
?>
<span class="button" data-variable="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value ); ?></span>
<?php
endforeach;
?>
</td>
</tr>
<?php $i++; endforeach; ?>
<?php
$i++;
endforeach;
?>
</table>
</div>
<div class="sp-equation">
<span class="sp-equation-variable"><?php echo esc_html( $title ); ?> = </span>
<span class="sp-equation-formula"><?php
<span class="sp-equation-formula">
<?php
$equation = trim( $equation );
if ( $equation !== '' ):
$equation = explode( ' ', $equation );
foreach ( $equation as $part ):
if ( array_key_exists( $part, $parts ) ) {
$name = $parts[ $part ];
} else {
$name = $part;
} ?><span class="button"><?php echo esc_html( $name ); ?><span class="remove">&times;</span><input type="hidden" name="sp_equation[]" value="<?php echo esc_attr( $part ); ?>"></span><?php
endforeach;
if ( $equation !== '' ) :
$equation = explode( ' ', $equation );
foreach ( $equation as $part ) :
if ( array_key_exists( $part, $parts ) ) {
$name = $parts[ $part ];
} else {
$name = $part;
}
?>
<span class="button"><?php echo esc_html( $name ); ?><span class="remove">&times;</span><input type="hidden" name="sp_equation[]" value="<?php echo esc_attr( $part ); ?>"></span>
<?php
endforeach;
endif;
?></span>
?>
</span>
</div>
</div>
<?php
@@ -115,21 +175,21 @@ class SP_Meta_Box_Equation {
// Get posts
$args = array(
'post_type' => $type,
'numberposts' => -1,
'post_type' => $type,
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'meta_query' => array(
'relation' => 'OR',
'orderby' => 'menu_order',
'order' => 'ASC',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'sp_format',
'value' => 'number',
'key' => 'sp_format',
'value' => 'number',
'compare' => 'NOT EXISTS',
),
array(
'key' => 'sp_format',
'value' => array( 'equation', 'text' ),
'key' => 'sp_format',
'value' => array( 'equation', 'text' ),
'compare' => 'NOT IN',
),
),
@@ -137,22 +197,24 @@ class SP_Meta_Box_Equation {
$vars = get_posts( $args );
// Add extra vars to the array
if ( isset( $defaults ) && is_array( $defaults ) ):
foreach ( $defaults as $key => $value ):
if ( isset( $defaults ) && is_array( $defaults ) ) :
foreach ( $defaults as $key => $value ) :
$arr[ $key ] = $value;
endforeach;
endif;
// Add vars to the array
if ( isset( $variations ) && is_array( $variations ) ):
foreach ( $vars as $var ):
if ( $totals ) $arr[ '$' . $var->post_name ] = $var->post_title;
foreach ( $variations as $key => $value ):
if ( isset( $variations ) && is_array( $variations ) ) :
foreach ( $vars as $var ) :
if ( $totals ) {
$arr[ '$' . $var->post_name ] = $var->post_title;
}
foreach ( $variations as $key => $value ) :
$arr[ '$' . $var->post_name . $key ] = $var->post_title . ' ' . $value;
endforeach;
endforeach;
else:
foreach ( $vars as $var ):
else :
foreach ( $vars as $var ) :
$arr[ '$' . $var->post_name ] = $var->post_title;
endforeach;
endif;
@@ -162,6 +224,7 @@ class SP_Meta_Box_Equation {
/**
* Equation part labels for localization
*
* @return null
*/
public static function equation_part_labels() {
@@ -170,4 +233,4 @@ class SP_Meta_Box_Equation {
__( 'Subsets', 'sportspress' );
__( 'Constants', 'sportspress' );
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Event Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Event_Details
@@ -19,9 +21,9 @@ class SP_Meta_Box_Event_Details {
* Output the metabox
*/
public static function output( $post ) {
$day = get_post_meta( $post->ID, 'sp_day', true );
$day = get_post_meta( $post->ID, 'sp_day', true );
$taxonomies = get_object_taxonomies( 'sp_event' );
$minutes = get_post_meta( $post->ID, 'sp_minutes', true );
$minutes = get_post_meta( $post->ID, 'sp_minutes', true );
?>
<?php do_action( 'sportspress_event_details_meta_box', $post ); ?>
<div class="sp-event-day-field">
@@ -39,7 +41,9 @@ class SP_Meta_Box_Event_Details {
</div>
<?php
foreach ( $taxonomies as $taxonomy ) {
if ( 'sp_venue' == $taxonomy ) continue;
if ( 'sp_venue' == $taxonomy ) {
continue;
}
sp_taxonomy_field( $taxonomy, $post, true, true, __( 'None', 'sportspress' ) );
}
?>
@@ -48,14 +52,14 @@ class SP_Meta_Box_Event_Details {
<p>
<?php
$terms = get_the_terms( $post->ID, 'sp_venue' );
$args = array(
'taxonomy' => 'sp_venue',
'name' => 'tax_input[sp_venue][]',
'class' => 'sp-has-dummy',
'selected' => sp_get_the_term_id_or_meta( $post->ID, 'sp_venue' ),
'values' => 'term_id',
$args = array(
'taxonomy' => 'sp_venue',
'name' => 'tax_input[sp_venue][]',
'class' => 'sp-has-dummy',
'selected' => sp_get_the_term_id_or_meta( $post->ID, 'sp_venue' ),
'values' => 'term_id',
'show_option_none' => __( '&mdash; Not set &mdash;', 'sportspress' ),
'chosen' => true,
'chosen' => true,
);
if ( in_array( 'sp_venue', apply_filters( 'sportspress_event_auto_taxonomies', array( 'sp_venue' ) ) ) ) {
$args['show_option_all'] = __( '(Auto)', 'sportspress' );
@@ -75,10 +79,10 @@ class SP_Meta_Box_Event_Details {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_day', sp_array_value( $_POST, 'sp_day', null, 'text' ) );
update_post_meta( $post_id, 'sp_minutes', sp_array_value( $_POST, 'sp_minutes', get_option( 'sportspress_event_minutes', 90 ), 'int' ) );
$venues = array_filter( sp_array_value( sp_array_value( $_POST, 'tax_input', array() ), 'sp_venue', array() ) );
$venues = array_filter( sp_array_value( sp_array_value( $_POST, 'tax_input', array() ), 'sp_venue', array() ) );
if ( empty( $venues ) ) {
$teams = sp_array_value( $_POST, 'sp_team', array(), 'int' );
$team = reset( $teams );
$team = reset( $teams );
$venue = sp_get_the_term_id( $team, 'sp_venue' );
wp_set_post_terms( $post_id, $venue, 'sp_venue' );
}

View File

@@ -2,13 +2,15 @@
/**
* Event Format
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Event_Format
@@ -23,7 +25,7 @@ class SP_Meta_Box_Event_Format {
$the_format = get_post_meta( $post->ID, 'sp_format', true );
?>
<div id="post-formats-select">
<?php foreach ( SP()->formats->event as $key => $format ): ?>
<?php foreach ( SP()->formats->event as $key => $format ) : ?>
<input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( true, ( $key == 'league' && ! $the_format ) || $the_format == $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $format ); ?></label><br>
<?php endforeach; ?>
</div>
@@ -36,4 +38,4 @@ class SP_Meta_Box_Event_Format {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'league', 'text' ) );
}
}
}

View File

@@ -5,34 +5,41 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Event_Mode
*/
class SP_Meta_Box_Event_Mode {
/**
* Output the metabox
*/
public static function output( $post ) {
$the_mode = sp_get_post_mode( $post->ID );
?>
<div id="post-formats-select">
<?php foreach ( array( 'team' => __( 'Team vs team', 'sportspress' ), 'player' => __( 'Player vs player', 'sportspress' ) ) as $key => $mode ): ?>
<input type="radio" name="sp_mode" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( $the_mode, $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $mode ); ?></label><br>
<?php endforeach; ?>
</div>
<?php
}
/**
* Output the metabox
*/
public static function output( $post ) {
$the_mode = sp_get_post_mode( $post->ID );
?>
<div id="post-formats-select">
<?php
foreach ( array(
'team' => __( 'Team vs team', 'sportspress' ),
'player' => __( 'Player vs player', 'sportspress' ),
) as $key => $mode ) :
?>
<input type="radio" name="sp_mode" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( $the_mode, $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $mode ); ?></label><br>
<?php endforeach; ?>
</div>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_mode', sp_array_value( $_POST, 'sp_mode', 'team', 'text' ) );
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_mode', sp_array_value( $_POST, 'sp_mode', 'team', 'text' ) );
}
}

View File

@@ -6,70 +6,76 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Event_Officials
*/
class SP_Meta_Box_Event_Officials {
/**
* Output the metabox
*/
public static function output( $post ) {
$duties = get_terms( array(
'taxonomy' => 'sp_duty',
'hide_empty' => false,
'orderby' => 'meta_value_num',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'sp_order',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'sp_order',
'compare' => 'EXISTS'
),
),
) );
/**
* Output the metabox
*/
public static function output( $post ) {
$duties = get_terms(
array(
'taxonomy' => 'sp_duty',
'hide_empty' => false,
'orderby' => 'meta_value_num',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'sp_order',
'compare' => 'NOT EXISTS',
),
array(
'key' => 'sp_order',
'compare' => 'EXISTS',
),
),
)
);
$officials = (array) get_post_meta( $post->ID, 'sp_officials', true );
$officials = (array) get_post_meta( $post->ID, 'sp_officials', true );
if ( is_array( $duties ) && sizeof( $duties ) ) {
foreach ( $duties as $duty ) {
?>
<p><strong><?php echo esc_html( $duty->name ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_official',
'name' => 'sp_officials[' . $duty->term_id . '][]',
'selected' => sp_array_value( $officials, $duty->term_id, array() ),
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Officials', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
if ( is_array( $duties ) && sizeof( $duties ) ) {
foreach ( $duties as $duty ) {
?>
<p><strong><?php echo esc_html( $duty->name ); ?></strong></p>
<p>
<?php
$args = array(
'post_type' => 'sp_official',
'name' => 'sp_officials[' . $duty->term_id . '][]',
'selected' => sp_array_value( $officials, $duty->term_id, array() ),
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Officials', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
if ( ! sp_dropdown_pages( $args ) ) {
sp_post_adder( 'sp_official', __( 'Add New', 'sportspress' ) );
}
?></p>
<?php
}
} else {
sp_taxonomy_adder( 'sp_duty', 'sp_official', __( 'Duty', 'sportspress' ) );
}
}
if ( ! sp_dropdown_pages( $args ) ) {
sp_post_adder( 'sp_official', __( 'Add New', 'sportspress' ) );
}
?>
</p>
<?php
}
} else {
sp_taxonomy_adder( 'sp_duty', 'sp_official', __( 'Duty', 'sportspress' ) );
}
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_officials', sp_array_value( $_POST, 'sp_officials', array(), 'int' ) );
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_officials', sp_array_value( $_POST, 'sp_officials', array(), 'int' ) );
}
}

View File

@@ -2,13 +2,15 @@
/**
* Event Performance
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Event_Performance
@@ -22,32 +24,35 @@ class SP_Meta_Box_Event_Performance {
$event = new SP_Event( $post );
list( $labels, $columns, $stats, $teams, $formats, $order, $timed, $stars ) = $event->performance( true );
if ( 'yes' == get_option( 'sportspress_event_performance_show_minutes', 'no' ) )
if ( 'yes' == get_option( 'sportspress_event_performance_show_minutes', 'no' ) ) {
$timeline = $event->timeline( true );
else
} else {
$timeline = false;
}
// Determine if columns are auto or manual
if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) )
if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) ) {
$manual = true;
else
} else {
$manual = false;
}
// Determine if we need checkboxes
if ( $manual )
if ( $manual ) {
$has_checkboxes = true;
else
} else {
$has_checkboxes = false;
}
// Get player number option
$numbers = 'yes' == get_option( 'sportspress_event_show_player_numbers', 'yes' ) ? true : false;
// Get positions
$positions = array();
if ( 'yes' == get_option( 'sportspress_event_show_position', 'yes' ) && taxonomy_exists( 'sp_position' ) ):
$args = array(
'hide_empty' => false,
'parent' => 0,
if ( 'yes' == get_option( 'sportspress_event_show_position', 'yes' ) && taxonomy_exists( 'sp_position' ) ) :
$args = array(
'hide_empty' => false,
'parent' => 0,
'include_children' => true,
);
$positions = get_terms( 'sp_position', $args );
@@ -55,7 +60,7 @@ class SP_Meta_Box_Event_Performance {
// Apply filters to labels
$labels = apply_filters( 'sportspress_event_performance_labels_admin', $labels );
// Check if individual mode
$is_individual = 'player' === sp_get_post_mode( $post->ID );
@@ -95,27 +100,29 @@ class SP_Meta_Box_Event_Performance {
<?php self::footer( sp_array_value( $stats, -1 ), $labels, 0, $positions, $status, false, $numbers, -1, $formats ); ?>
<tbody>
<?php
foreach ( $teams as $key => $team_id ):
if ( -1 == $team_id ) continue;
foreach ( $teams as $key => $team_id ) :
if ( -1 == $team_id ) {
continue;
}
// Get results for players in the team
$players = sp_array_between( (array)get_post_meta( $post_id, 'sp_player', false ), 0, $key );
$players = sp_array_between( (array) get_post_meta( $post_id, 'sp_player', false ), 0, $key );
$players[] = -1;
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
// Get team timeline
if ( is_array( $timeline ) ):
if ( is_array( $timeline ) ) :
$team_timeline = (array) sp_array_value( $timeline, $team_id, array() );
else:
else :
$team_timeline = false;
endif;
foreach ( $data as $player_id => $player_performance ):
foreach ( $data as $player_id => $player_performance ) :
// Get player timeline
if ( is_array( $team_timeline ) ):
if ( is_array( $team_timeline ) ) :
$player_timeline = (array) sp_array_value( $team_timeline, $player_id, array() );
else:
else :
$player_timeline = false;
endif;
@@ -129,27 +136,46 @@ class SP_Meta_Box_Event_Performance {
<?php
} else {
$i = 0;
foreach ( $teams as $key => $team_id ):
if ( -1 == $team_id ) continue;
foreach ( $teams as $key => $team_id ) :
if ( -1 == $team_id ) {
continue;
}
if ( -1 == $sections ) {
// Get results for players in the team
$players = sp_array_between( (array)get_post_meta( $post_id, 'sp_player', false ), 0, $key );
$players = sp_array_between( (array) get_post_meta( $post_id, 'sp_player', false ), 0, $key );
$players[] = -1;
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
// Get team timeline
if ( is_array( $timeline ) ):
if ( is_array( $timeline ) ) :
$team_timeline = (array) sp_array_value( $timeline, $team_id, array() );
else:
else :
$team_timeline = false;
endif;
?>
<div>
<p>
<strong><?php echo get_the_title( $team_id ); ?></strong>
<a class="add-new-h2 sp-add-new-h2" href="<?php echo esc_url( admin_url( add_query_arg( array( 'import' => 'sp_event_performance_csv', 'event' => $post_id, 'team' => $team_id, 'teams' => sizeof( $teams ), 'index' => $key ), 'admin.php' ) ) ); ?>"><?php _e( 'Import', 'sportspress' ); ?></a>
<a class="add-new-h2 sp-add-new-h2" href="
<?php
echo esc_url(
admin_url(
add_query_arg(
array(
'import' => 'sp_event_performance_csv',
'event' => $post_id,
'team' => $team_id,
'teams' => sizeof( $teams ),
'index' => $key,
),
'admin.php'
)
)
);
?>
"><?php _e( 'Import', 'sportspress' ); ?></a>
</p>
<?php self::table( $labels, $columns, $data, $team_id, $has_checkboxes && $i === 0, $positions, $status, -1, $formats, $order, $numbers, $team_timeline, $timed, $stars ); ?>
<?php do_action( 'sportspress_after_event_performance_table_admin', $labels, $columns, $data, $team_id ); ?>
@@ -158,21 +184,21 @@ class SP_Meta_Box_Event_Performance {
<?php
// Get labels by section
$args = array(
'post_type' => 'sp_performance',
'numberposts' => 100,
'post_type' => 'sp_performance',
'numberposts' => 100,
'posts_per_page' => 100,
'orderby' => 'menu_order',
'order' => 'ASC',
'meta_query' => array(
'relation' => 'OR',
'orderby' => 'menu_order',
'order' => 'ASC',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'sp_format',
'value' => 'number',
'key' => 'sp_format',
'value' => 'number',
'compare' => 'NOT EXISTS',
),
array(
'key' => 'sp_format',
'value' => 'equation',
'key' => 'sp_format',
'value' => 'equation',
'compare' => '!=',
),
),
@@ -181,12 +207,12 @@ class SP_Meta_Box_Event_Performance {
$performances = get_posts( $args );
$labels = array( array(), array() );
foreach ( $performances as $performance ):
foreach ( $performances as $performance ) :
$section = get_post_meta( $performance->ID, 'sp_section', true );
if ( '' === $section ) {
$section = -1;
}
switch ( $section ):
switch ( $section ) :
case 1:
$labels[1][ $performance->post_name ] = $performance->post_title;
break;
@@ -194,47 +220,65 @@ class SP_Meta_Box_Event_Performance {
$labels[0][ $performance->post_name ] = $performance->post_title;
endswitch;
endforeach;
$offense = (array)get_post_meta( $post_id, 'sp_offense', false );
$defense = (array)get_post_meta( $post_id, 'sp_defense', false );
$data = array();
$offense = (array) get_post_meta( $post_id, 'sp_offense', false );
$defense = (array) get_post_meta( $post_id, 'sp_defense', false );
$data = array();
if ( sizeof( $offense ) || sizeof( $defense ) ) {
// Get results for offensive players in the team
$offense = sp_array_between( $offense, 0, $key );
$offense = sp_array_between( $offense, 0, $key );
$offense[] = -1;
$data[0] = sp_array_combine( $offense, sp_array_value( $stats, $team_id, array() ) );
$data[0] = sp_array_combine( $offense, sp_array_value( $stats, $team_id, array() ) );
// Get results for defensive players in the team
$defense = sp_array_between( $defense, 0, $key );
$defense = sp_array_between( $defense, 0, $key );
$defense[] = -1;
$data[1] = sp_array_combine( $defense, sp_array_value( $stats, $team_id, array() ) );
$data[1] = sp_array_combine( $defense, sp_array_value( $stats, $team_id, array() ) );
} else {
// Get results for all players in the team
$players = sp_array_between( (array)get_post_meta( $post_id, 'sp_player', false ), 0, $key );
$players = sp_array_between( (array) get_post_meta( $post_id, 'sp_player', false ), 0, $key );
$players[] = -1;
$data[0] = $data[1] = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
$data[0] = $data[1] = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
}
// Get team timeline
if ( is_array( $timeline ) ):
if ( is_array( $timeline ) ) :
$team_timeline = (array) sp_array_value( $timeline, $team_id, array() );
else:
else :
$team_timeline = false;
endif;
// Determine order of sections
if ( 1 == $sections ) {
$section_order = array( 1 => __( 'Defense', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ) );
$section_order = array(
1 => __( 'Defense', 'sportspress' ),
0 => __( 'Offense', 'sportspress' ),
);
} else {
$section_order = array( __( 'Offense', 'sportspress' ), __( 'Defense', 'sportspress' ) );
}
foreach ( $section_order as $section_id => $section_label ) {
?>
<div>
<p>
<strong><?php echo get_the_title( $team_id ); ?> &mdash; <?php echo esc_html( $section_label ); ?></strong>
<a class="add-new-h2 sp-add-new-h2" href="<?php echo esc_url( admin_url( add_query_arg( array( 'import' => 'sp_event_performance_csv', 'event' => $post_id, 'team' => $team_id ), 'admin.php' ) ) ); ?>"><?php _e( 'Import', 'sportspress' ); ?></a>
<a class="add-new-h2 sp-add-new-h2" href="
<?php
echo esc_url(
admin_url(
add_query_arg(
array(
'import' => 'sp_event_performance_csv',
'event' => $post_id,
'team' => $team_id,
),
'admin.php'
)
)
);
?>
"><?php _e( 'Import', 'sportspress' ); ?></a>
</p>
<?php self::table( $labels[ $section_id ], $columns, $data[ $section_id ], $team_id, ( $has_checkboxes && 0 === $i ), $positions, $status, $section_id, $formats, $order, $numbers, $team_timeline, $timed, $stars ); ?>
<?php do_action( 'sportspress_after_event_performance_table_admin', $labels[ $section_id ], $columns, $data[ $section_id ], $team_id ); ?>
@@ -259,11 +303,11 @@ class SP_Meta_Box_Event_Performance {
<tbody>
<?php
if ( 1 == $section && is_array( $order ) && sizeof( $order ) ) {
$players = array();
$players = array();
$player_order = sp_array_value( $order, $team_id, array() );
if ( is_array( $player_order ) && sizeof( $player_order ) ) {
foreach ( $player_order as $key ) {
if ( array_key_exists( $key, $data ) ):
if ( array_key_exists( $key, $data ) ) :
$players[ $key ] = $data[ $key ];
endif;
}
@@ -276,12 +320,12 @@ class SP_Meta_Box_Event_Performance {
$data = $players;
}
foreach ( $data as $player_id => $player_performance ):
foreach ( $data as $player_id => $player_performance ) :
// Get player timeline
if ( is_array( $team_timeline ) ):
if ( is_array( $team_timeline ) ) :
$player_timeline = (array) sp_array_value( $team_timeline, $player_id, array() );
else:
else :
$player_timeline = false;
endif;
@@ -315,22 +359,28 @@ class SP_Meta_Box_Event_Performance {
<?php _e( 'Position', 'sportspress' ); ?>
</th>
<?php } ?>
<?php $i = 0; foreach ( $labels as $key => $label ): ?>
<?php if ( 'equation' === sp_array_value( $formats, $key, 'number' ) ) continue; ?>
<?php $i = 0; foreach ( $labels as $key => $label ) : ?>
<?php
if ( 'equation' === sp_array_value( $formats, $key, 'number' ) ) {
continue;}
?>
<th>
<?php if ( $has_checkboxes ): ?>
<?php if ( 0 == $i ): ?>
<?php if ( $has_checkboxes ) : ?>
<?php if ( 0 == $i ) : ?>
<input type="hidden" name="sp_columns[]" value="">
<?php endif; ?>
<label for="sp_columns_<?php echo esc_attr( $key ); ?>">
<input type="checkbox" name="sp_columns[]" value="<?php echo esc_attr( $key ); ?>" id="sp_columns_<?php echo esc_attr( $key ); ?>" <?php checked( ! is_array( $columns ) || in_array( $key, $columns ) ); ?>>
<?php echo esc_html( $label ); ?>
</label>
<?php else: ?>
<?php else : ?>
<?php echo esc_html( $label ); ?>
<?php endif; ?>
</th>
<?php $i++; endforeach; ?>
<?php
$i++;
endforeach;
?>
<?php if ( apply_filters( 'sportspress_event_performance_show_status', $status, $section ) ) { ?>
<th>
<?php _e( 'Status', 'sportspress' ); ?>
@@ -363,13 +413,16 @@ class SP_Meta_Box_Event_Performance {
<?php if ( ! empty( $positions ) ) { ?>
<td>&nbsp;</td>
<?php } ?>
<?php foreach( $labels as $column => $label ):
if ( 'equation' === sp_array_value( $formats, $column, 'number' ) ) continue;
$player_id = 0;
<?php
foreach ( $labels as $column => $label ) :
if ( 'equation' === sp_array_value( $formats, $column, 'number' ) ) {
continue;
}
$player_id = 0;
$player_performance = sp_array_value( $data, $player_id, array() );
$value = sp_array_value( $player_performance, $column, '' );
$format = sp_array_value( $formats, $column, 'number' );
$placeholder = sp_get_format_placeholder( $format );
$value = sp_array_value( $player_performance, $column, '' );
$format = sp_array_value( $formats, $column, 'number' );
$placeholder = sp_get_format_placeholder( $format );
?>
<td><input type="text" name="sp_players[<?php echo esc_attr( $team_id ); ?>][<?php echo esc_attr( $player_id ); ?>][<?php echo esc_attr( $column ); ?>]" placeholder="<?php echo trim( $placeholder ); ?>" value="<?php echo esc_attr( $value ); ?>" data-sp-format="<?php echo esc_attr( $format ); ?>" /></td>
<?php endforeach; ?>
@@ -389,10 +442,12 @@ class SP_Meta_Box_Event_Performance {
* Admin edit table row
*/
public static function row( $labels = array(), $player_id = 0, $player_performance = array(), $team_id = 0, $data = array(), $positions = true, $status = true, $sortable = true, $numbers = true, $section = -1, $formats = array(), $player_timeline = array(), $timed = array(), $stars = array() ) {
if ( $player_id <= 0 ) return;
if ( $player_id <= 0 ) {
return;
}
$stars_type = get_option( 'sportspress_event_performance_stars_type', 0 );
$value = sp_array_value( $player_performance, 'number', '' );
$value = sp_array_value( $player_performance, 'number', '' );
?>
<tr class="sp-row sp-post" data-player="<?php echo esc_attr( $player_id ); ?>">
<?php if ( $sortable ) { ?>
@@ -413,51 +468,55 @@ class SP_Meta_Box_Event_Performance {
<td>
<?php
$selected = (array) sp_array_value( $player_performance, 'position', null );
if ( $selected == null ):
if ( $selected == null ) :
$selected = (array) sp_get_the_term_id( $player_id, 'sp_position', 0 );
endif;
$args = array(
'taxonomy' => 'sp_position',
'name' => 'sp_players[' . $team_id . '][' . $player_id . '][position][]',
'values' => 'term_id',
'orderby' => 'meta_value_num',
'meta_query' => array(
'taxonomy' => 'sp_position',
'name' => 'sp_players[' . $team_id . '][' . $player_id . '][position][]',
'values' => 'term_id',
'orderby' => 'meta_value_num',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'sp_order',
'compare' => 'NOT EXISTS'
'key' => 'sp_order',
'compare' => 'NOT EXISTS',
),
array(
'key' => 'sp_order',
'compare' => 'EXISTS'
'key' => 'sp_order',
'compare' => 'EXISTS',
),
),
'selected' => $selected,
'class' => 'sp-position',
'property' => 'multiple',
'chosen' => true,
'selected' => $selected,
'class' => 'sp-position',
'property' => 'multiple',
'chosen' => true,
'include_children' => ( 'no' == get_option( 'sportspress_event_hide_child_positions', 'no' ) ),
);
sp_dropdown_taxonomies( $args );
?>
</td>
<?php } ?>
<?php foreach( $labels as $column => $label ):
if ( 'equation' === sp_array_value( $formats, $column, 'number' ) ) continue;
$value = sp_array_value( $player_performance, $column, '' );
$intval = intval( $value );
<?php
foreach ( $labels as $column => $label ) :
if ( 'equation' === sp_array_value( $formats, $column, 'number' ) ) {
continue;
}
$value = sp_array_value( $player_performance, $column, '' );
$intval = intval( $value );
$placeholder = sp_get_format_placeholder( sp_array_value( $formats, $column, 'number' ) );
?>
<td>
<?php $format = sp_array_value( $formats, $column, 'number' ); ?>
<?php if ( 'time' === $format ) { ?>
<?php
$intval = intval( $value );
$intval = intval( $value );
$timeval = gmdate( 'i:s', $intval );
$hours = floor( $intval / 3600 );
$hours = floor( $intval / 3600 );
if ( '00' != $hours )
$timeval = $hours . ':' . $timeval;
if ( '00' != $hours ) {
$timeval = $hours . ':' . $timeval;
}
$timeval = preg_replace( '/^0/', '', $timeval );
?>
@@ -479,11 +538,14 @@ class SP_Meta_Box_Event_Performance {
} else {
$times = false;
}
if ( is_array( $times ) ) {
?>
<hr>
<?php for ( $i = 0; $i < $intval; $i++ ) { ?><input class="sp-sync-input small-text" type="text" name="sp_timeline[<?php echo esc_attr( $team_id ); ?>][<?php echo esc_attr( $player_id ); ?>][<?php echo esc_attr( $column ); ?>][<?php echo $i; ?>]" value="<?php echo esc_attr( sp_array_value( $times, $i, '' ) ); ?>" placeholder="-" /><?php } ?>
<?php
for ( $i = 0; $i < $intval; $i++ ) {
?>
<input class="sp-sync-input small-text" type="text" name="sp_timeline[<?php echo esc_attr( $team_id ); ?>][<?php echo esc_attr( $player_id ); ?>][<?php echo esc_attr( $column ); ?>][<?php echo $i; ?>]" value="<?php echo esc_attr( sp_array_value( $times, $i, '' ) ); ?>" placeholder="-" /><?php } ?>
<span class="description"><?php _e( 'mins', 'sportspress' ); ?></span>
<?php
}
@@ -531,17 +593,21 @@ class SP_Meta_Box_Event_Performance {
*/
public static function status_select( $team_id, $player_id, $value = null ) {
if ( ! $team_id || ! $player_id )
if ( ! $team_id || ! $player_id ) {
return '&mdash;';
}
$options = apply_filters( 'sportspress_event_performance_status_options', array(
'lineup' => __( 'Starting Lineup', 'sportspress' ),
'sub' => __( 'Substitute', 'sportspress' ),
) );
$options = apply_filters(
'sportspress_event_performance_status_options',
array(
'lineup' => __( 'Starting Lineup', 'sportspress' ),
'sub' => __( 'Substitute', 'sportspress' ),
)
);
$output = '<select class="sp-sync-select" name="sp_players[' . $team_id . '][' . $player_id . '][status]">';
foreach( $options as $key => $name ):
foreach ( $options as $key => $name ) :
$output .= '<option value="' . $key . '"' . ( $key == $value ? ' selected' : '' ) . '>' . $name . '</option>';
endforeach;
@@ -556,17 +622,20 @@ class SP_Meta_Box_Event_Performance {
*/
public static function sub_select( $team_id, $player_id, $value, $data = array() ) {
if ( ! $team_id || ! $player_id )
if ( ! $team_id || ! $player_id ) {
return '&mdash;';
}
$output = '<select class="sp-sync-select" name="sp_players[' . $team_id . '][' . $player_id . '][sub]" style="display: none;">';
$output .= '<option value="0">' . __( 'None', 'sportspress' ) . '</option>';
// Add players as selectable options
foreach( $data as $id => $performance ):
if ( ! $id || $id == $player_id ) continue;
$number = get_post_meta( $id, 'sp_number', true );
foreach ( $data as $id => $performance ) :
if ( ! $id || $id == $player_id ) {
continue;
}
$number = get_post_meta( $id, 'sp_number', true );
$output .= '<option value="' . $id . '"' . ( $id == $value ? ' selected' : '' ) . '>' . ( $number ? $number . '. ' : '' ) . get_the_title( $id ) . '</option>';
endforeach;

View File

@@ -2,13 +2,15 @@
/**
* Event Results
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Event_Results
@@ -20,12 +22,13 @@ class SP_Meta_Box_Event_Results {
*/
public static function output( $post ) {
// Determine if we need checkboxes
if ( 'manual' == get_option( 'sportspress_event_result_columns', 'auto' ) )
if ( 'manual' == get_option( 'sportspress_event_result_columns', 'auto' ) ) {
$has_checkboxes = true;
else
} else {
$has_checkboxes = false;
}
$event = new SP_Event( $post );
$event = new SP_Event( $post );
list( $columns, $usecolumns, $data ) = $event->results( true );
self::table( $columns, $usecolumns, $data, $has_checkboxes );
}
@@ -34,7 +37,7 @@ class SP_Meta_Box_Event_Results {
* Save meta box data
*/
public static function save( $post_id, $post ) {
$results = (array)sp_array_value( $_POST, 'sp_results', array(), 'text' );
$results = (array) sp_array_value( $_POST, 'sp_results', array(), 'text' );
$main_result = get_option( 'sportspress_primary_result', null );
// Get player performance
@@ -57,15 +60,25 @@ class SP_Meta_Box_Event_Results {
if ( ! $finished ) {
foreach ( $performance as $team => $players ) {
foreach ( $players as $player => $pp ) {
if ( 0 >= $player ) continue;
if ( 0 >= $player ) {
continue;
}
foreach ( $pp as $pk => $pv ) {
if ( in_array( $pk, apply_filters( 'sportspress_event_auto_result_bypass_keys', array( 'number', 'status', 'sub' ) ) ) ) continue;
if ( in_array( $pk, apply_filters( 'sportspress_event_auto_result_bypass_keys', array( 'number', 'status', 'sub' ) ) ) ) {
continue;
}
if ( is_array( $pv ) ) continue;
if ( is_array( $pv ) ) {
continue;
}
$pv = trim( $pv );
if ( '' == $pv ) continue;
if ( ! ctype_digit( $pv ) ) continue;
if ( '' == $pv ) {
continue;
}
if ( ! ctype_digit( $pv ) ) {
continue;
}
$finished = true;
break;
@@ -73,16 +86,16 @@ class SP_Meta_Box_Event_Results {
}
}
}
if ( $finished ) {
// Get results with equations
$args = array(
'post_type' => 'sp_result',
'numberposts' => -1,
$args = array(
'post_type' => 'sp_result',
'numberposts' => -1,
'posts_per_page' => -1,
'meta_query' => array(
'meta_query' => array(
array(
'key' => 'sp_equation',
'key' => 'sp_equation',
'compare' => 'EXISTS',
),
),
@@ -96,25 +109,26 @@ class SP_Meta_Box_Event_Results {
$precision[ $result->post_name ] = (int) get_post_meta( $result->ID, 'sp_precision', true );
}
// Apply equations to empty results
foreach ( $equations as $key => $equation ) {
if ( '' == $equation ) continue;
if ( '' == $equation ) {
continue;
}
foreach ( $results as $team => $team_results ) {
if ( '' === sp_array_value( $team_results, $key, '' ) ) {
$totals = array();
if ( '' === sp_array_value( $team_results, $key, '' ) ) {
$totals = array();
$players = sp_array_value( $performance, $team, array() );
foreach ( $players as $player => $pp ) {
foreach ( $pp as $pk => $pv ) {
$value = sp_array_value( $totals, $pk, 0 );
$value += floatval( $pv );
$value = sp_array_value( $totals, $pk, 0 );
$value += floatval( $pv );
$totals[ $pk ] = $value;
}
}
$totals[ 'eventsplayed' ] = 1;
$totals = apply_filters( 'sportspress_event_result_equation_vars', $totals, $performance, $team );
$results[ $team ][ $key ] = sp_solve( $equation, $totals, sp_array_value( $precision, $key, 0 ), '' );
}
$totals['eventsplayed'] = 1;
$totals = apply_filters( 'sportspress_event_result_equation_vars', $totals, $performance, $team );
$results[ $team ][ $key ] = sp_solve( $equation, $totals, sp_array_value( $precision, $key, 0 ), '' );
}
}
}
}
@@ -138,55 +152,61 @@ class SP_Meta_Box_Event_Results {
if ( count( $primary_results ) && ! in_array( null, $primary_results ) ) {
if ( count( array_unique( $primary_results ) ) === 1 ) {
$args = array(
'post_type' => 'sp_outcome',
'numberposts' => -1,
$args = array(
'post_type' => 'sp_outcome',
'numberposts' => -1,
'posts_per_page' => -1,
'meta_key' => 'sp_condition',
'meta_value' => '=',
'meta_key' => 'sp_condition',
'meta_value' => '=',
);
$outcomes = get_posts( $args );
foreach ( $results as $team => $team_results ) {
if ( array_key_exists( 'outcome', $team_results ) ) continue;
if ( array_key_exists( 'outcome', $team_results ) ) {
continue;
}
if ( $outcomes ) {
$results[ $team ][ 'outcome' ] = array();
$results[ $team ]['outcome'] = array();
foreach ( $outcomes as $outcome ) {
$results[ $team ][ 'outcome' ][] = $outcome->post_name;
$results[ $team ]['outcome'][] = $outcome->post_name;
}
}
}
} else {
// Get default outcomes
$args = array(
'post_type' => 'sp_outcome',
'numberposts' => -1,
$args = array(
'post_type' => 'sp_outcome',
'numberposts' => -1,
'posts_per_page' => -1,
'meta_key' => 'sp_condition',
'meta_value' => 'else',
'meta_key' => 'sp_condition',
'meta_value' => 'else',
);
$default_outcomes = get_posts( $args );
// Get greater than outcomes
$args = array(
'post_type' => 'sp_outcome',
'numberposts' => -1,
$args = array(
'post_type' => 'sp_outcome',
'numberposts' => -1,
'posts_per_page' => -1,
'meta_key' => 'sp_condition',
'meta_value' => '>',
'meta_key' => 'sp_condition',
'meta_value' => '>',
);
$gt_outcomes = get_posts( $args );
if ( empty ( $gt_outcomes ) ) $gt_outcomes = $default_outcomes;
if ( empty( $gt_outcomes ) ) {
$gt_outcomes = $default_outcomes;
}
// Get less than outcomes
$args = array(
'post_type' => 'sp_outcome',
'numberposts' => -1,
$args = array(
'post_type' => 'sp_outcome',
'numberposts' => -1,
'posts_per_page' => -1,
'meta_key' => 'sp_condition',
'meta_value' => '<',
'meta_key' => 'sp_condition',
'meta_value' => '<',
);
$lt_outcomes = get_posts( $args );
if ( empty ( $lt_outcomes ) ) $lt_outcomes = $default_outcomes;
if ( empty( $lt_outcomes ) ) {
$lt_outcomes = $default_outcomes;
}
// Get min and max values
$min = min( $primary_results );
@@ -201,9 +221,9 @@ class SP_Meta_Box_Event_Results {
} else {
$outcomes = $default_outcomes;
}
$results[ $key ][ 'outcome' ] = array();
$results[ $key ]['outcome'] = array();
foreach ( $outcomes as $outcome ) {
$results[ $key ][ 'outcome' ][] = $outcome->post_name;
$results[ $key ]['outcome'][] = $outcome->post_name;
}
}
}
@@ -220,20 +240,20 @@ class SP_Meta_Box_Event_Results {
*/
public static function table( $columns = array(), $usecolumns = array(), $data = array(), $has_checkboxes = false ) {
// Get results with equations
$args = array(
'post_type' => 'sp_result',
'numberposts' => -1,
$args = array(
'post_type' => 'sp_result',
'numberposts' => -1,
'posts_per_page' => -1,
'meta_query' => array(
'meta_query' => array(
array(
'key' => 'sp_equation',
'key' => 'sp_equation',
'compare' => 'NOT IN',
'value' => null
'value' => null,
),
),
);
$dynamic_results = get_posts( $args );
$auto_columns = wp_list_pluck( $dynamic_results, 'post_name' );
$auto_columns = wp_list_pluck( $dynamic_results, 'post_name' );
?>
<div class="sp-data-table-container">
<table class="widefat sp-data-table sp-results-table">
@@ -242,14 +262,14 @@ class SP_Meta_Box_Event_Results {
<th class="column-team">
<?php _e( 'Team', 'sportspress' ); ?>
</th>
<?php foreach ( $columns as $key => $label ): ?>
<?php foreach ( $columns as $key => $label ) : ?>
<th class="column-<?php echo esc_attr( $key ); ?>">
<?php if ( $has_checkboxes ): ?>
<?php if ( $has_checkboxes ) : ?>
<label for="sp_result_columns_<?php echo esc_attr( $key ); ?>">
<input type="checkbox" name="sp_result_columns[]" value="<?php echo esc_attr( $key ); ?>" id="sp_result_columns_<?php echo esc_attr( $key ); ?>" <?php checked( ! is_array( $usecolumns ) || in_array( $key, $usecolumns ) ); ?>>
<?php echo esc_html( $label ); ?>
</label>
<?php else: ?>
<?php else : ?>
<?php echo esc_html( $label ); ?>
<?php endif; ?>
</th>
@@ -262,35 +282,48 @@ class SP_Meta_Box_Event_Results {
<tbody>
<?php
$i = 0;
foreach ( $data as $team_id => $team_results ):
if ( ! $team_id || -1 == $team_id ) continue;
foreach ( $data as $team_id => $team_results ) :
if ( ! $team_id || -1 == $team_id ) {
continue;
}
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>" data-team="<?php echo esc_attr( $team_id ); ?>">
<tr class="sp-row sp-post
<?php
if ( $i % 2 == 0 ) {
echo ' alternate';}
?>
" data-team="<?php echo esc_attr( $team_id ); ?>">
<td>
<?php echo get_the_title( $team_id ); ?>
</td>
<?php foreach( $columns as $column => $label ):
<?php
foreach ( $columns as $column => $label ) :
$value = sp_array_value( $team_results, $column, '' );
?>
<td><input class="sp-team-<?php echo esc_attr( $column ); ?>-input" type="text" name="sp_results[<?php echo esc_attr( $team_id ); ?>][<?php echo esc_attr( $column ); ?>]" value="<?php echo esc_attr( $value ); ?>"<?php if ( in_array( $column, $auto_columns ) ) { ?> placeholder="<?php _e( '(Auto)', 'sportspress' ); ?>"<?php } ?> /></td>
<td><input class="sp-team-<?php echo esc_attr( $column ); ?>-input" type="text" name="sp_results[<?php echo esc_attr( $team_id ); ?>][<?php echo esc_attr( $column ); ?>]" value="<?php echo esc_attr( $value ); ?>"
<?php
if ( in_array( $column, $auto_columns ) ) {
?>
placeholder="<?php _e( '(Auto)', 'sportspress' ); ?>"<?php } ?> /></td>
<?php endforeach; ?>
<td>
<?php
$values = sp_array_value( $team_results, 'outcome', '' );
if ( ! is_array( $values ) )
if ( ! is_array( $values ) ) {
$values = array( $values );
}
$args = array(
'post_type' => 'sp_outcome',
'name' => 'sp_results[' . $team_id . '][outcome][]',
'post_type' => 'sp_outcome',
'name' => 'sp_results[' . $team_id . '][outcome][]',
'option_none_value' => '',
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'selected' => $values,
'class' => 'sp-outcome',
'property' => 'multiple',
'chosen' => true,
'placeholder' => __( '(Auto)', 'sportspress' ),
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'selected' => $values,
'class' => 'sp-outcome',
'property' => 'multiple',
'chosen' => true,
'placeholder' => __( '(Auto)', 'sportspress' ),
);
sp_dropdown_pages( $args );
?>
@@ -305,4 +338,4 @@ class SP_Meta_Box_Event_Results {
</div>
<?php
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Event Shortcode
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Event_Shortcode
@@ -19,27 +21,30 @@ class SP_Meta_Box_Event_Shortcode {
* Output the metabox
*/
public static function output( $post ) {
$shortcodes = apply_filters( 'sportspress_event_shortcodes', array(
'event_results' => __( 'Results', 'sportspress' ),
'event_details' => __( 'Details', 'sportspress' ),
'event_performance' => __( 'Box Score', 'sportspress' ),
'event_venue' => __( 'Venue', 'sportspress' ),
'event_officials' => __( 'Officials', 'sportspress' ),
'event_teams' => __( 'Teams', 'sportspress' ),
'event_full' => __( 'Full Info', 'sportspress' ),
) );
$shortcodes = apply_filters(
'sportspress_event_shortcodes',
array(
'event_results' => __( 'Results', 'sportspress' ),
'event_details' => __( 'Details', 'sportspress' ),
'event_performance' => __( 'Box Score', 'sportspress' ),
'event_venue' => __( 'Venue', 'sportspress' ),
'event_officials' => __( 'Officials', 'sportspress' ),
'event_teams' => __( 'Teams', 'sportspress' ),
'event_full' => __( 'Full Info', 'sportspress' ),
)
);
if ( $shortcodes ) {
?>
?>
<p class="howto">
<?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?>
</p>
<?php foreach ( $shortcodes as $id => $label ) { ?>
<?php foreach ( $shortcodes as $id => $label ) { ?>
<p>
<strong><?php echo esc_html( $label ); ?></strong>
</p>
<p><input type="text" value="<?php sp_shortcode_template( $id, $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
<?php } ?>
<?php
<?php
}
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Event Specs
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Event_Specs
@@ -23,23 +25,23 @@ class SP_Meta_Box_Event_Specs {
$metrics = get_post_meta( $post->ID, 'sp_specs', true );
$args = array(
'post_type' => 'sp_spec',
'numberposts' => -1,
'post_type' => 'sp_spec',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'orderby' => 'menu_order',
'order' => 'ASC',
);
$vars = get_posts( $args );
if ( $vars ):
foreach ( $vars as $var ):
?>
if ( $vars ) :
foreach ( $vars as $var ) :
?>
<p><strong><?php echo esc_html( $var->post_title ); ?></strong></p>
<p><input type="text" name="sp_specs[<?php echo esc_attr( $var->post_name ); ?>]" value="<?php echo esc_attr( sp_array_value( $metrics, $var->post_name, '' ) ); ?>" /></p>
<?php
<?php
endforeach;
else:
else :
sp_post_adder( 'sp_spec', __( 'Add New', 'sportspress' ) );
endif;
}
@@ -50,4 +52,4 @@ class SP_Meta_Box_Event_Specs {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_specs', sp_array_value( $_POST, 'sp_specs', array(), 'text' ) );
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Event Teams
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Event_Teams
@@ -19,32 +21,32 @@ class SP_Meta_Box_Event_Teams {
* Output the metabox
*/
public static function output( $post ) {
$limit = get_option( 'sportspress_event_teams', 2 );
$teams = (array) get_post_meta( $post->ID, 'sp_team', false );
$limit = get_option( 'sportspress_event_teams', 2 );
$teams = (array) get_post_meta( $post->ID, 'sp_team', false );
$post_type = sp_get_post_mode_type( $post->ID );
if ( $limit && 'sp_player' !== $post_type ) {
for ( $i = 0; $i < $limit; $i ++ ):
for ( $i = 0; $i < $limit; $i ++ ) :
$team = array_shift( $teams );
?>
<div class="sp-instance">
<p class="sp-tab-select sp-title-generator">
<?php
$args = array(
'post_type' => $post_type,
'name' => 'sp_team[]',
'class' => 'sportspress-pages',
'post_type' => $post_type,
'name' => 'sp_team[]',
'class' => 'sportspress-pages',
'show_option_none' => __( '&mdash; None &mdash;', 'sportspress' ),
'values' => 'ID',
'selected' => $team,
'chosen' => true,
'tax_query' => array(),
'values' => 'ID',
'selected' => $team,
'chosen' => true,
'tax_query' => array(),
);
if ( 'yes' == get_option( 'sportspress_event_filter_teams_by_league', 'no' ) ) {
$league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 );
if ( $league_id ) {
$args['tax_query'][] = array(
'taxonomy' => 'sp_league',
'terms' => $league_id,
'terms' => $league_id,
);
}
}
@@ -53,7 +55,7 @@ class SP_Meta_Box_Event_Teams {
if ( $season_id ) {
$args['tax_query'][] = array(
'taxonomy' => 'sp_season',
'terms' => $season_id,
'terms' => $season_id,
);
}
}
@@ -64,34 +66,34 @@ class SP_Meta_Box_Event_Teams {
?>
</p>
<?php
$tabs = array();
$tabs = array();
$sections = get_option( 'sportspress_event_performance_sections', -1 );
if ( 0 == $sections ) {
$tabs['sp_offense'] = array(
'label' => __( 'Offense', 'sportspress' ),
'label' => __( 'Offense', 'sportspress' ),
'post_type' => 'sp_player',
);
$tabs['sp_defense'] = array(
'label' => __( 'Defense', 'sportspress' ),
'label' => __( 'Defense', 'sportspress' ),
'post_type' => 'sp_player',
);
} elseif ( 1 == $sections ) {
$tabs['sp_defense'] = array(
'label' => __( 'Defense', 'sportspress' ),
'label' => __( 'Defense', 'sportspress' ),
'post_type' => 'sp_player',
);
$tabs['sp_offense'] = array(
'label' => __( 'Offense', 'sportspress' ),
'label' => __( 'Offense', 'sportspress' ),
'post_type' => 'sp_player',
);
} else {
$tabs['sp_player'] = array(
'label' => __( 'Players', 'sportspress' ),
'label' => __( 'Players', 'sportspress' ),
'post_type' => 'sp_player',
);
}
$tabs['sp_staff'] = array(
'label' => __( 'Staff', 'sportspress' ),
'label' => __( 'Staff', 'sportspress' ),
'post_type' => 'sp_staff',
);
?>
@@ -99,21 +101,25 @@ class SP_Meta_Box_Event_Teams {
<ul id="sp_team-tabs" class="sp-tab-bar category-tabs">
<?php
$j = 0;
foreach ( $tabs as $slug => $tab ) {
?>
<li class="<?php if ( 0 == $j ) { ?>tabs<?php } ?>"><a href="#<?php echo esc_attr( $slug ); ?>-all"><?php echo esc_html( $tab['label'] ); ?></a></li>
foreach ( $tabs as $slug => $tab ) {
?>
<li class="
<?php
if ( 0 == $j ) {
?>
tabs<?php } ?>"><a href="#<?php echo esc_attr( $slug ); ?>-all"><?php echo esc_html( $tab['label'] ); ?></a></li>
<?php
$j++;
}
}
?>
</ul>
<?php
<?php
$j = 0;
foreach ( $tabs as $slug => $tab ) {
do_action( 'sportspress_event_teams_meta_box_checklist', $post->ID, $tab['post_type'], ( 0 == $j ? 'block' : 'none' ), $team, $i, $slug );
$j++;
}
?>
?>
<?php } ?>
</div>
<?php
@@ -123,17 +129,17 @@ class SP_Meta_Box_Event_Teams {
<p><strong><?php printf( __( 'Select %s:', 'sportspress' ), sp_get_post_mode_label( $post->ID ) ); ?></strong></p>
<?php
$args = array(
'post_type' => $post_type,
'name' => 'sp_team[]',
'selected' => $teams,
'values' => 'ID',
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
'post_type' => $post_type,
'name' => 'sp_team[]',
'selected' => $teams,
'values' => 'ID',
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
'placeholder' => __( 'None', 'sportspress' ),
);
if ( ! sp_dropdown_pages( $args ) ):
sp_post_adder( $post_type, __( 'Add New', 'sportspress' ) );
if ( ! sp_dropdown_pages( $args ) ) :
sp_post_adder( $post_type, __( 'Add New', 'sportspress' ) );
endif;
}
wp_nonce_field( 'sp-get-players', 'sp-get-players-nonce', false );
@@ -156,7 +162,7 @@ class SP_Meta_Box_Event_Teams {
}
sp_update_post_meta_recursive( $post_id, 'sp_player', $players );
} else {
$tabs = array();
$tabs = array();
$sections = get_option( 'sportspress_event_performance_sections', -1 );
if ( -1 == $sections ) {
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array(), 'int' ) );

View File

@@ -2,13 +2,15 @@
/**
* Event Video
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Event_Video
@@ -20,8 +22,8 @@ class SP_Meta_Box_Event_Video {
*/
public static function output( $post ) {
$video = get_post_meta( $post->ID, 'sp_video', true );
if ( $video ):
?>
if ( $video ) :
?>
<fieldset class="sp-video-embed">
<?php echo apply_filters( 'the_content', '[embed width="254"]' . $video . '[/embed]' ); ?>
<p><a href="#" class="sp-remove-video"><?php _e( 'Remove video', 'sportspress' ); ?></a></p>
@@ -32,7 +34,11 @@ class SP_Meta_Box_Event_Video {
<p><input class="widefat" type="text" name="sp_video" id="sp_video" value="<?php echo esc_url( $video ); ?>"></p>
<p><a href="#" class="sp-remove-video"><?php _e( 'Cancel', 'sportspress' ); ?></a></p>
</fieldset>
<fieldset class="sp-video-adder<?php if ( $video ): ?> hidden<?php endif; ?>">
<fieldset class="sp-video-adder
<?php
if ( $video ) :
?>
hidden<?php endif; ?>">
<p><a href="#" class="sp-add-video"><?php _e( 'Add video', 'sportspress' ); ?></a></p>
</fieldset>
<?php
@@ -44,4 +50,4 @@ class SP_Meta_Box_Event_Video {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_video', sp_array_value( $_POST, 'sp_video', null, 'text' ) );
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* List Columns
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_List_Columns
@@ -19,8 +21,8 @@ class SP_Meta_Box_List_Columns {
* Output the metabox
*/
public static function output( $post ) {
$selected = (array)get_post_meta( $post->ID, 'sp_columns', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
$selected = (array) get_post_meta( $post->ID, 'sp_columns', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
?>
<p><strong><?php _e( 'General', 'sportspress' ); ?></strong></p>
<ul class="categorychecklist form-no-clear">
@@ -33,7 +35,8 @@ class SP_Meta_Box_List_Columns {
} else {
_e( 'Rank', 'sportspress' );
}
?>
?>
</label>
</li>
<li>
@@ -72,4 +75,4 @@ class SP_Meta_Box_List_Columns {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array(), 'key' ) );
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* List Data
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_List_Data
@@ -21,8 +23,8 @@ class SP_Meta_Box_List_Data {
public static function output( $post ) {
global $pagenow;
if ( is_admin() && in_array( $pagenow, array( 'post-new.php' ) ) && 'sp_list' == get_post_type() ) {
self::table( );
}else{
self::table();
} else {
$list = new SP_Player_List( $post );
list( $columns, $data, $placeholders, $merged, $orderby ) = $list->data( true );
$adjustments = $list->adjustments;
@@ -62,8 +64,11 @@ class SP_Meta_Box_List_Data {
<?php if ( array_key_exists( 'position', $columns ) ) { ?>
<th><?php _e( 'Position', 'sportspress' ); ?></th>
<?php } ?>
<?php foreach ( $columns as $key => $label ): ?>
<?php if ( in_array( $key, array( 'number', 'team', 'position' ) ) ) continue; ?>
<?php foreach ( $columns as $key => $label ) : ?>
<?php
if ( in_array( $key, array( 'number', 'team', 'position' ) ) ) {
continue;}
?>
<th><label for="sp_columns_<?php echo esc_attr( $key ); ?>">
<?php echo esc_html( $label ); ?>
</label></th>
@@ -72,19 +77,27 @@ class SP_Meta_Box_List_Data {
</thead>
<tbody>
<?php
if ( is_array( $data ) && sizeof( $data ) > 0 ):
if ( is_array( $data ) && sizeof( $data ) > 0 ) :
$i = 0;
foreach ( $data as $player_id => $player_stats ):
if ( !$player_id ) continue;
$teams = get_post_meta( $player_id, 'sp_team', false );
$div = get_term( $player_id, 'sp_season' );
foreach ( $data as $player_id => $player_stats ) :
if ( ! $player_id ) {
continue;
}
$teams = get_post_meta( $player_id, 'sp_team', false );
$div = get_term( $player_id, 'sp_season' );
$number = get_post_meta( $player_id, 'sp_number', true );
$default_name = sp_array_value( $player_stats, 'name', '' );
if ( $default_name == null )
if ( $default_name == null ) {
$default_name = get_the_title( $player_id );
}
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<tr class="sp-row sp-post
<?php
if ( $i % 2 == 0 ) {
echo ' alternate';}
?>
">
<?php if ( array_key_exists( 'number', $columns ) ) { ?>
<td>
<?php
@@ -97,7 +110,10 @@ class SP_Meta_Box_List_Data {
</td>
<?php } ?>
<td>
<?php if ( $show_player_photo ) echo get_the_post_thumbnail( $player_id, 'sportspress-fit-mini' ); ?>
<?php
if ( $show_player_photo ) {
echo get_the_post_thumbnail( $player_id, 'sportspress-fit-mini' );}
?>
<span class="sp-default-value">
<span class="sp-default-value-input"><?php echo esc_html( $default_name ); ?></span>
<a class="dashicons dashicons-edit sp-edit" title="<?php _e( 'Edit', 'sportspress' ); ?>"></a>
@@ -112,14 +128,16 @@ class SP_Meta_Box_List_Data {
<td>
<?php
$selected = sp_array_value( $player_stats, 'team', get_post_meta( get_the_ID(), 'sp_team', true ) );
if ( ! $selected ) $selected = get_post_meta( $player_id, 'sp_team', true );
if ( ! $selected ) {
$selected = get_post_meta( $player_id, 'sp_team', true );
}
$include = get_post_meta( $player_id, 'sp_team' );
$args = array(
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_players[' . $player_id . '][team]',
'include' => $include,
'selected' => $selected,
'values' => 'ID',
'name' => 'sp_players[' . $player_id . '][team]',
'include' => $include,
'selected' => $selected,
'values' => 'ID',
);
wp_dropdown_pages( $args );
?>
@@ -129,33 +147,36 @@ class SP_Meta_Box_List_Data {
<td>
<?php
$selected = sp_array_value( $player_stats, 'position', null );
$args = array(
'taxonomy' => 'sp_position',
'name' => 'sp_players[' . $player_id . '][position]',
$args = array(
'taxonomy' => 'sp_position',
'name' => 'sp_players[' . $player_id . '][position]',
'show_option_blank' => __( '(Auto)', 'sportspress' ),
'values' => 'term_id',
'orderby' => 'meta_value_num',
'values' => 'term_id',
'orderby' => 'meta_value_num',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'sp_order',
'compare' => 'NOT EXISTS'
'compare' => 'NOT EXISTS',
),
array(
'key' => 'sp_order',
'compare' => 'EXISTS'
'compare' => 'EXISTS',
),
),
'selected' => $selected,
'selected' => $selected,
'include_children' => ( 'no' == get_option( 'sportspress_event_hide_child_positions', 'no' ) ),
);
sp_dropdown_taxonomies( $args );
?>
</td>
<?php } ?>
<?php foreach( $columns as $column => $label ):
if ( in_array( $column, array( 'number', 'team', 'position' ) ) ) continue;
$value = sp_array_value( $player_stats, $column, '' );
<?php
foreach ( $columns as $column => $label ) :
if ( in_array( $column, array( 'number', 'team', 'position' ) ) ) {
continue;
}
$value = sp_array_value( $player_stats, $column, '' );
$placeholder = sp_array_value( sp_array_value( $placeholders, $player_id, array() ), $column, 0 );
?>
<td><input type="text" name="sp_players[<?php echo esc_attr( $player_id ); ?>][<?php echo esc_attr( $column ); ?>]" value="<?php echo esc_attr( $value ); ?>" placeholder="<?php echo esc_attr( $placeholder ); ?>" data-placeholder="<?php echo esc_attr( $placeholder ); ?>" data-matrix="<?php echo esc_attr( $player_id ); ?>_<?php echo esc_attr( $column ); ?>" data-adjustment="<?php echo esc_attr( sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $column, 0 ) ); ?>" /></td>
@@ -164,14 +185,19 @@ class SP_Meta_Box_List_Data {
<?php
$i++;
endforeach;
else:
?>
else :
?>
<tr class="sp-row alternate">
<td colspan="<?php $colspan = sizeof( $columns ) + ( apply_filters( 'sportspress_has_teams', true ) ? 3 : 2 ); echo esc_attr( $colspan ); ?>">
<td colspan="
<?php
$colspan = sizeof( $columns ) + ( apply_filters( 'sportspress_has_teams', true ) ? 3 : 2 );
echo esc_attr( $colspan );
?>
">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Data', 'sportspress' ) ); ?>
</td>
</tr>
<?php
<?php
endif;
?>
</tbody>
@@ -183,27 +209,41 @@ class SP_Meta_Box_List_Data {
<tr>
<th>#</th>
<th><?php _e( 'Player', 'sportspress' ); ?></th>
<?php foreach ( $columns as $key => $label ): if ( in_array( $key, array( 'number', 'team', 'position' ) ) ) continue; ?>
<?php
foreach ( $columns as $key => $label ) :
if ( in_array( $key, array( 'number', 'team', 'position' ) ) ) {
continue;}
?>
<th><?php echo esc_html( $label ); ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
if ( is_array( $data ) && sizeof( $data ) > 0 ):
if ( is_array( $data ) && sizeof( $data ) > 0 ) :
$i = 0;
foreach ( $data as $player_id => $player_stats ):
if ( !$player_id ) continue;
$div = get_term( $player_id, 'sp_season' );
foreach ( $data as $player_id => $player_stats ) :
if ( ! $player_id ) {
continue;
}
$div = get_term( $player_id, 'sp_season' );
$number = get_post_meta( $player_id, 'sp_number', true );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<tr class="sp-row sp-post
<?php
if ( $i % 2 == 0 ) {
echo ' alternate';}
?>
">
<td><?php echo ( $number ? $number : '&nbsp;' ); ?></td>
<td>
<?php echo get_the_title( $player_id ); ?>
</td>
<?php foreach( $columns as $column => $label ):
if ( in_array( $column, array( 'number', 'team', 'position' ) ) ) continue;
<?php
foreach ( $columns as $column => $label ) :
if ( in_array( $column, array( 'number', 'team', 'position' ) ) ) {
continue;
}
$value = sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $column, '' );
?>
<td><input type="text" name="sp_adjustments[<?php echo esc_attr( $player_id ); ?>][<?php echo esc_attr( $column ); ?>]" value="<?php echo esc_attr( $value ); ?>" placeholder="0" data-matrix="<?php echo esc_attr( $player_id ); ?>_<?php echo esc_attr( $column ); ?>" /></td>
@@ -212,14 +252,19 @@ class SP_Meta_Box_List_Data {
<?php
$i++;
endforeach;
else:
?>
else :
?>
<tr class="sp-row alternate">
<td colspan="<?php $colspan = sizeof( $columns ) + 3; echo esc_attr( $colspan ); ?>">
<td colspan="
<?php
$colspan = sizeof( $columns ) + 3;
echo esc_attr( $colspan );
?>
">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?>
</td>
</tr>
<?php
<?php
endif;
?>
</tbody>
@@ -227,4 +272,4 @@ class SP_Meta_Box_List_Data {
</div>
<?php
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* List Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_List_Details
@@ -19,24 +21,24 @@ class SP_Meta_Box_List_Details {
* Output the metabox
*/
public static function output( $post ) {
$taxonomies = get_object_taxonomies( 'sp_list' );
$caption = get_post_meta( $post->ID, 'sp_caption', true );
$team_id = get_post_meta( $post->ID, 'sp_team', true );
$era = get_post_meta( $post->ID, 'sp_era', true );
$grouping = get_post_meta( $post->ID, 'sp_grouping', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
$order = get_post_meta( $post->ID, 'sp_order', true );
$select = get_post_meta( $post->ID, 'sp_select', true );
$number = get_post_meta( $post->ID, 'sp_number', true );
$crop = get_post_meta( $post->ID, 'sp_crop', true );
$date = get_post_meta( $post->ID, 'sp_date', true );
$date_from = get_post_meta( $post->ID, 'sp_date_from', true );
$date_to = get_post_meta( $post->ID, 'sp_date_to', true );
$date_past = get_post_meta( $post->ID, 'sp_date_past', true );
$date_relative = get_post_meta( $post->ID, 'sp_date_relative', true );
$continents = SP()->countries->continents;
$nationalities = get_post_meta( $post->ID, 'sp_nationality', false );
$default_nationality = get_option( 'sportspress_default_nationality' , false );
$taxonomies = get_object_taxonomies( 'sp_list' );
$caption = get_post_meta( $post->ID, 'sp_caption', true );
$team_id = get_post_meta( $post->ID, 'sp_team', true );
$era = get_post_meta( $post->ID, 'sp_era', true );
$grouping = get_post_meta( $post->ID, 'sp_grouping', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
$order = get_post_meta( $post->ID, 'sp_order', true );
$select = get_post_meta( $post->ID, 'sp_select', true );
$number = get_post_meta( $post->ID, 'sp_number', true );
$crop = get_post_meta( $post->ID, 'sp_crop', true );
$date = get_post_meta( $post->ID, 'sp_date', true );
$date_from = get_post_meta( $post->ID, 'sp_date_from', true );
$date_to = get_post_meta( $post->ID, 'sp_date_to', true );
$date_past = get_post_meta( $post->ID, 'sp_date_past', true );
$date_relative = get_post_meta( $post->ID, 'sp_date_relative', true );
$continents = SP()->countries->continents;
$nationalities = get_post_meta( $post->ID, 'sp_nationality', false );
$default_nationality = get_option( 'sportspress_default_nationality', false );
?>
<div>
<p><strong><?php _e( 'Heading', 'sportspress' ); ?></strong></p>
@@ -47,8 +49,8 @@ class SP_Meta_Box_List_Details {
<p>
<?php
$args = array(
'name' => 'sp_date',
'id' => 'sp_date',
'name' => 'sp_date',
'id' => 'sp_date',
'selected' => $date,
);
sp_dropdown_dates( $args );
@@ -85,13 +87,13 @@ class SP_Meta_Box_List_Details {
<p class="sp-tab-select sp-team-era-selector">
<?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_team',
'post_type' => 'sp_team',
'name' => 'sp_team',
'show_option_all' => __( 'All', 'sportspress' ),
'selected' => $team_id,
'values' => 'ID',
'selected' => $team_id,
'values' => 'ID',
);
if ( ! sp_dropdown_pages( $args ) ):
if ( ! sp_dropdown_pages( $args ) ) :
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
@@ -103,12 +105,16 @@ class SP_Meta_Box_List_Details {
</p>
<p><strong><?php _e( 'Nationality', 'sportspress' ); ?></strong></p>
<p>
<select id="sp_nationality" name="sp_nationality[]" data-placeholder="<?php printf( __( 'Select %s', 'sportspress' ), __( 'Nationality', 'sportspress' ) ); ?>" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>" multiple="multiple">
<select id="sp_nationality" name="sp_nationality[]" data-placeholder="<?php printf( __( 'Select %s', 'sportspress' ), __( 'Nationality', 'sportspress' ) ); ?>" class="widefat chosen-select
<?php
if ( is_rtl() ) :
?>
chosen-rtl<?php endif; ?>" multiple="multiple">
<option value=""></option>
<?php foreach ( $continents as $continent => $countries ): ?>
<?php foreach ( $continents as $continent => $countries ) : ?>
<optgroup label="<?php echo esc_attr( $continent ); ?>">
<?php foreach ( $countries as $code => $country ): ?>
<option value="<?php echo esc_attr( $code ); ?>" <?php selected ( in_array( $code, $nationalities ) ); ?>><?php echo esc_html( $country ); ?></option>
<?php foreach ( $countries as $code => $country ) : ?>
<option value="<?php echo esc_attr( $code ); ?>" <?php selected( in_array( $code, $nationalities ) ); ?>><?php echo esc_html( $country ); ?></option>
<?php endforeach; ?>
</optgroup>
<?php endforeach; ?>
@@ -127,12 +133,12 @@ class SP_Meta_Box_List_Details {
$args = array(
'prepend_options' => array(
'number' => __( 'Squad Number', 'sportspress' ),
'name' => __( 'Name', 'sportspress' ),
'name' => __( 'Name', 'sportspress' ),
),
'post_type' => array( 'sp_performance', 'sp_metric', 'sp_statistic' ),
'name' => 'sp_orderby',
'selected' => $orderby,
'values' => 'slug',
'post_type' => array( 'sp_performance', 'sp_metric', 'sp_statistic' ),
'name' => 'sp_orderby',
'selected' => $orderby,
'values' => 'slug',
);
sp_dropdown_pages( $args );
?>
@@ -160,11 +166,11 @@ class SP_Meta_Box_List_Details {
<?php
if ( 'manual' == $select ) {
$player_filters = array( 'sp_league', 'sp_season' );
if ( $team_id ) {
if ( in_array( $era, [ 'all', 'past' ] ) ) {
if ( $team_id ) {
if ( in_array( $era, array( 'all', 'past' ) ) ) {
$player_filters[] = 'sp_past_team';
}
if ( in_array( $era, [ 'all', 'current' ] ) ) {
if ( in_array( $era, array( 'all', 'current' ) ) ) {
$player_filters[] = 'sp_current_team';
}
}

View File

@@ -2,13 +2,15 @@
/**
* List Format
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_List_Format
@@ -23,7 +25,7 @@ class SP_Meta_Box_List_Format {
$the_format = get_post_meta( $post->ID, 'sp_format', true );
?>
<div id="post-formats-select">
<?php foreach ( SP()->formats->list as $key => $format ): ?>
<?php foreach ( SP()->formats->list as $key => $format ) : ?>
<input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( true, ( $key == 'list' && ! $the_format ) || $the_format == $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $format ); ?></label><br>
<?php endforeach; ?>
</div>
@@ -36,4 +38,4 @@ class SP_Meta_Box_List_Format {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'list', 'key' ) );
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* List Shortcode
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.6.1
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_List_Shortcode
@@ -20,7 +22,9 @@ class SP_Meta_Box_List_Shortcode {
*/
public static function output( $post ) {
$the_format = get_post_meta( $post->ID, 'sp_format', true );
if ( ! $the_format ) $the_format = 'list';
if ( ! $the_format ) {
$the_format = 'list';
}
?>
<p class="howto">
<?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?>
@@ -28,4 +32,4 @@ class SP_Meta_Box_List_Shortcode {
<p><input type="text" value="<?php sp_shortcode_template( 'player_' . $the_format, $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
<?php
}
}
}

View File

@@ -2,16 +2,19 @@
/**
* Metric Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Meta_Box_Config' ) )
include( 'class-sp-meta-box-config.php' );
if ( ! class_exists( 'SP_Meta_Box_Config' ) ) {
require 'class-sp-meta-box-config.php';
}
/**
* SP_Meta_Box_Metric_Details
@@ -24,7 +27,9 @@ class SP_Meta_Box_Metric_Details extends SP_Meta_Box_Config {
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;
if ( '' === $visible ) {
$visible = 1;
}
?>
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
<p>
@@ -59,4 +64,4 @@ class SP_Meta_Box_Metric_Details extends SP_Meta_Box_Config {
self::delete_duplicate( $_POST );
update_post_meta( $post_id, 'sp_visible', sp_array_value( $_POST, 'sp_visible', 1, 'int' ) );
}
}
}

View File

@@ -2,16 +2,19 @@
/**
* Outcome Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Meta_Box_Config' ) )
include( 'class-sp-meta-box-config.php' );
if ( ! class_exists( 'SP_Meta_Box_Config' ) ) {
require 'class-sp-meta-box-config.php';
}
/**
* SP_Meta_Box_Outcome_Details
@@ -30,18 +33,24 @@ class SP_Meta_Box_Outcome_Details extends SP_Meta_Box_Config {
$readonly = false;
}
$abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true );
$color = get_post_meta( $post->ID, 'sp_color', true );
$condition = get_post_meta( $post->ID, 'sp_condition', true );
$main_result = get_option( 'sportspress_primary_result', null );
$result = get_page_by_path( $main_result, ARRAY_A, 'sp_result' );
$label = sp_array_value( $result, 'post_title', __( 'Primary', 'sportspress' ) );
if ( '' === $color ) $color = '#888888';
$color = get_post_meta( $post->ID, 'sp_color', true );
$condition = get_post_meta( $post->ID, 'sp_condition', true );
$main_result = get_option( 'sportspress_primary_result', null );
$result = get_page_by_path( $main_result, ARRAY_A, 'sp_result' );
$label = sp_array_value( $result, 'post_title', __( 'Primary', 'sportspress' ) );
if ( '' === $color ) {
$color = '#888888';
}
?>
<p><strong><?php _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 ); ?>"<?php if ( $readonly ) { ?> readonly="readonly"<?php } ?>>
<input name="sp_key" type="text" id="sp_key" value="<?php echo esc_attr( $post->post_name ); ?>"
<?php
if ( $readonly ) {
?>
readonly="readonly"<?php } ?>>
</p>
<p><strong><?php _e( 'Abbreviation', 'sportspress' ); ?></strong></p>
<p>
@@ -52,21 +61,21 @@ class SP_Meta_Box_Outcome_Details extends SP_Meta_Box_Config {
<div class="sp-color-box">
<input name="sp_color" id="sp_color" type="text" value="<?php echo esc_attr( $color ); ?>" class="colorpick">
<div id="sp_color" class="colorpickdiv"></div>
</div>
</div>
</p>
<p><strong><?php _e( 'Condition', 'sportspress' ); ?></strong></p>
<p>
<select name="sp_condition">
<?php
$options = array(
'0' => '&mdash;',
'>' => sprintf( __( 'Most %s', 'sportspress' ), $label ),
'<' => sprintf( __( 'Least %s', 'sportspress' ), $label ),
'=' => sprintf( __( 'Equal %s', 'sportspress' ), $label ),
'0' => '&mdash;',
'>' => sprintf( __( 'Most %s', 'sportspress' ), $label ),
'<' => sprintf( __( 'Least %s', 'sportspress' ), $label ),
'=' => sprintf( __( 'Equal %s', 'sportspress' ), $label ),
'else' => sprintf( __( 'Default', 'sportspress' ), $label ),
);
foreach ( $options as $key => $value ):
foreach ( $options as $key => $value ) :
printf( '<option value="%s" %s>%s</option>', $key, selected( true, $key == $condition, false ), $value );
endforeach;
?>
@@ -83,4 +92,4 @@ class SP_Meta_Box_Outcome_Details extends SP_Meta_Box_Config {
update_post_meta( $post_id, 'sp_color', sp_array_value( $_POST, 'sp_color', array(), 'text' ) );
update_post_meta( $post_id, 'sp_condition', sp_array_value( $_POST, 'sp_condition', array(), 'text' ) );
}
}
}

View File

@@ -2,16 +2,19 @@
/**
* Performance Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Meta_Box_Config' ) )
include( 'class-sp-meta-box-config.php' );
if ( ! class_exists( 'SP_Meta_Box_Config' ) ) {
require 'class-sp-meta-box-config.php';
}
/**
* SP_Meta_Box_Performance_Details
@@ -29,10 +32,10 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
} else {
$readonly = false;
}
// Post Meta
$singular = get_post_meta( $post->ID, 'sp_singular', true );
$section = get_post_meta( $post->ID, 'sp_section', true );
$section = get_post_meta( $post->ID, 'sp_section', true );
if ( '' === $section ) {
$section = -1;
}
@@ -56,7 +59,11 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
<p><strong><?php _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 ); ?>"<?php if ( $readonly ) { ?> readonly="readonly"<?php } ?>>
<input name="sp_key" type="text" id="sp_key" value="<?php echo esc_attr( $post->post_name ); ?>"
<?php
if ( $readonly ) {
?>
readonly="readonly"<?php } ?>>
</p>
<p><strong><?php _e( 'Singular', 'sportspress' ); ?></strong></p>
<p>
@@ -66,8 +73,18 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
<p class="sp-section-selector">
<select name="sp_section">
<?php
$options = apply_filters( 'sportspress_performance_sections', array( -1 => __( 'All', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
foreach ( $options as $key => $value ):
$options = apply_filters(
'sportspress_performance_sections',
array(
-1 => __( 'All', 'sportspress' ),
0 => __( 'Offense', 'sportspress' ),
1 => __(
'Defense',
'sportspress'
),
)
);
foreach ( $options as $key => $value ) :
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $section, true, false ), $value );
endforeach;
?>
@@ -77,8 +94,20 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
<p class="sp-format-selector">
<select name="sp_format">
<?php
$options = apply_filters( 'sportspress_performance_formats', array( 'number' => __( 'Number', 'sportspress' ), 'time' => __( 'Time', 'sportspress' ), 'text' => __( 'Text', 'sportspress' ), 'equation' => __( 'Equation', 'sportspress' ), 'checkbox' => __( 'Checkbox', 'sportspress' ) ) );
foreach ( $options as $key => $value ):
$options = apply_filters(
'sportspress_performance_formats',
array(
'number' => __( 'Number', 'sportspress' ),
'time' => __( 'Time', 'sportspress' ),
'text' => __( 'Text', 'sportspress' ),
'equation' => __( 'Equation', 'sportspress' ),
'checkbox' => __(
'Checkbox',
'sportspress'
),
)
);
foreach ( $options as $key => $value ) :
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $format, true, false ), $value );
endforeach;
?>
@@ -176,4 +205,4 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
update_post_meta( $post_id, 'sp_visible', sp_array_value( $_POST, 'sp_visible', 1, 'int' ) );
}
}
}
}

View File

@@ -2,16 +2,19 @@
/**
* Performance Equation
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.1.6
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Meta_Box_Equation' ) )
include( 'class-sp-meta-box-equation.php' );
if ( ! class_exists( 'SP_Meta_Box_Equation' ) ) {
require 'class-sp-meta-box-equation.php';
}
/**
* SP_Meta_Box_Performance_Equation
@@ -23,7 +26,7 @@ class SP_Meta_Box_Performance_Equation extends SP_Meta_Box_Equation {
*/
public static function output( $post ) {
$equation = get_post_meta( $post->ID, 'sp_equation', true );
$groups = array( 'performance' );
$groups = array( 'performance' );
self::builder( $post->post_title, $equation, $groups );
}
}

View File

@@ -2,13 +2,15 @@
/**
* Player Columns
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Player_Columns
@@ -20,20 +22,27 @@ class SP_Meta_Box_Player_Columns {
*/
public static function output( $post ) {
$selected = (array) get_post_meta( $post->ID, 'sp_columns', true );
$tabs = apply_filters( 'sportspress_player_column_tabs', array( 'sp_performance', 'sp_statistic' ) );
$tabs = apply_filters( 'sportspress_player_column_tabs', array( 'sp_performance', 'sp_statistic' ) );
?>
<div class="sp-instance">
<?php if ( $tabs ) { ?>
<ul id="sp_column-tabs" class="sp-tab-bar category-tabs">
<?php foreach ( $tabs as $index => $post_type ) { $object = get_post_type_object( $post_type ); ?>
<li class="<?php if ( 0 == $index ) { ?>tabs<?php } ?>"><a href="#<?php echo esc_attr( $post_type ); ?>-all"><?php echo esc_html( $object->labels->menu_name ); ?></a></li>
<?php
foreach ( $tabs as $index => $post_type ) {
$object = get_post_type_object( $post_type );
?>
<li class="
<?php
if ( 0 == $index ) {
?>
tabs<?php } ?>"><a href="#<?php echo esc_attr( $post_type ); ?>-all"><?php echo esc_html( $object->labels->menu_name ); ?></a></li>
<?php } ?>
</ul>
<?php
<?php
foreach ( $tabs as $index => $post_type ) {
sp_column_checklist( $post->ID, $post_type, ( 0 == $index ? 'block' : 'none' ), $selected );
}
?>
?>
<?php } ?>
</div>
<?php
@@ -45,4 +54,4 @@ class SP_Meta_Box_Player_Columns {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array(), 'key' ) );
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Player Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Player_Details
@@ -22,57 +24,62 @@ class SP_Meta_Box_Player_Details {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$continents = SP()->countries->continents;
$number = get_post_meta( $post->ID, 'sp_number', true );
$nationalities = get_post_meta( $post->ID, 'sp_nationality', false );
$default_nationality = get_option( 'sportspress_default_nationality' , false );
if ( empty( $nationalities ) && $default_nationality ) {
$number = get_post_meta( $post->ID, 'sp_number', true );
$nationalities = get_post_meta( $post->ID, 'sp_nationality', false );
$default_nationality = get_option( 'sportspress_default_nationality', false );
if ( empty( $nationalities ) && $default_nationality ) {
if ( $default_nationality != '' ) {
$nationalities[] = $default_nationality;
}
}
foreach ( $nationalities as $index => $nationality ):
if ( 2 == strlen( $nationality ) ):
$legacy = SP()->countries->legacy;
$nationality = strtolower( $nationality );
$nationality = sp_array_value( $legacy, $nationality, null );
foreach ( $nationalities as $index => $nationality ) :
if ( 2 == strlen( $nationality ) ) :
$legacy = SP()->countries->legacy;
$nationality = strtolower( $nationality );
$nationality = sp_array_value( $legacy, $nationality, null );
$nationalities[ $index ] = $nationality;
endif;
endforeach;
if ( taxonomy_exists( 'sp_league' ) ):
$leagues = get_the_terms( $post->ID, 'sp_league' );
if ( taxonomy_exists( 'sp_league' ) ) :
$leagues = get_the_terms( $post->ID, 'sp_league' );
$league_ids = array();
if ( $leagues ):
foreach ( $leagues as $league ):
if ( $leagues ) :
foreach ( $leagues as $league ) :
$league_ids[] = $league->term_id;
endforeach;
endif;
endif;
if ( taxonomy_exists( 'sp_season' ) ):
$seasons = get_the_terms( $post->ID, 'sp_season' );
if ( taxonomy_exists( 'sp_season' ) ) :
$seasons = get_the_terms( $post->ID, 'sp_season' );
$season_ids = array();
if ( $seasons ):
foreach ( $seasons as $season ):
if ( $seasons ) :
foreach ( $seasons as $season ) :
$season_ids[] = $season->term_id;
endforeach;
endif;
endif;
if ( taxonomy_exists( 'sp_position' ) ):
$positions = get_the_terms( $post->ID, 'sp_position' );
if ( taxonomy_exists( 'sp_position' ) ) :
$positions = get_the_terms( $post->ID, 'sp_position' );
$position_ids = array();
if ( $positions ):
foreach ( $positions as $position ):
if ( $positions ) :
foreach ( $positions as $position ) :
$position_ids[] = $position->term_id;
endforeach;
endif;
endif;
$teams = get_posts( array( 'post_type' => 'sp_team', 'posts_per_page' => -1 ) );
$past_teams = array_filter( get_post_meta( $post->ID, 'sp_past_team', false ) );
$teams = get_posts(
array(
'post_type' => 'sp_team',
'posts_per_page' => -1,
)
);
$past_teams = array_filter( get_post_meta( $post->ID, 'sp_past_team', false ) );
$current_teams = array_filter( get_post_meta( $post->ID, 'sp_current_team', false ) );
?>
@@ -80,12 +87,16 @@ class SP_Meta_Box_Player_Details {
<p><input type="text" size="4" id="sp_number" name="sp_number" value="<?php echo esc_attr( $number ); ?>"></p>
<p><strong><?php _e( 'Nationality', 'sportspress' ); ?></strong></p>
<p><select id="sp_nationality" name="sp_nationality[]" data-placeholder="<?php printf( __( 'Select %s', 'sportspress' ), __( 'Nationality', 'sportspress' ) ); ?>" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>" multiple="multiple">
<p><select id="sp_nationality" name="sp_nationality[]" data-placeholder="<?php printf( __( 'Select %s', 'sportspress' ), __( 'Nationality', 'sportspress' ) ); ?>" class="widefat chosen-select
<?php
if ( is_rtl() ) :
?>
chosen-rtl<?php endif; ?>" multiple="multiple">
<option value=""></option>
<?php foreach ( $continents as $continent => $countries ): ?>
<?php foreach ( $continents as $continent => $countries ) : ?>
<optgroup label="<?php echo esc_attr( $continent ); ?>">
<?php foreach ( $countries as $code => $country ): ?>
<option value="<?php echo esc_attr( $code ); ?>" <?php selected ( in_array( $code, $nationalities ) ); ?>><?php echo esc_html( $country ); ?></option>
<?php foreach ( $countries as $code => $country ) : ?>
<option value="<?php echo esc_attr( $code ); ?>" <?php selected( in_array( $code, $nationalities ) ); ?>><?php echo esc_html( $country ); ?></option>
<?php endforeach; ?>
</optgroup>
<?php endforeach; ?>
@@ -93,83 +104,93 @@ class SP_Meta_Box_Player_Details {
<?php if ( taxonomy_exists( 'sp_position' ) ) { ?>
<p><strong><?php _e( 'Positions', 'sportspress' ); ?></strong></p>
<p><?php
<p>
<?php
$args = array(
'taxonomy' => 'sp_position',
'name' => 'tax_input[sp_position][]',
'selected' => $position_ids,
'values' => 'term_id',
'taxonomy' => 'sp_position',
'name' => 'tax_input[sp_position][]',
'selected' => $position_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Positions', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?></p>
?>
</p>
<?php } ?>
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
<p><?php
<p>
<?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_current_team[]',
'selected' => $current_teams,
'values' => 'ID',
'post_type' => 'sp_team',
'name' => 'sp_current_team[]',
'selected' => $current_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-current-teams widefat',
'property' => 'multiple',
'chosen' => true,
'class' => 'sp-current-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?></p>
?>
</p>
<p><strong><?php _e( 'Past Teams', 'sportspress' ); ?></strong></p>
<p><?php
<p>
<?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_past_team[]',
'selected' => $past_teams,
'values' => 'ID',
'post_type' => 'sp_team',
'name' => 'sp_past_team[]',
'selected' => $past_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-past-teams widefat',
'property' => 'multiple',
'chosen' => true,
'class' => 'sp-past-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?></p>
?>
</p>
<?php if ( taxonomy_exists( 'sp_league' ) ) { ?>
<p><strong><?php _e( 'Leagues', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'taxonomy' => 'sp_league',
'name' => 'tax_input[sp_league][]',
'selected' => $league_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?></p>
<p>
<?php
$args = array(
'taxonomy' => 'sp_league',
'name' => 'tax_input[sp_league][]',
'selected' => $league_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?>
</p>
<?php } ?>
<?php if ( taxonomy_exists( 'sp_season' ) ) { ?>
<p><strong><?php _e( 'Seasons', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'taxonomy' => 'sp_season',
'name' => 'tax_input[sp_season][]',
'selected' => $season_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Seasons', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?></p>
<p>
<?php
$args = array(
'taxonomy' => 'sp_season',
'name' => 'tax_input[sp_season][]',
'selected' => $season_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Seasons', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?>
</p>
<?php } ?>
<?php
}

View File

@@ -2,13 +2,15 @@
/**
* Player Metrics
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Player_Metrics
@@ -23,23 +25,23 @@ class SP_Meta_Box_Player_Metrics {
$metrics = get_post_meta( $post->ID, 'sp_metrics', true );
$args = array(
'post_type' => 'sp_metric',
'numberposts' => -1,
'post_type' => 'sp_metric',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'orderby' => 'menu_order',
'order' => 'ASC',
);
$vars = get_posts( $args );
if ( $vars ):
foreach ( $vars as $var ):
?>
if ( $vars ) :
foreach ( $vars as $var ) :
?>
<p><strong><?php echo esc_html( $var->post_title ); ?></strong></p>
<p><input type="text" name="sp_metrics[<?php echo esc_attr( $var->post_name ); ?>]" value="<?php echo esc_attr( sp_array_value( $metrics, $var->post_name, '' ) ); ?>" /></p>
<?php
<?php
endforeach;
else:
else :
sp_post_adder( 'sp_metric', __( 'Add New', 'sportspress' ) );
endif;
}
@@ -50,4 +52,4 @@ class SP_Meta_Box_Player_Metrics {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_metrics', sp_array_value( $_POST, 'sp_metrics', array(), 'text' ) );
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Player Shortcode
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.6.1
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Player_Shortcode
@@ -33,4 +35,4 @@ class SP_Meta_Box_Player_Shortcode {
<p><input type="text" value="<?php sp_shortcode_template( 'player_statistics', $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
<?php
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Player Statistics
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Player_Statistics
@@ -19,21 +21,21 @@ class SP_Meta_Box_Player_Statistics {
* Output the metabox
*/
public static function output( $post ) {
$player = new SP_Player( $post );
$player = new SP_Player( $post );
$leagues = $player->get_terms_sorted_by_sp_order( 'sp_league' );
if ( is_array ( $leagues ) ) {
if ( is_array( $leagues ) ) {
$league_num = sizeof( $leagues );
}else{
$league_num =0;
} else {
$league_num = 0;
}
$sections = get_option( 'sportspress_player_performance_sections', -1 );
$sections = get_option( 'sportspress_player_performance_sections', -1 );
$show_career_totals = 'yes' === get_option( 'sportspress_player_show_career_total', 'no' ) ? true : false;
if ( $leagues ) {
if ( -1 == $sections ) {
// Loop through statistics for each league
$i = 0;
foreach ( $leagues as $league ):
foreach ( $leagues as $league ) :
?>
<p><strong><?php echo esc_html( $league->name ); ?></strong></p>
<?php
@@ -51,16 +53,19 @@ class SP_Meta_Box_Player_Statistics {
} else {
// Determine order of sections
if ( 1 == $sections ) {
$section_order = array( 1 => __( 'Defense', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ) );
$section_order = array(
1 => __( 'Defense', 'sportspress' ),
0 => __( 'Offense', 'sportspress' ),
);
} else {
$section_order = array( __( 'Offense', 'sportspress' ), __( 'Defense', 'sportspress' ) );
}
$s = 0;
foreach ( $section_order as $section_id => $section_label ) {
// Loop through statistics for each league
$i = 0;
foreach ( $leagues as $league ):
foreach ( $leagues as $league ) :
?>
<p><strong><?php echo esc_html( $league->name ); ?> &mdash; <?php echo esc_html( $section_label ); ?></strong></p>
<?php
@@ -94,20 +99,31 @@ class SP_Meta_Box_Player_Statistics {
*/
public static function table( $id = null, $league_id = null, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $has_checkboxes = false, $team_select = false, $formats = array(), $total_types = array() ) {
$readonly = false;
$teams = array_filter( get_post_meta( $id, 'sp_team', false ) );
$buffer = apply_filters( 'sportspress_meta_box_player_statistics_table_buffer', array( 'teams' => $teams, 'readonly' => $readonly ), $id );
$teams = array_filter( get_post_meta( $id, 'sp_team', false ) );
$buffer = apply_filters(
'sportspress_meta_box_player_statistics_table_buffer',
array(
'teams' => $teams,
'readonly' => $readonly,
),
$id
);
?>
<div class="sp-data-table-container">
<table class="widefat sp-data-table sp-player-statistics-table">
<thead>
<tr>
<th><?php _e( 'Season', 'sportspress' ); ?></th>
<?php if ( $team_select && apply_filters( 'sportspress_player_team_statistics', $league_id ) ): ?>
<?php if ( $team_select && apply_filters( 'sportspress_player_team_statistics', $league_id ) ) : ?>
<th>
<?php _e( 'Team', 'sportspress' ); ?>
</th>
<?php endif; ?>
<?php foreach ( $columns as $key => $label ): if ( $key == 'team' ) continue; ?>
<?php
foreach ( $columns as $key => $label ) :
if ( $key == 'team' ) {
continue;}
?>
<th><?php echo esc_html( $label ); ?></th>
<?php endforeach; ?>
<?php do_action( 'sportspress_meta_box_player_statistics_table_header_row', $id, $league_id ); ?>
@@ -122,29 +138,34 @@ class SP_Meta_Box_Player_Statistics {
<?php if ( $team_select && apply_filters( 'sportspress_player_team_statistics', $league_id ) ) { ?>
<td>&nbsp;</td>
<?php } ?>
<?php foreach ( $columns as $column => $label ): if ( $column == 'team' ) continue;
<?php
foreach ( $columns as $column => $label ) :
if ( $column == 'team' ) {
continue;}
?>
<td><?php
$value = sp_array_value( sp_array_value( $data, 0, array() ), $column, null );
<td>
<?php
$value = sp_array_value( sp_array_value( $data, 0, array() ), $column, null );
$placeholder = sp_array_value( sp_array_value( $placeholders, 0, array() ), $column, 0 );
// Convert value and placeholder to time format
if ( 'time' === sp_array_value( $formats, $column, 'number' ) ) {
$timeval = sp_time_value( $value );
$placeholder = sp_time_value( $placeholder );
}
if ( 'time' === sp_array_value( $formats, $column, 'number' ) ) {
$timeval = sp_time_value( $value );
$placeholder = sp_time_value( $placeholder );
}
if ( $readonly ) {
echo $value ? esc_html( $value ) : esc_html( $placeholder );
if ( $readonly ) {
echo $value ? esc_html( $value ) : esc_html( $placeholder );
} else {
if ( 'time' === sp_array_value( $formats, $column, 'number' ) ) {
echo '<input class="sp-convert-time-input" type="text" name="sp_times[' . $league_id . '][0][' . $column . ']" value="' . ( '' === $value ? '' : esc_attr( $timeval ) ) . '" placeholder="' . esc_attr( $placeholder ) . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' />';
echo '<input class="sp-convert-time-output" type="hidden" name="sp_statistics[' . $league_id . '][0][' . $column . ']" value="' . esc_attr( $value ) . '" data-sp-format="' . sp_array_value( $formats, $column, 'number' ) . '" data-sp-total-type="' . sp_array_value( $total_types, $column, 'total' ) . '" />';
} else {
if ( 'time' === sp_array_value( $formats, $column, 'number' ) ) {
echo '<input class="sp-convert-time-input" type="text" name="sp_times[' . $league_id . '][0][' . $column . ']" value="' . ( '' === $value ? '' : esc_attr( $timeval ) ) . '" placeholder="' . esc_attr( $placeholder ) . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' />';
echo '<input class="sp-convert-time-output" type="hidden" name="sp_statistics[' . $league_id . '][0][' . $column . ']" value="' . esc_attr( $value ) . '" data-sp-format="' . sp_array_value( $formats, $column, 'number' ) . '" data-sp-total-type="' . sp_array_value( $total_types, $column, 'total' ) . '" />';
} else {
echo '<input type="text" name="sp_statistics[' . $league_id . '][0][' . $column . ']" value="' . esc_attr( $value ) . '" placeholder="' . esc_attr( $placeholder ) . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' data-sp-format="' . sp_array_value( $formats, $column, 'number' ) . '" data-sp-total-type="' . sp_array_value( $total_types, $column, 'total' ) . '" />';
}
echo '<input type="text" name="sp_statistics[' . $league_id . '][0][' . $column . ']" value="' . esc_attr( $value ) . '" placeholder="' . esc_attr( $placeholder ) . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' data-sp-format="' . sp_array_value( $formats, $column, 'number' ) . '" data-sp-total-type="' . sp_array_value( $total_types, $column, 'total' ) . '" />';
}
?></td>
}
?>
</td>
<?php endforeach; ?>
<?php do_action( 'sportspress_meta_box_player_statistics_table_footer_row', $id, $league_id ); ?>
</tr>
@@ -152,42 +173,54 @@ class SP_Meta_Box_Player_Statistics {
<tbody>
<?php
$i = 0;
foreach ( $data as $div_id => $div_stats ):
if ( $div_id === 'statistics' ) continue;
if ( $div_id === 0 ) continue;
foreach ( $data as $div_id => $div_stats ) :
if ( $div_id === 'statistics' ) {
continue;
}
if ( $div_id === 0 ) {
continue;
}
$div = get_term( $div_id, 'sp_season' );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?> <?php echo implode( ' ', apply_filters( 'sportspress_meta_box_player_statistics_row_classes', array(), $league_id, $div_id ) ); ?>" data-league="<?php echo (int) $league_id; ?>" data-season="<?php echo (int) $div_id; ?>">
<tr class="sp-row sp-post
<?php
if ( $i % 2 == 0 ) {
echo ' alternate';}
?>
<?php echo implode( ' ', apply_filters( 'sportspress_meta_box_player_statistics_row_classes', array(), $league_id, $div_id ) ); ?>" data-league="<?php echo (int) $league_id; ?>" data-season="<?php echo (int) $div_id; ?>">
<td>
<label>
<?php if ( ! apply_filters( 'sportspress_player_team_statistics', $league_id ) ): ?>
<?php if ( ! apply_filters( 'sportspress_player_team_statistics', $league_id ) ) : ?>
<?php $value = sp_array_value( $leagues, $div_id, '-1' ); ?>
<input type="hidden" name="sp_leagues[<?php echo esc_attr( $league_id ); ?>][<?php echo esc_attr( $div_id ); ?>]" value="-1">
<input type="checkbox" name="sp_leagues[<?php echo esc_attr( $league_id ); ?>][<?php echo esc_attr( $div_id ); ?>]" value="1" <?php checked( $value ); ?>>
<?php endif; ?>
<?php
if ( 0 === $div_id ) _e( 'Total', 'sportspress' );
elseif ( 'WP_Error' != get_class( $div ) ) echo apply_filters( 'sportspress_meta_box_player_statistics_season_name', $div->name, $league_id, $div_id, $div_stats );
if ( 0 === $div_id ) {
_e( 'Total', 'sportspress' );
} elseif ( 'WP_Error' != get_class( $div ) ) {
echo apply_filters( 'sportspress_meta_box_player_statistics_season_name', $div->name, $league_id, $div_id, $div_stats );
}
?>
</label>
</td>
<?php if ( $team_select && apply_filters( 'sportspress_player_team_statistics', $league_id ) ): ?>
<?php if ( $div_id == 0 ): ?>
<?php if ( $team_select && apply_filters( 'sportspress_player_team_statistics', $league_id ) ) : ?>
<?php if ( $div_id == 0 ) : ?>
<td>&nbsp;</td>
<?php else: ?>
<?php else : ?>
<td>
<?php $value = sp_array_value( $leagues, $div_id, '-1' ); ?>
<?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_leagues[' . $league_id . '][' . $div_id . ']',
'post_type' => 'sp_team',
'name' => 'sp_leagues[' . $league_id . '][' . $div_id . ']',
'show_option_none' => __( '&mdash; None &mdash;', 'sportspress' ),
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'selected' => $value,
'values' => 'ID',
'include' => $teams,
'tax_query' => array(
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'selected' => $value,
'values' => 'ID',
'include' => $teams,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'sp_league',
@@ -201,7 +234,7 @@ class SP_Meta_Box_Player_Statistics {
),
),
);
if ( ! sp_dropdown_pages( $args ) ):
if ( ! sp_dropdown_pages( $args ) ) :
_e( '&mdash; None &mdash;', 'sportspress' );
endif;
?>
@@ -209,32 +242,47 @@ class SP_Meta_Box_Player_Statistics {
<?php endif; ?>
<?php endif; ?>
<?php
$collection = array( 'columns' => $columns, 'data' => $data, 'placeholders' => $placeholders, 'merged' => $merged, 'seasons_teams' => array(), 'has_checkboxes' => $has_checkboxes, 'formats' => $formats, 'total_types' => $total_types, 'buffer' => $buffer );
$collection = array(
'columns' => $columns,
'data' => $data,
'placeholders' => $placeholders,
'merged' => $merged,
'seasons_teams' => array(),
'has_checkboxes' => $has_checkboxes,
'formats' => $formats,
'total_types' => $total_types,
'buffer' => $buffer,
);
list( $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes, $formats, $total_types, $buffer ) = array_values( apply_filters( 'sportspress_meta_box_player_statistics_collection', $collection, $id, $league_id, $div_id, $value ) );
?>
<?php foreach ( $columns as $column => $label ): if ( $column == 'team' ) continue;
<?php
foreach ( $columns as $column => $label ) :
if ( $column == 'team' ) {
continue;}
?>
<td><?php
$value = sp_array_value( sp_array_value( $data, $div_id, array() ), $column, null );
<td>
<?php
$value = sp_array_value( sp_array_value( $data, $div_id, array() ), $column, null );
$placeholder = sp_array_value( sp_array_value( $placeholders, $div_id, array() ), $column, 0 );
// Convert value and placeholder to time format
if ( 'time' === sp_array_value( $formats, $column, 'number' ) ) {
$timeval = sp_time_value( $value );
$placeholder = sp_time_value( $placeholder );
}
if ( 'time' === sp_array_value( $formats, $column, 'number' ) ) {
$timeval = sp_time_value( $value );
$placeholder = sp_time_value( $placeholder );
}
if ( $readonly ) {
echo $timeval ? esc_html( $timeval ) : esc_html( $placeholder );
if ( $readonly ) {
echo $timeval ? esc_html( $timeval ) : esc_html( $placeholder );
} else {
if ( 'time' === sp_array_value( $formats, $column, 'number' ) ) {
echo '<input class="sp-convert-time-input" type="text" name="sp_times[' . $league_id . '][' . $div_id . '][' . $column . ']" value="' . ( '' === $value ? '' : esc_attr( $timeval ) ) . '" placeholder="' . esc_attr( $placeholder ) . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' data-column="' . $column . '" />';
echo '<input class="sp-convert-time-output" type="hidden" name="sp_statistics[' . $league_id . '][' . $div_id . '][' . $column . ']" value="' . esc_attr( $value ) . '" />';
} else {
if ( 'time' === sp_array_value( $formats, $column, 'number' ) ) {
echo '<input class="sp-convert-time-input" type="text" name="sp_times[' . $league_id . '][' . $div_id . '][' . $column . ']" value="' . ( '' === $value ? '' : esc_attr( $timeval ) ) . '" placeholder="' . esc_attr( $placeholder ) . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' data-column="' . $column . '" />';
echo '<input class="sp-convert-time-output" type="hidden" name="sp_statistics[' . $league_id . '][' . $div_id . '][' . $column . ']" value="' . esc_attr( $value ) . '" />';
} else {
echo '<input type="text" name="sp_statistics[' . $league_id . '][' . $div_id . '][' . $column . ']" value="' . esc_attr( $value ) . '" placeholder="' . esc_attr( $placeholder ) . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' data-column="' . $column . '" />';
}
echo '<input type="text" name="sp_statistics[' . $league_id . '][' . $div_id . '][' . $column . ']" value="' . esc_attr( $value ) . '" placeholder="' . esc_attr( $placeholder ) . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' data-column="' . $column . '" />';
}
?></td>
}
?>
</td>
<?php endforeach; ?>
<?php do_action( 'sportspress_meta_box_player_statistics_table_row', $id, $league_id, $div_id, $team_select, $buffer, $i ); ?>
</tr>

View File

@@ -2,16 +2,19 @@
/**
* Result Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Meta_Box_Config' ) )
include( 'class-sp-meta-box-config.php' );
if ( ! class_exists( 'SP_Meta_Box_Config' ) ) {
require 'class-sp-meta-box-config.php';
}
/**
* SP_Meta_Box_Result_Details
@@ -34,7 +37,11 @@ class SP_Meta_Box_Result_Details extends SP_Meta_Box_Config {
<p><strong><?php _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 ); ?>"<?php if ( $readonly ) { ?> readonly="readonly"<?php } ?>> <span class="description">(for, against)</span>
<input name="sp_key" type="text" id="sp_key" value="<?php echo esc_attr( $post->post_name ); ?>"
<?php
if ( $readonly ) {
?>
readonly="readonly"<?php } ?>> <span class="description">(for, against)</span>
</p>
<p><strong><?php _e( 'Decimal Places', 'sportspress' ); ?></strong></p>
<p class="sp-precision-selector">
@@ -50,4 +57,4 @@ class SP_Meta_Box_Result_Details extends SP_Meta_Box_Config {
self::delete_duplicate( $_POST );
update_post_meta( $post_id, 'sp_precision', (int) sp_array_value( $_POST, 'sp_precision', 1, 'int' ) );
}
}
}

View File

@@ -2,16 +2,19 @@
/**
* Result Equation
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Meta_Box_Equation' ) )
include( 'class-sp-meta-box-equation.php' );
if ( ! class_exists( 'SP_Meta_Box_Equation' ) ) {
require 'class-sp-meta-box-equation.php';
}
/**
* SP_Meta_Box_Result_Equation
@@ -23,7 +26,7 @@ class SP_Meta_Box_Result_Equation extends SP_Meta_Box_Equation {
*/
public static function output( $post ) {
$equation = get_post_meta( $post->ID, 'sp_equation', true );
$groups = array( 'performance' );
$groups = array( 'performance' );
self::builder( $post->post_title, $equation, $groups );
}
}

View File

@@ -2,16 +2,19 @@
/**
* Spec Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Meta_Box_Config' ) )
include( 'class-sp-meta-box-config.php' );
if ( ! class_exists( 'SP_Meta_Box_Config' ) ) {
require 'class-sp-meta-box-config.php';
}
/**
* SP_Meta_Box_Spec_Details
@@ -24,7 +27,9 @@ class SP_Meta_Box_Spec_Details extends SP_Meta_Box_Config {
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;
if ( '' === $visible ) {
$visible = 1;
}
?>
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
<p>
@@ -59,4 +64,4 @@ class SP_Meta_Box_Spec_Details extends SP_Meta_Box_Config {
self::delete_duplicate( $_POST );
update_post_meta( $post_id, 'sp_visible', sp_array_value( $_POST, 'sp_visible', 1, 'int' ) );
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Staff Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Staff_Details
@@ -23,126 +25,145 @@ class SP_Meta_Box_Staff_Details {
$continents = SP()->countries->continents;
$nationalities = get_post_meta( $post->ID, 'sp_nationality', false );
foreach ( $nationalities as $index => $nationality ):
if ( 2 == strlen( $nationality ) ):
$legacy = SP()->countries->legacy;
$nationality = strtolower( $nationality );
$nationality = sp_array_value( $legacy, $nationality, null );
foreach ( $nationalities as $index => $nationality ) :
if ( 2 == strlen( $nationality ) ) :
$legacy = SP()->countries->legacy;
$nationality = strtolower( $nationality );
$nationality = sp_array_value( $legacy, $nationality, null );
$nationalities[ $index ] = $nationality;
endif;
endforeach;
$leagues = get_the_terms( $post->ID, 'sp_league' );
$leagues = get_the_terms( $post->ID, 'sp_league' );
$league_ids = array();
if ( $leagues ):
foreach ( $leagues as $league ):
if ( $leagues ) :
foreach ( $leagues as $league ) :
$league_ids[] = $league->term_id;
endforeach;
endif;
$seasons = get_the_terms( $post->ID, 'sp_season' );
$seasons = get_the_terms( $post->ID, 'sp_season' );
$season_ids = array();
if ( $seasons ):
foreach ( $seasons as $season ):
if ( $seasons ) :
foreach ( $seasons as $season ) :
$season_ids[] = $season->term_id;
endforeach;
endif;
$roles = get_the_terms( $post->ID, 'sp_role' );
$roles = get_the_terms( $post->ID, 'sp_role' );
$role_ids = is_array( $roles ) ? wp_list_pluck( $roles, 'term_id' ) : array();
$teams = get_posts( array( 'post_type' => 'sp_team', 'posts_per_page' => -1 ) );
$past_teams = array_filter( get_post_meta( $post->ID, 'sp_past_team', false ) );
$teams = get_posts(
array(
'post_type' => 'sp_team',
'posts_per_page' => -1,
)
);
$past_teams = array_filter( get_post_meta( $post->ID, 'sp_past_team', false ) );
$current_teams = array_filter( get_post_meta( $post->ID, 'sp_current_team', false ) );
?>
<p><strong><?php _e( 'Jobs', 'sportspress' ); ?></strong></p>
<p><?php
<p>
<?php
$args = array(
'taxonomy' => 'sp_role',
'name' => 'tax_input[sp_role][]',
'selected' => $role_ids,
'values' => 'term_id',
'taxonomy' => 'sp_role',
'name' => 'tax_input[sp_role][]',
'selected' => $role_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Jobs', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
if ( ! sp_dropdown_taxonomies( $args ) ):
sp_taxonomy_adder( 'sp_role', 'sp_staff', __( 'Add New', 'sportspress' ) );
if ( ! sp_dropdown_taxonomies( $args ) ) :
sp_taxonomy_adder( 'sp_role', 'sp_staff', __( 'Add New', 'sportspress' ) );
endif;
?></p>
?>
</p>
<p><strong><?php _e( 'Nationality', 'sportspress' ); ?></strong></p>
<p><select id="sp_nationality" name="sp_nationality[]" data-placeholder="<?php printf( __( 'Select %s', 'sportspress' ), __( 'Nationality', 'sportspress' ) ); ?>" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>" multiple="multiple">
<p><select id="sp_nationality" name="sp_nationality[]" data-placeholder="<?php printf( __( 'Select %s', 'sportspress' ), __( 'Nationality', 'sportspress' ) ); ?>" class="widefat chosen-select
<?php
if ( is_rtl() ) :
?>
chosen-rtl<?php endif; ?>" multiple="multiple">
<option value=""></option>
<?php foreach ( $continents as $continent => $countries ): ?>
<?php foreach ( $continents as $continent => $countries ) : ?>
<optgroup label="<?php echo esc_attr( $continent ); ?>">
<?php foreach ( $countries as $code => $country ): ?>
<option value="<?php echo esc_attr( $code ); ?>" <?php selected ( in_array( $code, $nationalities ) ); ?>><?php echo esc_html( $country ); ?></option>
<?php foreach ( $countries as $code => $country ) : ?>
<option value="<?php echo esc_attr( $code ); ?>" <?php selected( in_array( $code, $nationalities ) ); ?>><?php echo esc_html( $country ); ?></option>
<?php endforeach; ?>
</optgroup>
<?php endforeach; ?>
</select></p>
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
<p><?php
<p>
<?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_current_team[]',
'selected' => $current_teams,
'values' => 'ID',
'post_type' => 'sp_team',
'name' => 'sp_current_team[]',
'selected' => $current_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-current-teams widefat',
'property' => 'multiple',
'chosen' => true,
'class' => 'sp-current-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?></p>
?>
</p>
<p><strong><?php _e( 'Past Teams', 'sportspress' ); ?></strong></p>
<p><?php
<p>
<?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_past_team[]',
'selected' => $past_teams,
'values' => 'ID',
'post_type' => 'sp_team',
'name' => 'sp_past_team[]',
'selected' => $past_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-past-teams widefat',
'property' => 'multiple',
'chosen' => true,
'class' => 'sp-past-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?></p>
?>
</p>
<p><strong><?php _e( 'Leagues', 'sportspress' ); ?></strong></p>
<p><?php
<p>
<?php
$args = array(
'taxonomy' => 'sp_league',
'name' => 'tax_input[sp_league][]',
'selected' => $league_ids,
'values' => 'term_id',
'taxonomy' => 'sp_league',
'name' => 'tax_input[sp_league][]',
'selected' => $league_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?></p>
?>
</p>
<p><strong><?php _e( 'Seasons', 'sportspress' ); ?></strong></p>
<p><?php
<p>
<?php
$args = array(
'taxonomy' => 'sp_season',
'name' => 'tax_input[sp_season][]',
'selected' => $season_ids,
'values' => 'term_id',
'taxonomy' => 'sp_season',
'name' => 'tax_input[sp_season][]',
'selected' => $season_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Seasons', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?></p>
?>
</p>
<?php
}

View File

@@ -2,13 +2,15 @@
/**
* Staff Shortcode
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.5.5
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Staff_Shortcode
@@ -26,4 +28,4 @@ class SP_Meta_Box_Staff_Shortcode {
<p><input type="text" value="<?php sp_shortcode_template( 'staff_profile', $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
<?php
}
}
}

View File

@@ -2,16 +2,19 @@
/**
* Statistic Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Meta_Box_Config' ) )
include( 'class-sp-meta-box-config.php' );
if ( ! class_exists( 'SP_Meta_Box_Config' ) ) {
require 'class-sp-meta-box-config.php';
}
/**
* SP_Meta_Box_Statistic_Details
@@ -24,16 +27,24 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$precision = get_post_meta( $post->ID, 'sp_precision', true );
$section = get_post_meta( $post->ID, 'sp_section', true );
$format = get_post_meta( $post->ID, 'sp_format', true );
$total = get_post_meta( $post->ID, 'sp_type', true );
$visible = get_post_meta( $post->ID, 'sp_visible', true );
$section = get_post_meta( $post->ID, 'sp_section', true );
$format = get_post_meta( $post->ID, 'sp_format', true );
$total = get_post_meta( $post->ID, 'sp_type', true );
$visible = get_post_meta( $post->ID, 'sp_visible', true );
// Defaults
if ( '' === $precision ) $precision = 0;
if ( '' === $section ) $section = -1;
if ( '' === $format ) $format = 'number';
if ( '' === $visible ) $visible = 1;
if ( '' === $precision ) {
$precision = 0;
}
if ( '' === $section ) {
$section = -1;
}
if ( '' === $format ) {
$format = 'number';
}
if ( '' === $visible ) {
$visible = 1;
}
?>
<p><strong><?php _e( 'Key', 'sportspress' ); ?></strong></p>
<p>
@@ -48,8 +59,18 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
<p class="sp-section-selector">
<select name="sp_section">
<?php
$options = apply_filters( 'sportspress_performance_sections', array( -1 => __( 'All', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
foreach ( $options as $key => $value ):
$options = apply_filters(
'sportspress_performance_sections',
array(
-1 => __( 'All', 'sportspress' ),
0 => __( 'Offense', 'sportspress' ),
1 => __(
'Defense',
'sportspress'
),
)
);
foreach ( $options as $key => $value ) :
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $section, true, false ), $value );
endforeach;
?>
@@ -59,8 +80,17 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
<p>
<select name="sp_format">
<?php
$options = apply_filters( 'sportspress_statistic_formats', array( 'number' => __( 'Number', 'sportspress' ), 'time' => __( 'Time', 'sportspress' ) ) );
foreach ( $options as $key => $value ):
$options = apply_filters(
'sportspress_statistic_formats',
array(
'number' => __( 'Number', 'sportspress' ),
'time' => __(
'Time',
'sportspress'
),
)
);
foreach ( $options as $key => $value ) :
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $format, true, false ), $value );
endforeach;
?>
@@ -70,8 +100,17 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
<p>
<select name="sp_type">
<?php
$options = apply_filters( 'sportspress_statistic_total_types', array( 'total' => __( 'Total', 'sportspress' ), 'average' => __( 'Average', 'sportspress' ) ) );
foreach ( $options as $key => $value ):
$options = apply_filters(
'sportspress_statistic_total_types',
array(
'total' => __( 'Total', 'sportspress' ),
'average' => __(
'Average',
'sportspress'
),
)
);
foreach ( $options as $key => $value ) :
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $total, true, false ), $value );
endforeach;
?>
@@ -110,4 +149,4 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
update_post_meta( $post_id, 'sp_visible', sp_array_value( $_POST, 'sp_visible', 1, 'int' ) );
}
}
}

View File

@@ -2,16 +2,19 @@
/**
* Statistic Equation
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Meta_Box_Equation' ) )
include( 'class-sp-meta-box-equation.php' );
if ( ! class_exists( 'SP_Meta_Box_Equation' ) ) {
require 'class-sp-meta-box-equation.php';
}
/**
* SP_Meta_Box_Statistic_Equation
@@ -23,7 +26,7 @@ class SP_Meta_Box_Statistic_Equation extends SP_Meta_Box_Equation {
*/
public static function output( $post ) {
$equation = get_post_meta( $post->ID, 'sp_equation', true );
$groups = array( 'player_event', 'outcome', 'result', 'performance', 'metric' );
$groups = array( 'player_event', 'outcome', 'result', 'performance', 'metric' );
self::builder( $post->post_title, $equation, $groups );
}
}

View File

@@ -2,13 +2,15 @@
/**
* Table Data
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Table_Data
@@ -21,12 +23,12 @@ class SP_Meta_Box_Table_Data {
public static function output( $post ) {
global $pagenow;
if ( is_admin() && in_array( $pagenow, array( 'post-new.php' ) ) && 'sp_table' == get_post_type() ) {
self::table( );
}else{
self::table();
} else {
$table = new SP_League_Table( $post );
list( $columns, $usecolumns, $data, $placeholders, $merged ) = $table->data( true );
$adjustments = $table->adjustments;
$highlight = get_post_meta( $table->ID, 'sp_highlight', true );
$highlight = get_post_meta( $table->ID, 'sp_highlight', true );
self::table( $table->ID, $columns, $usecolumns, $data, $placeholders, $adjustments, $highlight );
}
}
@@ -45,24 +47,39 @@ class SP_Meta_Box_Table_Data {
* Admin edit table
*/
public static function table( $id = 0, $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array(), $highlight = null, $readonly = false ) {
if ( is_array( $usecolumns ) )
if ( is_array( $usecolumns ) ) {
$usecolumns = array_filter( $usecolumns );
}
$mode = sp_get_post_mode( $id );
if ( 'player' === $mode ) {
$show_team_logo = get_option( 'sportspress_list_show_photos', 'no' ) == 'yes' ? true : false;
$icon_class = 'sp-icon-tshirt';
$icon_class = 'sp-icon-tshirt';
} else {
$show_team_logo = get_option( 'sportspress_table_show_logos', 'no' ) == 'yes' ? true : false;
$icon_class = 'sp-icon-shield';
$icon_class = 'sp-icon-shield';
}
?>
<?php if ( $readonly ) { ?>
<p>
<strong><?php echo get_the_title( $id ); ?></strong>
<a class="add-new-h2 sp-add-new-h2" href="<?php echo esc_url( admin_url( add_query_arg( array( 'post' => $id, 'action' => 'edit' ), 'post.php' ) ) ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></a>
<a class="add-new-h2 sp-add-new-h2" href="
<?php
echo esc_url(
admin_url(
add_query_arg(
array(
'post' => $id,
'action' => 'edit',
),
'post.php'
)
)
);
?>
"><?php _e( 'Edit', 'sportspress' ); ?></a>
</p>
<?php } else { ?>
<input type="hidden" name="sp_highlight" value="0">
@@ -80,7 +97,7 @@ class SP_Meta_Box_Table_Data {
<th class="radio"><span class="dashicons <?php echo $icon_class; ?> sp-tip" title="<?php _e( 'Highlight', 'sportspress' ); ?>"></span></th>
<?php } ?>
<th><?php _e( 'Team', 'sportspress' ); ?></th>
<?php foreach ( $columns as $key => $label ): ?>
<?php foreach ( $columns as $key => $label ) : ?>
<th><label for="sp_columns_<?php echo esc_attr( $key ); ?>">
<?php if ( ! $readonly ) { ?>
<input type="checkbox" name="sp_columns[]" value="<?php echo esc_attr( $key ); ?>" id="sp_columns_<?php echo esc_attr( $key ); ?>" <?php checked( ! is_array( $usecolumns ) || in_array( $key, $usecolumns ) ); ?>>
@@ -92,22 +109,32 @@ class SP_Meta_Box_Table_Data {
</thead>
<tbody>
<?php
if ( is_array( $data ) && sizeof( $data ) > 0 ):
if ( is_array( $data ) && sizeof( $data ) > 0 ) :
$i = 0;
foreach ( $data as $team_id => $team_stats ):
if ( !$team_id )
foreach ( $data as $team_id => $team_stats ) :
if ( ! $team_id ) {
continue;
}
$default_name = sp_array_value( $team_stats, 'name', '' );
if ( $default_name == null )
if ( $default_name == null ) {
$default_name = get_the_title( $team_id );
}
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<tr class="sp-row sp-post
<?php
if ( $i % 2 == 0 ) {
echo ' alternate';}
?>
">
<?php if ( ! $readonly ) { ?>
<td><input type="radio" class="sp-radio-toggle" name="sp_highlight" value="<?php echo esc_attr( $team_id ); ?>" <?php checked( $highlight, $team_id ); ?> <?php disabled( $readonly ); ?>></td>
<?php } ?>
<td>
<?php if ( $show_team_logo ) echo get_the_post_thumbnail( $team_id, 'sportspress-fit-mini' ); ?>
<?php
if ( $show_team_logo ) {
echo get_the_post_thumbnail( $team_id, 'sportspress-fit-mini' );}
?>
<?php if ( $readonly ) { ?>
<?php echo esc_html( $default_name ); ?>
<?php } else { ?>
@@ -122,8 +149,9 @@ class SP_Meta_Box_Table_Data {
</span>
<?php } ?>
</td>
<?php foreach( $columns as $column => $label ):
$value = sp_array_value( $team_stats, $column, '' );
<?php
foreach ( $columns as $column => $label ) :
$value = sp_array_value( $team_stats, $column, '' );
$placeholder = sp_array_value( sp_array_value( $placeholders, $team_id, array() ), $column, 0 );
$placeholder = wp_strip_all_tags( $placeholder );
?>
@@ -133,14 +161,19 @@ class SP_Meta_Box_Table_Data {
<?php
$i++;
endforeach;
else:
?>
else :
?>
<tr class="sp-row alternate">
<td colspan="<?php $colspan = sizeof( $columns ) + ( $readonly ? 1 : 2 ); echo $colspan; ?>">
<td colspan="
<?php
$colspan = sizeof( $columns ) + ( $readonly ? 1 : 2 );
echo $colspan;
?>
">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Data', 'sportspress' ) ); ?>
</td>
</tr>
<?php
<?php
endif;
?>
</tbody>
@@ -151,24 +184,31 @@ class SP_Meta_Box_Table_Data {
<thead>
<tr>
<th><?php _e( 'Team', 'sportspress' ); ?></th>
<?php foreach ( $columns as $key => $label ): ?>
<?php foreach ( $columns as $key => $label ) : ?>
<th><?php echo esc_html( $label ); ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
if ( is_array( $data ) && sizeof( $data ) > 0 ):
if ( is_array( $data ) && sizeof( $data ) > 0 ) :
$i = 0;
foreach ( $data as $team_id => $team_stats ):
if ( !$team_id )
foreach ( $data as $team_id => $team_stats ) :
if ( ! $team_id ) {
continue;
}
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<tr class="sp-row sp-post
<?php
if ( $i % 2 == 0 ) {
echo ' alternate';}
?>
">
<td>
<?php echo get_the_title( $team_id ); ?>
</td>
<?php foreach( $columns as $column => $label ):
<?php
foreach ( $columns as $column => $label ) :
$value = sp_array_value( sp_array_value( $adjustments, $team_id, array() ), $column, '' );
?>
<td><input type="text" name="sp_adjustments[<?php echo esc_attr( $team_id ); ?>][<?php echo esc_attr( $column ); ?>]" value="<?php echo esc_attr( $value ); ?>" placeholder="0" data-matrix="<?php echo esc_attr( $team_id ); ?>_<?php echo esc_attr( $column ); ?>" /></td>
@@ -177,14 +217,19 @@ class SP_Meta_Box_Table_Data {
<?php
$i++;
endforeach;
else:
?>
else :
?>
<tr class="sp-row alternate">
<td colspan="<?php $colspan = sizeof( $columns ) + 1; echo $colspan; ?>">
<td colspan="
<?php
$colspan = sizeof( $columns ) + 1;
echo $colspan;
?>
">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Data', 'sportspress' ) ); ?>
</td>
</tr>
<?php
<?php
endif;
?>
</tbody>
@@ -192,4 +237,4 @@ class SP_Meta_Box_Table_Data {
</div>
<?php
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Table Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Table_Details
@@ -20,18 +22,18 @@ class SP_Meta_Box_Table_Details {
*/
public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$taxonomies = get_object_taxonomies( 'sp_table' );
$caption = get_post_meta( $post->ID, 'sp_caption', true );
$select = get_post_meta( $post->ID, 'sp_select', true );
$post_type = sp_get_post_mode_type( $post->ID );
$date = get_post_meta( $post->ID, 'sp_date', true );
$date_from = get_post_meta( $post->ID, 'sp_date_from', true );
$date_to = get_post_meta( $post->ID, 'sp_date_to', true );
$date_past = get_post_meta( $post->ID, 'sp_date_past', true );
$taxonomies = get_object_taxonomies( 'sp_table' );
$caption = get_post_meta( $post->ID, 'sp_caption', true );
$select = get_post_meta( $post->ID, 'sp_select', true );
$post_type = sp_get_post_mode_type( $post->ID );
$date = get_post_meta( $post->ID, 'sp_date', true );
$date_from = get_post_meta( $post->ID, 'sp_date_from', true );
$date_to = get_post_meta( $post->ID, 'sp_date_to', true );
$date_past = get_post_meta( $post->ID, 'sp_date_past', true );
$date_relative = get_post_meta( $post->ID, 'sp_date_relative', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
$order = get_post_meta( $post->ID, 'sp_order', true );
$event_status = get_post_meta( $post->ID, 'sp_event_status', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
$order = get_post_meta( $post->ID, 'sp_order', true );
$event_status = get_post_meta( $post->ID, 'sp_event_status', true );
if ( empty( $event_status ) ) {
$event_status = array( 'publish', 'future' );
}
@@ -45,8 +47,8 @@ class SP_Meta_Box_Table_Details {
<p>
<?php
$args = array(
'name' => 'sp_date',
'id' => 'sp_date',
'name' => 'sp_date',
'id' => 'sp_date',
'selected' => $date,
);
sp_dropdown_dates( $args );
@@ -97,8 +99,8 @@ class SP_Meta_Box_Table_Details {
?>
<p><strong><?php _e( 'Event Status (with results)', 'sportspress' ); ?></strong></p>
<p>
<input type="checkbox" name="sp_event_status[]" value="publish" <?php echo ( in_array( "publish" , $event_status) ) ? 'checked' : false; ?>> Published/Played<br>
<input type="checkbox" name="sp_event_status[]" value="future" <?php echo ( in_array( "future" , $event_status) ) ? 'checked' : false; ?>> Scheduled/Future<br>
<input type="checkbox" name="sp_event_status[]" value="publish" <?php echo ( in_array( 'publish', $event_status ) ) ? 'checked' : false; ?>> Published/Played<br>
<input type="checkbox" name="sp_event_status[]" value="future" <?php echo ( in_array( 'future', $event_status ) ) ? 'checked' : false; ?>> Scheduled/Future<br>
</p>
</div>
<p><strong><?php _e( 'Sort by', 'sportspress' ); ?></strong></p>
@@ -107,12 +109,12 @@ class SP_Meta_Box_Table_Details {
$args = array(
'prepend_options' => array(
'default' => __( 'Default', 'sportspress' ),
'name' => __( 'Name', 'sportspress' ),
'name' => __( 'Name', 'sportspress' ),
),
'post_type' => array( 'sp_column' ),
'name' => 'sp_orderby',
'selected' => $orderby,
'values' => 'slug',
'post_type' => array( 'sp_column' ),
'name' => 'sp_orderby',
'selected' => $orderby,
'values' => 'slug',
);
sp_dropdown_pages( $args );
?>
@@ -148,4 +150,4 @@ class SP_Meta_Box_Table_Details {
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', array(), 'text' ) );
update_post_meta( $post_id, 'sp_event_status', sp_array_value( $_POST, 'sp_event_status', array(), 'key' ) );
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Table Format
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Table_Format
@@ -23,7 +25,7 @@ class SP_Meta_Box_Table_Format {
$the_format = get_post_meta( $post->ID, 'sp_format', true );
?>
<div id="post-formats-select">
<?php foreach ( SP()->formats->table as $key => $format ): ?>
<?php foreach ( SP()->formats->table as $key => $format ) : ?>
<input type="radio" name="sp_format" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( true, ( $key == 'standings' && ! $the_format ) || $the_format == $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $format ); ?></label><br>
<?php endforeach; ?>
</div>
@@ -36,4 +38,4 @@ class SP_Meta_Box_Table_Format {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'standings', 'key' ) );
}
}
}

View File

@@ -5,34 +5,41 @@
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Table_Mode
*/
class SP_Meta_Box_Table_Mode {
/**
* Output the metabox
*/
public static function output( $post ) {
$the_mode = sp_get_post_mode( $post->ID );
?>
<div id="post-formats-select">
<?php foreach ( array( 'team' => __( 'Team vs team', 'sportspress' ), 'player' => __( 'Player vs player', 'sportspress' ) ) as $key => $mode ): ?>
<input type="radio" name="sp_mode" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( $the_mode, $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $mode ); ?></label><br>
<?php endforeach; ?>
</div>
<?php
}
/**
* Output the metabox
*/
public static function output( $post ) {
$the_mode = sp_get_post_mode( $post->ID );
?>
<div id="post-formats-select">
<?php
foreach ( array(
'team' => __( 'Team vs team', 'sportspress' ),
'player' => __( 'Player vs player', 'sportspress' ),
) as $key => $mode ) :
?>
<input type="radio" name="sp_mode" class="post-format" id="post-format-<?php echo esc_attr( $key ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php checked( $the_mode, $key ); ?>> <label for="post-format-<?php echo esc_attr( $key ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $mode ); ?></label><br>
<?php endforeach; ?>
</div>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_mode', sp_array_value( $_POST, 'sp_mode', 'team', 'key' ) );
}
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_mode', sp_array_value( $_POST, 'sp_mode', 'team', 'key' ) );
}
}

View File

@@ -2,13 +2,15 @@
/**
* Table Shortcode
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Table_Shortcode
@@ -20,7 +22,9 @@ class SP_Meta_Box_Table_Shortcode {
*/
public static function output( $post ) {
$the_format = get_post_meta( $post->ID, 'sp_format', true );
if ( ! $the_format ) $the_format = 'standings';
if ( ! $the_format ) {
$the_format = 'standings';
}
?>
<p class="howto">
<?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?>
@@ -28,4 +32,4 @@ class SP_Meta_Box_Table_Shortcode {
<p><input type="text" value="<?php sp_shortcode_template( 'team_' . $the_format, $post->ID ); ?>" readonly="readonly" class="code widefat"></p>
<?php
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Team Columns
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Team_Columns
@@ -19,21 +21,23 @@ class SP_Meta_Box_Team_Columns {
* Output the metabox
*/
public static function output( $post ) {
$team = new SP_Team( $post );
$leagues = get_the_terms( $post->ID, 'sp_league' );
$team = new SP_Team( $post );
$leagues = get_the_terms( $post->ID, 'sp_league' );
$league_num = sizeof( $leagues );
// Loop through columns for each league
if ( $leagues ): foreach ( $leagues as $league ):
if ( $leagues ) :
foreach ( $leagues as $league ) :
$league_id = $league->term_id;
?>
$league_id = $league->term_id;
?>
<p><strong><?php echo esc_html( $league->name ); ?></strong></p>
<?php
list( $columns, $data, $placeholders ) = $team->columns( $league_id );
self::table( $league_id, $columns, $data, $placeholders );
<?php
list( $columns, $data, $placeholders ) = $team->columns( $league_id );
self::table( $league_id, $columns, $data, $placeholders );
endforeach; endif;
endforeach;
endif;
?>
<p><strong><?php _e( 'Total', 'sportspress' ); ?></strong></p>
<?php
@@ -58,7 +62,7 @@ class SP_Meta_Box_Team_Columns {
<thead>
<tr>
<th><?php _e( 'Season', 'sportspress' ); ?></th>
<?php foreach ( $columns as $label ): ?>
<?php foreach ( $columns as $label ) : ?>
<th><?php echo esc_html( $label ); ?></th>
<?php endforeach; ?>
</tr>
@@ -66,10 +70,15 @@ class SP_Meta_Box_Team_Columns {
<tbody>
<?php
$i = 0;
foreach ( $data as $div_id => $div_stats ):
foreach ( $data as $div_id => $div_stats ) :
$div = get_term( $div_id, 'sp_season' );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<tr class="sp-row sp-post
<?php
if ( $i % 2 == 0 ) {
echo ' alternate';}
?>
">
<td>
<label for="sp_leagues_<?php echo esc_attr( $league_id ); ?>_<?php echo esc_attr( $div_id ); ?>">
<?php
@@ -81,14 +90,17 @@ class SP_Meta_Box_Team_Columns {
?>
</label>
</td>
<?php foreach( $columns as $column => $label ):
<?php
foreach ( $columns as $column => $label ) :
$value = sp_array_value( sp_array_value( $data, $div_id, array() ), $column, 0 );
?>
<td><?php
$value = sp_array_value( sp_array_value( $data, $div_id, array() ), $column, null );
<td>
<?php
$value = sp_array_value( sp_array_value( $data, $div_id, array() ), $column, null );
$placeholder = sp_array_value( sp_array_value( $placeholders, $div_id, array() ), $column, 0 );
echo '<input type="text" name="sp_columns[' . $league_id . '][' . $div_id . '][' . $column . ']" value="' . $value . '" placeholder="' . $placeholder . '" />';
?></td>
?>
</td>
<?php endforeach; ?>
</tr>
<?php
@@ -100,4 +112,4 @@ class SP_Meta_Box_Team_Columns {
</div>
<?php
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Team Details
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Team_Details
@@ -21,91 +23,97 @@ class SP_Meta_Box_Team_Details {
public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
if ( taxonomy_exists( 'sp_league' ) ):
$leagues = get_the_terms( $post->ID, 'sp_league' );
if ( taxonomy_exists( 'sp_league' ) ) :
$leagues = get_the_terms( $post->ID, 'sp_league' );
$league_ids = array();
if ( $leagues ):
foreach ( $leagues as $league ):
if ( $leagues ) :
foreach ( $leagues as $league ) :
$league_ids[] = $league->term_id;
endforeach;
endif;
endif;
if ( taxonomy_exists( 'sp_season' ) ):
$seasons = get_the_terms( $post->ID, 'sp_season' );
if ( taxonomy_exists( 'sp_season' ) ) :
$seasons = get_the_terms( $post->ID, 'sp_season' );
$season_ids = array();
if ( $seasons ):
foreach ( $seasons as $season ):
if ( $seasons ) :
foreach ( $seasons as $season ) :
$season_ids[] = $season->term_id;
endforeach;
endif;
endif;
if ( taxonomy_exists( 'sp_venue' ) ):
$venues = get_the_terms( $post->ID, 'sp_venue' );
if ( taxonomy_exists( 'sp_venue' ) ) :
$venues = get_the_terms( $post->ID, 'sp_venue' );
$venue_ids = array();
if ( $venues ):
foreach ( $venues as $venue ):
if ( $venues ) :
foreach ( $venues as $venue ) :
$venue_ids[] = $venue->term_id;
endforeach;
endif;
endif;
$short_name = get_post_meta( $post->ID, 'sp_short_name', true );
$short_name = get_post_meta( $post->ID, 'sp_short_name', true );
$abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true );
$redirect = get_post_meta( $post->ID, 'sp_redirect', true );
$url = get_post_meta( $post->ID, 'sp_url', true );
$redirect = get_post_meta( $post->ID, 'sp_redirect', true );
$url = get_post_meta( $post->ID, 'sp_url', true );
?>
<?php if ( taxonomy_exists( 'sp_league' ) ) { ?>
<p><strong><?php _e( 'Leagues', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'taxonomy' => 'sp_league',
'name' => 'tax_input[sp_league][]',
'selected' => $league_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?></p>
<p>
<?php
$args = array(
'taxonomy' => 'sp_league',
'name' => 'tax_input[sp_league][]',
'selected' => $league_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?>
</p>
<?php } ?>
<?php if ( taxonomy_exists( 'sp_season' ) ) { ?>
<p><strong><?php _e( 'Seasons', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'taxonomy' => 'sp_season',
'name' => 'tax_input[sp_season][]',
'selected' => $season_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Seasons', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?></p>
<p>
<?php
$args = array(
'taxonomy' => 'sp_season',
'name' => 'tax_input[sp_season][]',
'selected' => $season_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Seasons', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?>
</p>
<?php } ?>
<?php if ( taxonomy_exists( 'sp_venue' ) ) { ?>
<p><strong><?php _e( 'Home', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'taxonomy' => 'sp_venue',
'name' => 'tax_input[sp_venue][]',
'selected' => $venue_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Venue', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?></p>
<p>
<?php
$args = array(
'taxonomy' => 'sp_venue',
'name' => 'tax_input[sp_venue][]',
'selected' => $venue_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Venue', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?>
</p>
<?php } ?>
<p><strong><?php _e( 'Site URL', 'sportspress' ); ?></strong></p>

View File

@@ -2,13 +2,15 @@
/**
* Team Player Lists
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Team_Lists
@@ -21,13 +23,13 @@ class SP_Meta_Box_Team_Lists {
public static function output( $post ) {
global $pagenow;
if ( $pagenow != 'post-new.php' ):
if ( $pagenow != 'post-new.php' ) :
$team = new SP_Team( $post );
$team = new SP_Team( $post );
list( $data, $checked ) = $team->lists( true );
self::table( $data, $checked );
else:
else :
printf( __( 'No results found.', 'sportspress' ) );
@@ -70,14 +72,19 @@ class SP_Meta_Box_Team_Lists {
</thead>
<tbody>
<?php
if ( is_array( $data ) ):
if ( sizeof( $data ) > 0 ):
if ( is_array( $data ) ) :
if ( sizeof( $data ) > 0 ) :
$i = 0;
foreach ( $data as $list ):
foreach ( $data as $list ) :
$players = array_filter( get_post_meta( $list->ID, 'sp_player' ) );
$format = get_post_meta( $list->ID, 'sp_format', true );
$format = get_post_meta( $list->ID, 'sp_format', true );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<tr class="sp-row sp-post
<?php
if ( $i % 2 == 0 ) {
echo ' alternate';}
?>
">
<td>
<input type="checkbox" name="sp_list[]" id="sp_list_<?php echo $list->ID; ?>" value="<?php echo $list->ID; ?>" <?php checked( in_array( $list->ID, $checked ) ); ?>>
</td>
@@ -87,14 +94,14 @@ class SP_Meta_Box_Team_Lists {
</a>
</td>
<td><?php echo sizeof( $players ); ?></td>
<td><?php echo get_the_terms ( $list->ID, 'sp_league' ) ? the_terms( $list->ID, 'sp_league' ) : '&mdash;'; ?></td>
<td><?php echo get_the_terms ( $list->ID, 'sp_season' ) ? the_terms( $list->ID, 'sp_season' ) : '&mdash;'; ?></td>
<td><?php echo get_the_terms( $list->ID, 'sp_league' ) ? the_terms( $list->ID, 'sp_league' ) : '&mdash;'; ?></td>
<td><?php echo get_the_terms( $list->ID, 'sp_season' ) ? the_terms( $list->ID, 'sp_season' ) : '&mdash;'; ?></td>
<td><?php echo esc_html( sp_array_value( SP()->formats->list, $format, '&mdash;' ) ); ?></td>
</tr>
<?php
$i++;
endforeach;
else:
else :
?>
<tr class="sp-row alternate">
<td colspan="6">
@@ -103,14 +110,14 @@ class SP_Meta_Box_Team_Lists {
</tr>
<?php
endif;
else:
?>
else :
?>
<tr class="sp-row alternate">
<td colspan="6">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?>
</td>
</tr>
<?php
<?php
endif;
?>
</tbody>
@@ -118,4 +125,4 @@ class SP_Meta_Box_Team_Lists {
</div>
<?php
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Team Player Staff
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Team_Staff
@@ -21,13 +23,13 @@ class SP_Meta_Box_Team_Staff {
public static function output( $post ) {
global $pagenow;
if ( $pagenow != 'post-new.php' ):
if ( $pagenow != 'post-new.php' ) :
$team = new SP_Team( $post );
$team = new SP_Team( $post );
list( $data, $checked ) = $team->staff( true );
self::table( $data, $checked );
else:
else :
printf( __( 'No results found.', 'sportspress' ) );
@@ -67,13 +69,18 @@ class SP_Meta_Box_Team_Staff {
</thead>
<tbody>
<?php
if ( is_array( $data ) ):
if ( sizeof( $data ) > 0 ):
if ( is_array( $data ) ) :
if ( sizeof( $data ) > 0 ) :
$i = 0;
foreach ( $data as $staff ):
foreach ( $data as $staff ) :
$role = get_post_meta( $staff->ID, 'sp_role', true );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<tr class="sp-row sp-post
<?php
if ( $i % 2 == 0 ) {
echo ' alternate';}
?>
">
<td>
<input type="checkbox" name="sp_staff[]" id="sp_staff_<?php echo $staff->ID; ?>" value="<?php echo $staff->ID; ?>" <?php checked( in_array( $staff->ID, $checked ) ); ?>>
</td>
@@ -82,14 +89,14 @@ class SP_Meta_Box_Team_Staff {
<?php echo esc_html( $staff->post_title ); ?>
</a>
</td>
<td><?php echo get_the_terms ( $staff->ID, 'sp_role' ) ? the_terms( $staff->ID, 'sp_role' ) : '&mdash;'; ?></td>
<td><?php echo get_the_terms ( $staff->ID, 'sp_league' ) ? the_terms( $staff->ID, 'sp_league' ) : '&mdash;'; ?></td>
<td><?php echo get_the_terms ( $staff->ID, 'sp_season' ) ? the_terms( $staff->ID, 'sp_season' ) : '&mdash;'; ?></td>
<td><?php echo get_the_terms( $staff->ID, 'sp_role' ) ? the_terms( $staff->ID, 'sp_role' ) : '&mdash;'; ?></td>
<td><?php echo get_the_terms( $staff->ID, 'sp_league' ) ? the_terms( $staff->ID, 'sp_league' ) : '&mdash;'; ?></td>
<td><?php echo get_the_terms( $staff->ID, 'sp_season' ) ? the_terms( $staff->ID, 'sp_season' ) : '&mdash;'; ?></td>
</tr>
<?php
$i++;
endforeach;
else:
else :
?>
<tr class="sp-row alternate">
<td colspan="5">
@@ -98,14 +105,14 @@ class SP_Meta_Box_Team_Staff {
</tr>
<?php
endif;
else:
?>
else :
?>
<tr class="sp-row alternate">
<td colspan="5">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?>
</td>
</tr>
<?php
<?php
endif;
?>
</tbody>
@@ -113,4 +120,4 @@ class SP_Meta_Box_Team_Staff {
</div>
<?php
}
}
}

View File

@@ -2,13 +2,15 @@
/**
* Team League Tables
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* SP_Meta_Box_Team_Tables
@@ -21,13 +23,13 @@ class SP_Meta_Box_Team_Tables {
public static function output( $post ) {
global $pagenow;
if ( $pagenow != 'post-new.php' ):
if ( $pagenow != 'post-new.php' ) :
$team = new SP_Team( $post );
$team = new SP_Team( $post );
list( $data, $checked ) = $team->tables( true );
self::table( $data, $checked );
else:
else :
printf( __( 'No results found.', 'sportspress' ) );
@@ -67,14 +69,19 @@ class SP_Meta_Box_Team_Tables {
</thead>
<tbody>
<?php
if ( is_array( $data ) ):
if ( sizeof( $data ) > 0 ):
if ( is_array( $data ) ) :
if ( sizeof( $data ) > 0 ) :
$i = 0;
foreach ( $data as $table ):
$teams = array_filter( get_post_meta( $table->ID, 'sp_team' ) );
foreach ( $data as $table ) :
$teams = array_filter( get_post_meta( $table->ID, 'sp_team' ) );
$format = get_post_meta( $table->ID, 'sp_format', true );
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<tr class="sp-row sp-post
<?php
if ( $i % 2 == 0 ) {
echo ' alternate';}
?>
">
<td>
<input type="checkbox" name="sp_table[]" id="sp_table_<?php echo $table->ID; ?>" value="<?php echo $table->ID; ?>" <?php checked( in_array( $table->ID, $checked ) ); ?>>
</td>
@@ -84,13 +91,13 @@ class SP_Meta_Box_Team_Tables {
</a>
</td>
<td><?php echo sizeof( $teams ); ?></td>
<td><?php echo get_the_terms ( $table->ID, 'sp_league' ) ? the_terms( $table->ID, 'sp_league' ) : '&mdash;'; ?></td>
<td><?php echo get_the_terms ( $table->ID, 'sp_season' ) ? the_terms( $table->ID, 'sp_season' ) : '&mdash;'; ?></td>
<td><?php echo get_the_terms( $table->ID, 'sp_league' ) ? the_terms( $table->ID, 'sp_league' ) : '&mdash;'; ?></td>
<td><?php echo get_the_terms( $table->ID, 'sp_season' ) ? the_terms( $table->ID, 'sp_season' ) : '&mdash;'; ?></td>
</tr>
<?php
$i++;
endforeach;
else:
else :
?>
<tr class="sp-row alternate">
<td colspan="6">
@@ -99,14 +106,14 @@ class SP_Meta_Box_Team_Tables {
</tr>
<?php
endif;
else:
?>
else :
?>
<tr class="sp-row alternate">
<td colspan="5">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?>
</td>
</tr>
<?php
<?php
endif;
?>
</tbody>
@@ -114,4 +121,4 @@ class SP_Meta_Box_Team_Tables {
</div>
<?php
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -2,360 +2,400 @@
/**
* SportsPress General Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Settings_General' ) ) :
/**
* SP_Settings_General
*/
class SP_Settings_General extends SP_Settings_Page {
/**
* Constructor
* SP_Settings_General
*/
public function __construct() {
$this->id = 'general';
$this->label = __( 'General', 'sportspress' );
class SP_Settings_General extends SP_Settings_Page {
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_admin_field_timezone', array( $this, 'timezone_setting' ) );
add_action( 'sportspress_admin_field_colors', array( $this, 'colors_setting' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Constructor
*/
public function __construct() {
$this->id = 'general';
$this->label = __( 'General', 'sportspress' );
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
$presets = SP_Admin_Sports::get_preset_options();
$leagues = array( '' => __( '&mdash; Select &mdash;', 'sportspress' ) );
$terms = get_terms( array(
'taxonomy' => 'sp_league',
'hide_empty' => false,
) );
if ( $terms ) {
foreach ( $terms as $term ) {
$leagues[ $term->term_id ] = $term->name;
}
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_admin_field_timezone', array( $this, 'timezone_setting' ) );
add_action( 'sportspress_admin_field_colors', array( $this, 'colors_setting' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
$seasons = array( '' => __( '&mdash; Select &mdash;', 'sportspress' ) );
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
$terms = get_terms( array(
'taxonomy' => 'sp_season',
'hide_empty' => false,
) );
$presets = SP_Admin_Sports::get_preset_options();
if ( $terms ) {
foreach ( $terms as $term ) {
$seasons[ $term->term_id ] = $term->name;
$leagues = array( '' => __( '&mdash; Select &mdash;', 'sportspress' ) );
$terms = get_terms(
array(
'taxonomy' => 'sp_league',
'hide_empty' => false,
)
);
if ( $terms ) {
foreach ( $terms as $term ) {
$leagues[ $term->term_id ] = $term->name;
}
}
}
$settings = array_merge(
array(
array( 'title' => __( 'General Options', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ),
),
apply_filters( 'sportspress_general_options', array(
array( 'type' => 'timezone' ),
$seasons = array( '' => __( '&mdash; Select &mdash;', 'sportspress' ) );
$terms = get_terms(
array(
'title' => __( 'Sport', 'sportspress' ),
'id' => 'sportspress_sport',
'default' => 'none',
'type' => 'sport',
'options' => $presets,
),
'taxonomy' => 'sp_season',
'hide_empty' => false,
)
);
if ( $terms ) {
foreach ( $terms as $term ) {
$seasons[ $term->term_id ] = $term->name;
}
}
$settings = array_merge(
array(
'title' => __( 'Main League', 'sportspress' ),
'id' => 'sportspress_league',
'default' => null,
'type' => 'select',
'options' => $leagues,
),
array(
'title' => __( 'Current Season', 'sportspress' ),
'id' => 'sportspress_season',
'default' => null,
'type' => 'select',
'options' => $seasons,
),
)),
array(
array( 'type' => 'sectionend', 'id' => 'general_options' ),
array( 'title' => __( 'Styles and Scripts', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'script_styling_options' ),
)
);
$options = array(
array( 'type' => 'colors' ),
);
if ( ( $styles = SP_Frontend_Scripts::get_styles() ) && array_key_exists( 'sportspress-general', $styles ) ):
$options = array_merge( $options, array(
array(
'title' => __( 'Align', 'sportspress' ),
'id' => 'sportspress_table_text_align',
'default' => 'default',
'type' => 'radio',
'options' => array(
'default' => __( 'Default', 'sportspress' ),
'left' => __( 'Left', 'sportspress' ),
'center' => __( 'Center', 'sportspress' ),
'right' => __( 'Right', 'sportspress' ),
array(
'title' => __( 'General Options', 'sportspress' ),
'type' => 'title',
'desc' => '',
'id' => 'general_options',
),
),
apply_filters(
'sportspress_general_options',
array(
array( 'type' => 'timezone' ),
array(
'title' => __( 'Sport', 'sportspress' ),
'id' => 'sportspress_sport',
'default' => 'none',
'type' => 'sport',
'options' => $presets,
),
array(
'title' => __( 'Main League', 'sportspress' ),
'id' => 'sportspress_league',
'default' => null,
'type' => 'select',
'options' => $leagues,
),
array(
'title' => __( 'Current Season', 'sportspress' ),
'id' => 'sportspress_season',
'default' => null,
'type' => 'select',
'options' => $seasons,
),
)
),
array(
'title' => __( 'Padding', 'sportspress' ),
'id' => 'sportspress_table_padding',
'class' => 'small-text',
'default' => null,
'placeholder' => __( 'Auto', 'sportspress' ),
'desc' => 'px',
'type' => 'number',
array(
'type' => 'sectionend',
'id' => 'general_options',
),
array(
'title' => __( 'Styles and Scripts', 'sportspress' ),
'type' => 'title',
'desc' => '',
'id' => 'script_styling_options',
),
)
);
$options = array(
array( 'type' => 'colors' ),
);
if ( ( $styles = SP_Frontend_Scripts::get_styles() ) && array_key_exists( 'sportspress-general', $styles ) ) :
$options = array_merge(
$options,
array(
array(
'title' => __( 'Align', 'sportspress' ),
'id' => 'sportspress_table_text_align',
'default' => 'default',
'type' => 'radio',
'options' => array(
'default' => __( 'Default', 'sportspress' ),
'left' => __( 'Left', 'sportspress' ),
'center' => __( 'Center', 'sportspress' ),
'right' => __( 'Right', 'sportspress' ),
),
),
array(
'title' => __( 'Padding', 'sportspress' ),
'id' => 'sportspress_table_padding',
'class' => 'small-text',
'default' => null,
'placeholder' => __( 'Auto', 'sportspress' ),
'desc' => 'px',
'type' => 'number',
'custom_attributes' => array(
'step' => 1,
),
),
)
);
endif;
$options = array_merge(
$options,
array(
array(
'title' => __( 'Custom CSS', 'sportspress' ),
'id' => 'sportspress_custom_css',
'css' => 'width:100%; height: 130px;',
'type' => 'textarea',
),
),
apply_filters(
'sportspress_general_script_options',
array(
array(
'title' => __( 'Scripts', 'sportspress' ),
'desc' => __( 'Live countdowns', 'sportspress' ),
'id' => 'sportspress_enable_live_countdowns',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'desc_tip' => __( 'This will enable a script allowing the countdowns to be animated.', 'sportspress' ),
),
array(
'desc' => __( 'Shortcode menu', 'sportspress' ),
'id' => 'sportspress_rich_editing',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'desc_tip' => __( 'This will enable a shortcode menu to be displayed in the visual editor.', 'sportspress' ),
),
)
),
array(
array(
'title' => __( 'Tables', 'sportspress' ),
'desc' => __( 'Responsive', 'sportspress' ),
'id' => 'sportspress_enable_responsive_tables',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Scrollable', 'sportspress' ),
'id' => 'sportspress_enable_scrollable_tables',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Sortable', 'sportspress' ),
'id' => 'sportspress_enable_sortable_tables',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'title' => __( 'Widgets', 'sportspress' ),
'desc' => __( 'Unique', 'sportspress' ),
'id' => 'sportspress_widget_unique',
'default' => 'no',
'type' => 'checkbox',
'desc_tip' => __( 'Hide widget when same as content.', 'sportspress' ),
),
)
);
if ( apply_filters( 'sportspress_enable_header', false ) ) {
$options[] = array(
'title' => __( 'Header Offset', 'sportspress' ),
'id' => 'sportspress_header_offset',
'class' => 'small-text',
'default' => null,
'placeholder' => __( 'Auto', 'sportspress' ),
'desc' => 'px',
'type' => 'number',
'custom_attributes' => array(
'step' => 1
'step' => 1,
),
),
));
endif;
$options = array_merge( $options,
array(
array(
'title' => __( 'Custom CSS', 'sportspress' ),
'id' => 'sportspress_custom_css',
'css' => 'width:100%; height: 130px;',
'type' => 'textarea',
),
),
apply_filters( 'sportspress_general_script_options', array(
array(
'title' => __( 'Scripts', 'sportspress' ),
'desc' => __( 'Live countdowns', 'sportspress' ),
'id' => 'sportspress_enable_live_countdowns',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
'desc_tip' => __( 'This will enable a script allowing the countdowns to be animated.', 'sportspress' ),
),
array(
'desc' => __( 'Shortcode menu', 'sportspress' ),
'id' => 'sportspress_rich_editing',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'desc_tip' => __( 'This will enable a shortcode menu to be displayed in the visual editor.', 'sportspress' ),
),
) ),
array(
array(
'title' => __( 'Tables', 'sportspress' ),
'desc' => __( 'Responsive', 'sportspress' ),
'id' => 'sportspress_enable_responsive_tables',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Scrollable', 'sportspress' ),
'id' => 'sportspress_enable_scrollable_tables',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Sortable', 'sportspress' ),
'id' => 'sportspress_enable_sortable_tables',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'title' => __( 'Widgets', 'sportspress' ),
'desc' => __( 'Unique', 'sportspress' ),
'id' => 'sportspress_widget_unique',
'default' => 'no',
'type' => 'checkbox',
'desc_tip' => __( 'Hide widget when same as content.', 'sportspress' ),
),
) );
if ( apply_filters( 'sportspress_enable_header', false ) ) {
$options[] = array(
'title' => __( 'Header Offset', 'sportspress' ),
'id' => 'sportspress_header_offset',
'class' => 'small-text',
'default' => null,
'placeholder' => __( 'Auto', 'sportspress' ),
'desc' => 'px',
'type' => 'number',
'custom_attributes' => array(
'step' => 1
),
);
}
$settings = array_merge( $settings, apply_filters( 'sportspress_script_styling_options', $options ), array(
array( 'type' => 'sectionend', 'id' => 'script_styling_options' ),
));
return apply_filters( 'sportspress_general_settings', $settings ); // End general settings
}
/**
* Save settings
*/
public function save() {
if ( isset( $_POST['sportspress_sport'] ) && ! empty( $_POST['sportspress_sport'] ) && get_option( 'sportspress_sport', null ) !== $_POST['sportspress_sport'] ):
$sport = sanitize_key( $_POST['sportspress_sport'] );
SP_Admin_Sports::apply_preset( $sport );
delete_option( '_sp_needs_welcome' );
update_option( 'sportspress_installed', 1 );
endif;
if ( isset( $_POST['add_sample_data'] ) ):
SP_Admin_Sample_Data::delete_posts();
SP_Admin_Sample_Data::insert_posts();
endif;
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
// Map UTC+- timezones to gmt_offsets and set timezone_string to empty.
if ( ! empty( $_POST['timezone_string'] ) && preg_match( '/^UTC[+-]/', $_POST['timezone_string'] ) ) {
$_POST['gmt_offset'] = preg_replace( '/UTC\+?/', '', sanitize_text_field( $_POST['timezone_string'] ) );
$_POST['timezone_string'] = '';
}
if ( isset( $_POST['timezone_string'] ) )
update_option( 'timezone_string', sanitize_option( 'timezone_string', $_POST['timezone_string'] ) );
if ( isset( $_POST['gmt_offset'] ) )
update_option( 'gmt_offset', sanitize_option( 'gmt_offset', $_POST['gmt_offset'] ) );
if ( isset( $_POST['sportspress_frontend_css_primary'] ) ) {
// Save settings
$primary = ( ! empty( $_POST['sportspress_frontend_css_primary'] ) ) ? sp_format_hex( $_POST['sportspress_frontend_css_primary'] ) : '';
$background = ( ! empty( $_POST['sportspress_frontend_css_background'] ) ) ? sp_format_hex( $_POST['sportspress_frontend_css_background'] ) : '';
$text = ( ! empty( $_POST['sportspress_frontend_css_text'] ) ) ? sp_format_hex( $_POST['sportspress_frontend_css_text'] ) : '';
$heading = ( ! empty( $_POST['sportspress_frontend_css_heading'] ) ) ? sp_format_hex( $_POST['sportspress_frontend_css_heading'] ) : '';
$link = ( ! empty( $_POST['sportspress_frontend_css_link'] ) ) ? sp_format_hex( $_POST['sportspress_frontend_css_link'] ) : '';
$customize = ( ! empty( $_POST['sportspress_frontend_css_customize'] ) ) ? 1 : '';
$colors = array(
'primary' => $primary,
'background' => $background,
'text' => $text,
'heading' => $heading,
'link' => $link,
'customize' => $customize,
);
// Merge with existing options if available
$options = get_option( 'themeboy' );
if ( is_array( $options ) ) {
$colors = array_merge( $options, $colors );
);
}
update_option( 'themeboy', $colors );
$settings = array_merge(
$settings,
apply_filters( 'sportspress_script_styling_options', $options ),
array(
array(
'type' => 'sectionend',
'id' => 'script_styling_options',
),
)
);
return apply_filters( 'sportspress_general_settings', $settings ); // End general settings
}
}
/**
* Timezone settings
*
* @access public
* @return void
*/
public function timezone_setting() {
$current_offset = get_option( 'gmt_offset' );
$tzstring = get_option( 'timezone_string' );
/**
* Save settings
*/
public function save() {
if ( isset( $_POST['sportspress_sport'] ) && ! empty( $_POST['sportspress_sport'] ) && get_option( 'sportspress_sport', null ) !== $_POST['sportspress_sport'] ) :
$sport = sanitize_key( $_POST['sportspress_sport'] );
SP_Admin_Sports::apply_preset( $sport );
delete_option( '_sp_needs_welcome' );
update_option( 'sportspress_installed', 1 );
endif;
$check_zone_info = true;
if ( isset( $_POST['add_sample_data'] ) ) :
SP_Admin_Sample_Data::delete_posts();
SP_Admin_Sample_Data::insert_posts();
endif;
// Remove old Etc mappings. Fallback to gmt_offset.
if ( false !== strpos( $tzstring,'Etc/GMT' ) )
$tzstring = '';
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists
$check_zone_info = false;
if ( 0 == $current_offset )
$tzstring = 'UTC+0';
elseif ($current_offset < 0)
$tzstring = 'UTC' . $current_offset;
else
$tzstring = 'UTC+' . $current_offset;
// Map UTC+- timezones to gmt_offsets and set timezone_string to empty.
if ( ! empty( $_POST['timezone_string'] ) && preg_match( '/^UTC[+-]/', $_POST['timezone_string'] ) ) {
$_POST['gmt_offset'] = preg_replace( '/UTC\+?/', '', sanitize_text_field( $_POST['timezone_string'] ) );
$_POST['timezone_string'] = '';
}
if ( isset( $_POST['timezone_string'] ) ) {
update_option( 'timezone_string', sanitize_option( 'timezone_string', $_POST['timezone_string'] ) );
}
if ( isset( $_POST['gmt_offset'] ) ) {
update_option( 'gmt_offset', sanitize_option( 'gmt_offset', $_POST['gmt_offset'] ) );
}
if ( isset( $_POST['sportspress_frontend_css_primary'] ) ) {
// Save settings
$primary = ( ! empty( $_POST['sportspress_frontend_css_primary'] ) ) ? sp_format_hex( $_POST['sportspress_frontend_css_primary'] ) : '';
$background = ( ! empty( $_POST['sportspress_frontend_css_background'] ) ) ? sp_format_hex( $_POST['sportspress_frontend_css_background'] ) : '';
$text = ( ! empty( $_POST['sportspress_frontend_css_text'] ) ) ? sp_format_hex( $_POST['sportspress_frontend_css_text'] ) : '';
$heading = ( ! empty( $_POST['sportspress_frontend_css_heading'] ) ) ? sp_format_hex( $_POST['sportspress_frontend_css_heading'] ) : '';
$link = ( ! empty( $_POST['sportspress_frontend_css_link'] ) ) ? sp_format_hex( $_POST['sportspress_frontend_css_link'] ) : '';
$customize = ( ! empty( $_POST['sportspress_frontend_css_customize'] ) ) ? 1 : '';
$colors = array(
'primary' => $primary,
'background' => $background,
'text' => $text,
'heading' => $heading,
'link' => $link,
'customize' => $customize,
);
// Merge with existing options if available
$options = get_option( 'themeboy' );
if ( is_array( $options ) ) {
$colors = array_merge( $options, $colors );
}
update_option( 'themeboy', $colors );
}
}
$class = 'chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' );
?>
/**
* Timezone settings
*
* @access public
* @return void
*/
public function timezone_setting() {
$current_offset = get_option( 'gmt_offset' );
$tzstring = get_option( 'timezone_string' );
$check_zone_info = true;
// Remove old Etc mappings. Fallback to gmt_offset.
if ( false !== strpos( $tzstring, 'Etc/GMT' ) ) {
$tzstring = '';
}
if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists
$check_zone_info = false;
if ( 0 == $current_offset ) {
$tzstring = 'UTC+0';
} elseif ( $current_offset < 0 ) {
$tzstring = 'UTC' . $current_offset;
} else {
$tzstring = 'UTC+' . $current_offset;
}
}
$class = 'chosen-select' . ( is_rtl() ? ' chosen-rtl' : '' );
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="timezone_string"><?php _e( 'Timezone', 'sportspress' ); ?> <i class="dashicons dashicons-editor-help sp-desc-tip" title="<?php _e( 'Choose a city in the same timezone as you.', 'sportspress' ); ?>"></i></label>
</th>
<td class="forminp">
<td class="forminp">
<legend class="screen-reader-text"><span><?php _e( 'Timezone', 'sportspress' ); ?></span></legend>
<select id="timezone_string" name="timezone_string" class="<?php echo $class; ?>">
<?php echo wp_timezone_choice($tzstring); ?>
<?php echo wp_timezone_choice( $tzstring ); ?>
</select>
</td>
</tr>
<?php
}
</td>
</tr>
<?php
}
/**
* Output the frontend styles settings.
*
* @access public
* @return void
*/
public function colors_setting() {
// Define color schemes each with 5 colors: Primary, Background, Text, Heading, Link
$color_schemes = apply_filters( 'sportspress_color_schemes', array(
'ThemeBoy' => array( '2b353e', 'f4f4f4', '222222', 'ffffff', '00a69c' ),
'Gold' => array( '333333', 'f7f7f7', '333333', 'd8bf94', '9f8958' ),
'Denim' => array( '0e2440', 'eae5e0', '0e2440', 'ffffff', '2b6291' ),
'Patriot' => array( '0d4785', 'ecedee', '333333', 'ffffff', 'c51d27' ),
'Metro' => array( '3a7895', '223344', 'ffffff', 'ffffff', 'ffa800' ),
'Stellar' => array( '313150', '050528', 'ffffff', 'ffffff', 'e00034' ),
'Carbon' => array( '353535', '191919', 'ededed', 'ffffff', 'f67f17' ),
'Avocado' => array( '00241e', '013832', 'ffffff', 'ffffff', 'efb11e' ),
) );
?><tr valign="top" class="themeboy">
/**
* Output the frontend styles settings.
*
* @access public
* @return void
*/
public function colors_setting() {
// Define color schemes each with 5 colors: Primary, Background, Text, Heading, Link
$color_schemes = apply_filters(
'sportspress_color_schemes',
array(
'ThemeBoy' => array( '2b353e', 'f4f4f4', '222222', 'ffffff', '00a69c' ),
'Gold' => array( '333333', 'f7f7f7', '333333', 'd8bf94', '9f8958' ),
'Denim' => array( '0e2440', 'eae5e0', '0e2440', 'ffffff', '2b6291' ),
'Patriot' => array( '0d4785', 'ecedee', '333333', 'ffffff', 'c51d27' ),
'Metro' => array( '3a7895', '223344', 'ffffff', 'ffffff', 'ffa800' ),
'Stellar' => array( '313150', '050528', 'ffffff', 'ffffff', 'e00034' ),
'Carbon' => array( '353535', '191919', 'ededed', 'ffffff', 'f67f17' ),
'Avocado' => array( '00241e', '013832', 'ffffff', 'ffffff', 'efb11e' ),
)
);
?>
<tr valign="top" class="themeboy">
<th scope="row" class="titledesc">
<?php _e( 'Color Scheme', 'sportspress' ); ?>
</th>
<td class="forminp">
<fieldset>
<?php foreach ( $color_schemes as $name => $colors ) { ?>
<div class="color-option sp-color-option">
<td class="forminp">
<fieldset>
<?php foreach ( $color_schemes as $name => $colors ) { ?>
<div class="color-option sp-color-option">
<label data-sp-colors="<?php echo implode( ',', $colors ); ?>"><?php echo esc_html( $name ); ?></label>
<table class="color-palette">
<tbody>
@@ -368,14 +408,16 @@ class SP_Settings_General extends SP_Settings_Page {
</table>
</div>
<?php } ?>
</fieldset>
<fieldset>
<div class="sp-custom-colors">
</fieldset>
<fieldset>
<div class="sp-custom-colors">
<label data-sp-colors="<?php echo implode( ',', $colors ); ?>"><?php _e( 'Customize', 'sportspress' ); ?></label><br>
<?php
<?php
// Get settings
$colors = array_map( 'esc_attr', (array) get_option( 'themeboy', array() ) );
if ( empty( $colors ) ) $colors = array_map( 'esc_attr', (array) get_option( 'sportspress_frontend_css_colors', array() ) );
if ( empty( $colors ) ) {
$colors = array_map( 'esc_attr', (array) get_option( 'sportspress_frontend_css_colors', array() ) );
}
// Fallback
if ( ! isset( $colors['customize'] ) ) {
@@ -383,47 +425,59 @@ class SP_Settings_General extends SP_Settings_Page {
}
// Defaults
if ( empty( $colors['primary'] ) ) $colors['primary'] = '#2b353e';
if ( empty( $colors['background'] ) ) $colors['background'] = '#f4f4f4';
if ( empty( $colors['text'] ) ) $colors['text'] = '#222222';
if ( empty( $colors['heading'] ) ) $colors['heading'] = '#ffffff';
if ( empty( $colors['link'] ) ) $colors['link'] = '#00a69c';
if ( empty( $colors['primary'] ) ) {
$colors['primary'] = '#2b353e';
}
if ( empty( $colors['background'] ) ) {
$colors['background'] = '#f4f4f4';
}
if ( empty( $colors['text'] ) ) {
$colors['text'] = '#222222';
}
if ( empty( $colors['heading'] ) ) {
$colors['heading'] = '#ffffff';
}
if ( empty( $colors['link'] ) ) {
$colors['link'] = '#00a69c';
}
// Show inputs
$this->color_picker( __( 'Primary', 'sportspress' ), 'sportspress_frontend_css_primary', $colors['primary'] );
$this->color_picker( __( 'Background', 'sportspress' ), 'sportspress_frontend_css_background', $colors['background'] );
$this->color_picker( __( 'Text', 'sportspress' ), 'sportspress_frontend_css_text', $colors['text'] );
$this->color_picker( __( 'Heading', 'sportspress' ), 'sportspress_frontend_css_heading', $colors['heading'] );
$this->color_picker( __( 'Link', 'sportspress' ), 'sportspress_frontend_css_link', $colors['link'] );
$this->color_picker( __( 'Primary', 'sportspress' ), 'sportspress_frontend_css_primary', $colors['primary'] );
$this->color_picker( __( 'Background', 'sportspress' ), 'sportspress_frontend_css_background', $colors['background'] );
$this->color_picker( __( 'Text', 'sportspress' ), 'sportspress_frontend_css_text', $colors['text'] );
$this->color_picker( __( 'Heading', 'sportspress' ), 'sportspress_frontend_css_heading', $colors['heading'] );
$this->color_picker( __( 'Link', 'sportspress' ), 'sportspress_frontend_css_link', $colors['link'] );
if ( ( $styles = SP_Frontend_Scripts::get_styles() ) && array_key_exists( 'sportspress-general', $styles ) ):
?><br>
<label for="sportspress_frontend_css_customize">
if ( ( $styles = SP_Frontend_Scripts::get_styles() ) && array_key_exists( 'sportspress-general', $styles ) ) :
?>
<br>
<label for="sportspress_frontend_css_customize">
<input name="sportspress_frontend_css_customize" id="sportspress_frontend_css_customize" type="checkbox" value="1" <?php checked( $colors['customize'] ); ?>>
<?php _e( 'Enable', 'sportspress' ); ?>
</label>
<?php endif; ?>
</div>
</fieldset>
</fieldset>
</td>
</tr><?php
}
</tr>
<?php
}
/**
* Output a colour picker input box.
*
* @access public
* @param mixed $name
* @param mixed $id
* @param mixed $value
* @return void
*/
function color_picker( $name, $id, $value ) {
echo '<div class="sp-color-box"><strong>' . esc_html( $name ) . '</strong>
<input name="' . esc_attr( $id ). '" id="' . esc_attr( $id ) . '" type="text" value="' . esc_attr( $value ) . '" class="colorpick" /> <div id="colorPickerDiv_' . esc_attr( $id ) . '" class="colorpickdiv"></div>
/**
* Output a colour picker input box.
*
* @access public
* @param mixed $name
* @param mixed $id
* @param mixed $value
* @return void
*/
function color_picker( $name, $id, $value ) {
echo '<div class="sp-color-box"><strong>' . esc_html( $name ) . '</strong>
<input name="' . esc_attr( $id ) . '" id="' . esc_attr( $id ) . '" type="text" value="' . esc_attr( $value ) . '" class="colorpick" /> <div id="colorPickerDiv_' . esc_attr( $id ) . '" class="colorpickdiv"></div>
</div>';
}
}
}
endif;

View File

@@ -2,63 +2,69 @@
/**
* SportsPress License Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Settings_Licenses' ) ) :
/**
* SP_Settings_Licenses
*/
class SP_Settings_Licenses extends SP_Settings_Page {
/**
* @var array
* SP_Settings_Licenses
*/
public $licenses = array();
class SP_Settings_Licenses extends SP_Settings_Page {
/**
* Constructor
*/
public function __construct() {
$this->id = 'licenses';
$this->label = __( 'Licenses', 'sportspress' );
/**
* @var array
*/
public $licenses = array();
$this->licenses = apply_filters( 'sportspress_licenses', array(
'pro' => array(
'name' => 'SportsPress Pro',
'url' => 'https://account.themeboy.com',
),
));
if ( sizeof ( $this->licenses ) <= 1 )
return;
/**
* Constructor
*/
public function __construct() {
$this->id = 'licenses';
$this->label = __( 'Licenses', 'sportspress' );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
$this->licenses = apply_filters(
'sportspress_licenses',
array(
'pro' => array(
'name' => 'SportsPress Pro',
'url' => 'https://account.themeboy.com',
),
)
);
/**
* Output licenses
*
* @access public
* @return void
*/
public function output() {
?>
<?php wp_nonce_field( 'sp_license_nonce', 'sp_license_nonce' ); ?>
if ( sizeof( $this->licenses ) <= 1 ) {
return;
}
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Output licenses
*
* @access public
* @return void
*/
public function output() {
?>
<?php wp_nonce_field( 'sp_license_nonce', 'sp_license_nonce' ); ?>
<div class="sp-modules-wrapper">
<div class="sp-modules-main">
<?php
foreach ( $this->licenses as $id => $license ) {
$key = get_site_option( 'sportspress_' . $id . '_license_key' );
$key = trim( $key );
$key = get_site_option( 'sportspress_' . $id . '_license_key' );
$key = trim( $key );
$status = get_site_option( 'sportspress_' . $id . '_license_status', false );
?>
<div class="sp-settings-section sp-settings-section-license_options">
@@ -94,121 +100,137 @@ class SP_Settings_Licenses extends SP_Settings_Page {
<?php } ?>
</div>
</div>
<?php
<?php
$GLOBALS['hide_save_button'] = true;
}
/**
* Save license
*/
public function save() {
// run a quick security check
if ( ! check_admin_referer( 'sp_license_nonce', 'sp_license_nonce' ) ) {
return;
$GLOBALS['hide_save_button'] = true;
}
foreach ( $_POST as $name => $value ) {
if ( 'sp_license_activate_' === substr( $name, 0, 20 ) ) {
$this->activate( substr( $name, 20 ) );
} elseif ( 'sp_license_deactivate_' === substr( $name, 0, 22 ) ) {
$this->deactivate( substr( $name, 22 ) );
/**
* Save license
*/
public function save() {
// run a quick security check
if ( ! check_admin_referer( 'sp_license_nonce', 'sp_license_nonce' ) ) {
return;
}
foreach ( $_POST as $name => $value ) {
if ( 'sp_license_activate_' === substr( $name, 0, 20 ) ) {
$this->activate( substr( $name, 20 ) );
} elseif ( 'sp_license_deactivate_' === substr( $name, 0, 22 ) ) {
$this->deactivate( substr( $name, 22 ) );
}
}
}
/**
* Activate license
*/
public function activate( $id ) {
// return if a license key isn't set
if ( ! isset( $_POST[ 'sp_license_key_' . $id ] ) ) {
return;
}
// retrieve the license key
$license = trim( sanitize_text_field( $_POST[ 'sp_license_key_' . $id ] ) );
// get the name of the product
$name = $this->licenses[ $id ]['name'];
// data to send in our API request
$api_params = array(
'edd_action' => 'activate_license',
'license' => $license,
'item_name' => urlencode( $name ), // the name of our product in EDD
'url' => home_url(),
);
// Call the custom API.
$response = wp_remote_post(
$this->licenses[ $id ]['url'],
array(
'timeout' => 15,
'sslverify' => false,
'body' => $api_params,
)
);
// Make sure the response came back okay
if ( is_wp_error( $response ) ) {
SP_Admin_Settings::add_error( __( 'Sorry, there has been an error.', 'sportspress' ) );
return false;
}
// Decode the license data
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
// Update license status
update_site_option( 'sportspress_' . $id . '_license_status', $license_data->license );
// Update License or display error
if ( 'valid' == $license_data->license ) {
update_site_option( 'sportspress_' . $id . '_license_key', $license );
SP_Admin_Settings::add_override( __( 'License activated.', 'sportspress' ) );
} else {
SP_Admin_Settings::add_error( __( 'License invalid.', 'sportspress' ) );
}
}
/**
* Deactivate license
*/
public function deactivate( $id ) {
// return if a license key isn't set
if ( ! isset( $_POST[ 'sp_license_key_' . $id ] ) ) {
return;
}
// retrieve the license key
$license = trim( sanitize_text_field( $_POST[ 'sp_license_key_' . $id ] ) );
// get the name of the product
$name = $this->licenses[ $id ]['name'];
// data to send in our API request
$api_params = array(
'edd_action' => 'deactivate_license',
'license' => $license,
'item_name' => urlencode( $name ), // the name of our product in EDD
'url' => home_url(),
);
// Call the custom API.
$response = wp_remote_post(
$this->licenses[ $id ]['url'],
array(
'timeout' => 15,
'sslverify' => false,
'body' => $api_params,
)
);
// make sure the response came back okay
if ( is_wp_error( $response ) ) {
SP_Admin_Settings::add_error( __( 'Sorry, there has been an error.', 'sportspress' ) );
return false;
}
// decode the license data
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
// $license_data->license will be either "deactivated" or "failed"
if ( $license_data->license == 'deactivated' ) {
delete_site_option( 'sportspress_' . $id . '_license_status' );
SP_Admin_Settings::add_override( __( 'License deactivated.', 'sportspress' ) );
} else {
SP_Admin_Settings::add_error( __( 'Sorry, there has been an error.', 'sportspress' ) );
}
}
}
/**
* Activate license
*/
public function activate( $id ) {
// return if a license key isn't set
if ( ! isset( $_POST[ 'sp_license_key_' . $id ] ) )
return;
// retrieve the license key
$license = trim( sanitize_text_field( $_POST[ 'sp_license_key_' . $id ] ) );
// get the name of the product
$name = $this->licenses[ $id ]['name'];
// data to send in our API request
$api_params = array(
'edd_action'=> 'activate_license',
'license' => $license,
'item_name' => urlencode( $name ), // the name of our product in EDD
'url' => home_url()
);
// Call the custom API.
$response = wp_remote_post( $this->licenses[ $id ]['url'], array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
// Make sure the response came back okay
if ( is_wp_error( $response ) ) {
SP_Admin_Settings::add_error( __( 'Sorry, there has been an error.', 'sportspress' ) );
return false;
}
// Decode the license data
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
// Update license status
update_site_option( 'sportspress_' . $id . '_license_status', $license_data->license );
// Update License or display error
if ( 'valid' == $license_data->license ) {
update_site_option( 'sportspress_' . $id . '_license_key', $license );
SP_Admin_Settings::add_override( __( 'License activated.', 'sportspress' ) );
} else {
SP_Admin_Settings::add_error( __( 'License invalid.', 'sportspress' ) );
}
}
/**
* Deactivate license
*/
public function deactivate( $id ) {
// return if a license key isn't set
if ( ! isset( $_POST[ 'sp_license_key_' . $id ] ) )
return;
// retrieve the license key
$license = trim( sanitize_text_field( $_POST[ 'sp_license_key_' . $id ] ) );
// get the name of the product
$name = $this->licenses[ $id ]['name'];
// data to send in our API request
$api_params = array(
'edd_action'=> 'deactivate_license',
'license' => $license,
'item_name' => urlencode( $name ), // the name of our product in EDD
'url' => home_url()
);
// Call the custom API.
$response = wp_remote_post( $this->licenses[ $id ]['url'], array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
// make sure the response came back okay
if ( is_wp_error( $response ) ) {
SP_Admin_Settings::add_error( __( 'Sorry, there has been an error.', 'sportspress' ) );
return false;
}
// decode the license data
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
// $license_data->license will be either "deactivated" or "failed"
if ( $license_data->license == 'deactivated' ) {
delete_site_option( 'sportspress_' . $id . '_license_status' );
SP_Admin_Settings::add_override( __( 'License deactivated.', 'sportspress' ) );
} else {
SP_Admin_Settings::add_error( __( 'Sorry, there has been an error.', 'sportspress' ) );
}
}
}
endif;
return new SP_Settings_Licenses();

View File

@@ -2,55 +2,60 @@
/**
* SportsPress Module Settings
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Settings_Modules' ) ) :
/**
* SP_Settings_Modules
*/
class SP_Settings_Modules extends SP_Settings_Page {
/**
* @var array
* SP_Settings_Modules
*/
public $sections = array();
class SP_Settings_Modules extends SP_Settings_Page {
/**
* Constructor
*/
public function __construct() {
$this->id = 'modules';
$this->label = __( 'Modules', 'sportspress' );
/**
* @var array
*/
public $sections = array();
$this->sections = apply_filters( 'sportspress_module_sections', array(
'general' => __( 'General', 'sportspress' ),
'event' => __( 'Events', 'sportspress' ),
'team' => __( 'Teams', 'sportspress' ),
'player_staff' => __( 'Players', 'sportspress' ) . ' &amp; ' . __( 'Staff', 'sportspress' ),
'admin' => __( 'Dashboard', 'sportspress' ),
'other' => __( 'Other', 'sportspress' ),
));
/**
* Constructor
*/
public function __construct() {
$this->id = 'modules';
$this->label = __( 'Modules', 'sportspress' );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
$this->sections = apply_filters(
'sportspress_module_sections',
array(
'general' => __( 'General', 'sportspress' ),
'event' => __( 'Events', 'sportspress' ),
'team' => __( 'Teams', 'sportspress' ),
'player_staff' => __( 'Players', 'sportspress' ) . ' &amp; ' . __( 'Staff', 'sportspress' ),
'admin' => __( 'Dashboard', 'sportspress' ),
'other' => __( 'Other', 'sportspress' ),
)
);
/**
* Output modules
*
* @access public
* @return void
*/
public function output() {
?>
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'sportspress_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Output modules
*
* @access public
* @return void
*/
public function output() {
?>
<div class="sp-modules-wrapper">
<div class="sp-modules-sidebar">
<?php do_action( 'sportspress_modules_sidebar' ); ?>
@@ -64,7 +69,7 @@ class SP_Settings_Modules extends SP_Settings_Page {
</thead>
<tbody>
<tr><td>
<p><?php _e( 'Get SportsPress Pro to get access to all modules. You can upgrade any time without losing any of your data.','sportspress' ); ?></p>
<p><?php _e( 'Get SportsPress Pro to get access to all modules. You can upgrade any time without losing any of your data.', 'sportspress' ); ?></p>
<p class="sp-module-actions">
<span><?php _e( 'Premium', 'sportspress' ); ?></span>
<a class="button button-primary" href="<?php echo apply_filters( 'sportspress_pro_url', 'http://tboy.co/pro' ); ?>" target="_blank"><?php _e( 'Upgrade Now', 'sportspress' ); ?></a>
@@ -137,51 +142,51 @@ class SP_Settings_Modules extends SP_Settings_Page {
<?php
$categories = array(
'documentation' => array(
'icon' => 'sp-icon-book',
'icon' => 'sp-icon-book',
'label' => __( 'Documentation', 'sportspress' ),
'links' => array(
'http://tboy.co/installation' => __( 'Getting Started', 'sportspress' ),
'http://tboy.co/manuals' => __( 'Manuals', 'sportspress' ),
'http://tboy.co/videos' => __( 'Videos', 'sportspress' ),
'http://tboy.co/manuals' => __( 'Manuals', 'sportspress' ),
'http://tboy.co/videos' => __( 'Videos', 'sportspress' ),
),
),
'help' => array(
'icon' => 'dashicons dashicons-heart',
'help' => array(
'icon' => 'dashicons dashicons-heart',
'label' => __( 'Help', 'sportspress' ),
'links' => array(
'http://tboy.co/forums' => __( 'Support Forums', 'sportspress' ),
'http://tboy.co/ideas' => __( 'Feature Requests', 'sportspress' ),
'http://tboy.co/ideas' => __( 'Feature Requests', 'sportspress' ),
),
),
'social' => array(
'icon' => 'dashicons dashicons-share',
'social' => array(
'icon' => 'dashicons dashicons-share',
'label' => __( 'Connect', 'sportspress' ),
'links' => array(
'http://tboy.co/twitter' => __( 'Twitter', 'sportspress' ),
'http://tboy.co/twitter' => __( 'Twitter', 'sportspress' ),
'http://tboy.co/facebook' => __( 'Facebook', 'sportspress' ),
'http://tboy.co/youtube' => __( 'YouTube', 'sportspress' ),
'http://tboy.co/gplus' => __( 'Google+', 'sportspress' ),
'http://tboy.co/youtube' => __( 'YouTube', 'sportspress' ),
'http://tboy.co/gplus' => __( 'Google+', 'sportspress' ),
),
),
'developers' => array(
'icon' => 'dashicons dashicons-editor-code',
'developers' => array(
'icon' => 'dashicons dashicons-editor-code',
'label' => __( 'Developers', 'sportspress' ),
'links' => array(
'http://tboy.co/developers' => __( 'Reference', 'sportspress' ),
'http://tboy.co/slack' => __( 'Slack', 'sportspress' ),
'http://tboy.co/github' => __( 'GitHub', 'sportspress' ),
'http://tboy.co/slack' => __( 'Slack', 'sportspress' ),
'http://tboy.co/github' => __( 'GitHub', 'sportspress' ),
),
),
);
if ( class_exists( 'SportsPress_Pro' ) ) {
$categories['help']['links']['http://support.themeboy.com/'] = __( 'Premium Support', 'sportspress' );
} else {
$categories['help']['links'][ apply_filters( 'sportspress_pro_url', 'http://tboy.co/pro' ) ] = '<span class="sp-desc-tip" title="' . __( 'Upgrade to Pro', 'sportspress' ) . '">' . __( 'Premium Support', 'sportspress' ) . '</span>';
}
$categories = apply_filters( 'sportspress_modules_welcome_links', $categories );
if ( sizeof( $categories ) ) {
?>
<table class="widefat" cellspacing="0">
@@ -192,7 +197,7 @@ class SP_Settings_Modules extends SP_Settings_Page {
</thead>
<tbody>
<tr><td>
<?php foreach ( $categories as $slug => $category ) { ?>
<?php foreach ( $categories as $slug => $category ) { ?>
<p><strong><i class="<?php echo esc_attr( $category['icon'] ); ?>"></i> <?php echo esc_html( $category['label'] ); ?></strong></p>
<ul class="sp-<?php echo esc_attr( $slug ); ?>-links">
<?php foreach ( $category['links'] as $url => $text ) { ?>
@@ -205,11 +210,11 @@ class SP_Settings_Modules extends SP_Settings_Page {
</table>
<?php } ?>
<?php do_action( 'sportspress_modules_after_sidebar' ); ?>
<?php do_action( 'sportspress_modules_after_sidebar' ); ?>
</div>
<div class="sp-modules-main">
<?php foreach ( SP()->modules->data as $section => $modules ) { ?>
<?php foreach ( SP()->modules->data as $section => $modules ) { ?>
<table class="sp-modules-table widefat" cellspacing="0">
<thead>
<tr><th>
@@ -252,38 +257,38 @@ class SP_Settings_Modules extends SP_Settings_Page {
<?php } ?>
<p class="submit">
<input name="save" class="button button-primary" type="submit" value="<?php _e( 'Save Changes', 'sportspress' ); ?>" />
<?php $GLOBALS['hide_save_button'] = true; ?>
</p>
<input name="save" class="button button-primary" type="submit" value="<?php _e( 'Save Changes', 'sportspress' ); ?>" />
<?php $GLOBALS['hide_save_button'] = true; ?>
</p>
</div>
</div>
<input type="hidden" name="sportspress_update_modules" value="1">
<?php if ( isset( $_POST[ 'sportspress_update_modules' ] ) ) { ?>
<?php if ( isset( $_POST['sportspress_update_modules'] ) ) { ?>
<script type="text/javascript">
window.onload = function() {
window.location = window.location.href;
}
</script>
<?php
}
flush_rewrite_rules();
}
/**
* Save settings
*/
public function save() {
foreach ( SP()->modules->data as $sections => $modules ) {
foreach ( $modules as $id => $module ) {
$name = 'sportspress_load_' . $id . '_module';
update_option( $name, isset( $_POST[ $name ] ) ? 'yes' : 'no' );
<?php
}
flush_rewrite_rules();
}
/**
* Save settings
*/
public function save() {
foreach ( SP()->modules->data as $sections => $modules ) {
foreach ( $modules as $id => $module ) {
$name = 'sportspress_load_' . $id . '_module';
update_option( $name, isset( $_POST[ $name ] ) ? 'yes' : 'no' );
}
}
flush_rewrite_rules();
}
flush_rewrite_rules();
}
}
endif;

View File

@@ -2,126 +2,135 @@
/**
* SportsPress Settings Page/Tab
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.7.9
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.7.9
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'SP_Settings_Page' ) ) :
/**
* SP_Settings_Page
*/
class SP_Settings_Page {
protected $id = '';
protected $label = '';
protected $template = '';
/**
* Add this page to settings
* SP_Settings_Page
*/
public function add_settings_page( $pages ) {
$pages[ $this->id ] = $this->label;
class SP_Settings_Page {
return $pages;
}
protected $id = '';
protected $label = '';
protected $template = '';
/**
* Add this page to settings
*/
public function add_settings_page( $pages ) {
$pages[ $this->id ] = $this->label;
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
return array();
}
return $pages;
}
/**
* Templates
*
* @return array
*/
public function templates() {
if ( ! isset( $this->template ) ) return array();
$template = $this->template;
return SP()->templates->$template;
}
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
return array();
}
/**
* Output the settings
*/
public function output() {
$settings = $this->get_settings();
/**
* Templates
*
* @return array
*/
public function templates() {
if ( ! isset( $this->template ) ) {
return array();
}
$template = $this->template;
return SP()->templates->$template;
}
SP_Admin_Settings::output_fields( $settings );
}
/**
* Output the settings
*/
public function output() {
$settings = $this->get_settings();
/**
* Save settings
*/
public function save() {
global $current_section;
SP_Admin_Settings::output_fields( $settings );
}
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
/**
* Save settings
*/
public function save() {
global $current_section;
if ( $current_section )
do_action( 'sportspress_update_options_' . $this->template . '_' . $current_section );
$settings = $this->get_settings();
SP_Admin_Settings::save_fields( $settings );
$templates = $this->templates();
if ( ! empty( $templates ) )
update_option( 'sportspress_' . $this->template . '_template_order', sp_array_value( $_POST, 'sportspress_' . $this->template . '_template_order', false, 'key' ) );
if ( $current_section ) {
do_action( 'sportspress_update_options_' . $this->template . '_' . $current_section );
}
if ( isset( $_POST['sportspress_template_visibility'] ) && is_array( $_POST['sportspress_template_visibility'] ) ) {
foreach ( $_POST['sportspress_template_visibility'] as $option => $toggled ) {
if ( $toggled ) {
update_option( $option, 'yes' );
} else {
update_option( $option, 'no' );
$templates = $this->templates();
if ( ! empty( $templates ) ) {
update_option( 'sportspress_' . $this->template . '_template_order', sp_array_value( $_POST, 'sportspress_' . $this->template . '_template_order', false, 'key' ) );
}
if ( isset( $_POST['sportspress_template_visibility'] ) && is_array( $_POST['sportspress_template_visibility'] ) ) {
foreach ( $_POST['sportspress_template_visibility'] as $option => $toggled ) {
if ( $toggled ) {
update_option( $option, 'yes' );
} else {
update_option( $option, 'no' );
}
}
}
}
}
/**
* Layout settings
*
* @access public
* @return void
*/
public function layout_setting() {
$templates = $this->templates();
$templates = apply_filters( 'sportspress_' . $this->template . '_templates', $templates );
$layout = get_option( 'sportspress_' . $this->template . '_template_order' );
if ( false === $layout ) {
$layout = array_keys( $templates );
}
$templates = array_merge( array_flip( (array) $layout ), $templates );
$slice = array_search( 'tabs', array_keys( $templates ) );
if ( $slice ) {
$templates = array_slice( $templates, 0, $slice );
}
?>
/**
* Layout settings
*
* @access public
* @return void
*/
public function layout_setting() {
$templates = $this->templates();
$templates = apply_filters( 'sportspress_' . $this->template . '_templates', $templates );
$layout = get_option( 'sportspress_' . $this->template . '_template_order' );
if ( false === $layout ) {
$layout = array_keys( $templates );
}
$templates = array_merge( array_flip( (array) $layout ), $templates );
$slice = array_search( 'tabs', array_keys( $templates ) );
if ( $slice ) {
$templates = array_slice( $templates, 0, $slice );
}
?>
<tr valign="top">
<th>
<?php _e( 'Layout', 'sportspress' ); ?>
</th>
<td class="sp-sortable-list-container">
<p class="description"><?php _e( 'Drag each item into the order you prefer.', 'sportspress' ); ?></p>
<td class="sp-sortable-list-container">
<p class="description"><?php _e( 'Drag each item into the order you prefer.', 'sportspress' ); ?></p>
<ul class="sp-layout sp-sortable-list sp-connected-list ui-sortable">
<?php foreach ( $templates as $template => $details ) {
if ( ! is_array( $details ) ) continue;
$option = sp_array_value( $details, 'option', 'sportspress_' . $this->template . '_show_' . $template );
$visibility = get_option( $option, sp_array_value( $details, 'default', 'yes' ) );
?>
<li>
<ul class="sp-layout sp-sortable-list sp-connected-list ui-sortable">
<?php
foreach ( $templates as $template => $details ) {
if ( ! is_array( $details ) ) {
continue;
}
$option = sp_array_value( $details, 'option', 'sportspress_' . $this->template . '_show_' . $template );
$visibility = get_option( $option, sp_array_value( $details, 'default', 'yes' ) );
?>
<li>
<div class="sp-item-bar sp-layout-item-bar">
<div class="sp-item-handle sp-layout-item-handle ui-sortable-handle">
<span class="sp-item-title item-title"><?php echo esc_html( sp_array_value( $details, 'title', ucfirst( $template ) ) ); ?></span>
@@ -134,51 +143,54 @@ class SP_Settings_Page {
</div>
</li>
<?php } ?>
</ul>
</ul>
</td>
</tr>
<?php
}
/**
* Tabs settings
*
* @access public
* @return void
*/
public function tabs_setting() {
$templates = $this->templates();
$templates = apply_filters( 'sportspress_' . $this->template . '_templates', $templates );
$layout = get_option( 'sportspress_' . $this->template . '_template_order' );
if ( false === $layout ) {
$layout = array_keys( $templates );
<?php
}
$templates = array_merge( array_flip( (array) $layout ), $templates );
$slice = array_search( 'tabs', array_keys( $templates ) );
if ( $slice ) {
$templates = array_slice( $templates, $slice );
} else {
$templates = array();
}
?>
/**
* Tabs settings
*
* @access public
* @return void
*/
public function tabs_setting() {
$templates = $this->templates();
$templates = apply_filters( 'sportspress_' . $this->template . '_templates', $templates );
$layout = get_option( 'sportspress_' . $this->template . '_template_order' );
if ( false === $layout ) {
$layout = array_keys( $templates );
}
$templates = array_merge( array_flip( (array) $layout ), $templates );
$slice = array_search( 'tabs', array_keys( $templates ) );
if ( $slice ) {
$templates = array_slice( $templates, $slice );
} else {
$templates = array();
}
?>
<tr valign="top">
<th>
<?php _e( 'Tabs', 'sportspress' ); ?>
</th>
<td class="sp-sortable-list-container">
<p class="description"><?php _e( 'Drag items here to display them as tabs.', 'sportspress' ); ?></p>
<td class="sp-sortable-list-container">
<p class="description"><?php _e( 'Drag items here to display them as tabs.', 'sportspress' ); ?></p>
<input type="hidden" name="sportspress_<?php echo esc_attr( $this->template ); ?>_template_order[]" value="tabs">
<ul class="sp-layout sp-sortable-list sp-connected-list ui-sortable">
<?php foreach ( $templates as $template => $details ) {
if ( ! is_array( $details ) ) continue;
$option = sp_array_value( $details, 'option', 'sportspress_' . $this->template . '_show_' . $template );
$visibility = get_option( $option, sp_array_value( $details, 'default', 'yes' ) );
?>
<li>
<ul class="sp-layout sp-sortable-list sp-connected-list ui-sortable">
<?php
foreach ( $templates as $template => $details ) {
if ( ! is_array( $details ) ) {
continue;
}
$option = sp_array_value( $details, 'option', 'sportspress_' . $this->template . '_show_' . $template );
$visibility = get_option( $option, sp_array_value( $details, 'default', 'yes' ) );
?>
<li>
<div class="sp-item-bar sp-layout-item-bar">
<div class="sp-item-handle sp-layout-item-handle ui-sortable-handle">
<span class="sp-item-title item-title"><?php echo esc_html( sp_array_value( $details, 'title', ucfirst( $template ) ) ); ?></span>
@@ -191,11 +203,11 @@ class SP_Settings_Page {
</div>
</li>
<?php } ?>
</ul>
</ul>
</td>
</tr>
<?php
<?php
}
}
}
endif;

Some files were not shown because too many files have changed in this diff Show More