Move venue term functions into class

This commit is contained in:
Brian Miyaji
2014-03-26 11:12:22 +11:00
parent 1a00fdb2da
commit 32fddcc82e
6 changed files with 171 additions and 167 deletions

View File

@@ -1,7 +0,0 @@
<?php
function sportspress_current_screen() {
$screen = get_current_screen();
if ( $screen->id == 'dashboard' )
include_once( dirname( SP_PLUGIN_FILE ) . '/admin/tools/dashboard.php' );
}
add_action( 'current_screen', 'sportspress_current_screen' );

View File

@@ -1,78 +0,0 @@
<?php
function sportspress_venue_edit_form_fields( $term ) {
$t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" ); ?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[sp_address]"><?php _e( 'Address', 'sportspress' ); ?></label></th>
<td>
<input type="text" class="sp-address" name="term_meta[sp_address]" id="term_meta[sp_address]" value="<?php echo esc_attr( $term_meta['sp_address'] ) ? esc_attr( $term_meta['sp_address'] ) : ''; ?>">
<p><div class="sp-location-picker"></div></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[sp_latitude]"><?php _e( 'Latitude', 'sportspress' ); ?></label></th>
<td>
<input type="text" class="sp-latitude" name="term_meta[sp_latitude]" id="term_meta[sp_latitude]" value="<?php echo esc_attr( $term_meta['sp_latitude'] ) ? esc_attr( $term_meta['sp_latitude'] ) : ''; ?>">
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[sp_longitude]"><?php _e( 'Longitude', 'sportspress' ); ?></label></th>
<td>
<input type="text" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo esc_attr( $term_meta['sp_longitude'] ) ? esc_attr( $term_meta['sp_longitude'] ) : ''; ?>">
</td>
</tr>
<?php
}
add_action( 'sp_venue_edit_form_fields', 'sportspress_venue_edit_form_fields', 10, 2 );
function sportspress_venue_add_form_fields() {
$args = array(
'orderby' => 'id',
'order' => 'DESC',
'hide_empty' => false,
'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;
$term_meta = get_option( "taxonomy_$t_id" );
$latitude = sportspress_array_value( $term_meta, 'sp_latitude', '40.7324319' );
$longitude = sportspress_array_value( $term_meta, 'sp_longitude', '-73.82480799999996' );
else:
$latitude = '40.7324319';
$longitude = '-73.82480799999996';
endif;
?>
<div class="form-field">
<label for="term_meta[sp_address]"><?php _e( 'Address', 'sportspress' ); ?></label>
<input type="text" class="sp-address" name="term_meta[sp_address]" id="term_meta[sp_address]" value="">
<input type="hidden" class="sp-latitude" name="term_meta[sp_latitude]" id="term_meta[sp_latitude]" value="<?php echo $latitude; ?>">
<input type="hidden" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo $longitude; ?>">
<p><div class="sp-location-picker"></div></p>
</div>
<?php
}
add_action( 'sp_venue_add_form_fields', 'sportspress_venue_add_form_fields', 10, 2 );
function sportspress_save_venue_meta( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) {
$t_id = $term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$cat_keys = array_keys( $_POST['term_meta'] );
foreach ( $cat_keys as $key ) {
if ( isset ( $_POST['term_meta'][ $key ] ) ) {
$term_meta[$key] = $_POST['term_meta'][ $key ];
}
}
update_option( "taxonomy_$t_id", $term_meta );
}
}
add_action( 'edited_sp_venue', 'sportspress_save_venue_meta', 10, 2 );
add_action( 'create_sp_venue', 'sportspress_save_venue_meta', 10, 2 );

View File

@@ -1,77 +0,0 @@
<?php
/**
* Admin Dashboard
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( '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_tables' ) ) {
add_action( 'wp_dashboard_setup', array( $this, 'init' ) );
}
}
/**
* Init dashboard widgets
*/
public function init() {
wp_add_dashboard_widget( 'sportspress_dashboard_status', __( 'SportsPress Status', 'sportspress' ), array( $this, 'status_widget' ) );
}
/**
* Show status widget
*/
public function status_widget() {
$next_event = sportspress_get_next_event();
$now = new DateTime( current_time( 'mysql', 0 ) );
$date = new DateTime( $next_event->post_date );
$interval = date_diff( $now, $date );
$count = wp_count_posts( 'sp_event' );
$scheduled_count = $count->future;
$published_count = $count->publish;
?>
<ul class="sp_status_list">
<?php if ( $next_event ): ?>
<li class="countdown" data-countdown="<?php echo str_replace( '-', '/', $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 $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
}
}
endif;
return new SP_Admin_Dashboard();

View File

@@ -0,0 +1,169 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Handles taxonomies in admin
*
* @class SP_Admin_Taxonomies
* @version 2.1.0
* @package SportsPress/Admin
* @category Class
* @author ThemeBoy
*/
class SP_Admin_Taxonomies {
/**
* Constructor
*/
public function __construct() {
// Add form
add_action( 'sp_venue_add_form_fields', array( $this, 'add_venue_fields' ) );
add_action( 'sp_venue_edit_form_fields', array( $this, 'edit_venue_fields' ), 10, 1 );
add_action( 'edited_sp_venue', array( $this, 'save_venue_fields' ), 10, 2 );
add_action( 'create_sp_venue', array( $this, 'save_venue_fields' ), 10, 2 );
// Add columns
add_filter( 'manage_edit-sp_venue_columns', array( $this, 'venue_columns' ) );
add_filter( 'manage_sp_venue_custom_column', array( $this, 'venue_column' ), 10, 3 );
}
/**
* Category thumbnail fields.
*
* @access public
* @return void
*/
public function add_venue_fields() {
$args = array(
'orderby' => 'id',
'order' => 'DESC',
'hide_empty' => false,
'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;
$term_meta = get_option( "taxonomy_$t_id" );
$latitude = sportspress_array_value( $term_meta, 'sp_latitude', '40.7324319' );
$longitude = sportspress_array_value( $term_meta, 'sp_longitude', '-73.82480799999996' );
else:
$latitude = '40.7324319';
$longitude = '-73.82480799999996';
endif;
?>
<div class="form-field">
<label for="term_meta[sp_address]"><?php _e( 'Address', 'sportspress' ); ?></label>
<input type="text" class="sp-address" name="term_meta[sp_address]" id="term_meta[sp_address]" value="">
<input type="hidden" class="sp-latitude" name="term_meta[sp_latitude]" id="term_meta[sp_latitude]" value="<?php echo $latitude; ?>">
<input type="hidden" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo $longitude; ?>">
<p><div class="sp-location-picker"></div></p>
</div>
<?php
}
/**
* Edit category thumbnail field.
*
* @access public
* @param mixed $term Term (category) being edited
* @param mixed $taxonomy Taxonomy of the term being edited
*/
public function edit_venue_fields( $term, $taxonomy ) {
$t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" ); ?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[sp_address]"><?php _e( 'Address', 'sportspress' ); ?></label></th>
<td>
<input type="text" class="sp-address" name="term_meta[sp_address]" id="term_meta[sp_address]" value="<?php echo esc_attr( $term_meta['sp_address'] ) ? esc_attr( $term_meta['sp_address'] ) : ''; ?>">
<p><div class="sp-location-picker"></div></p>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[sp_latitude]"><?php _e( 'Latitude', 'sportspress' ); ?></label></th>
<td>
<input type="text" class="sp-latitude" name="term_meta[sp_latitude]" id="term_meta[sp_latitude]" value="<?php echo esc_attr( $term_meta['sp_latitude'] ) ? esc_attr( $term_meta['sp_latitude'] ) : ''; ?>">
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[sp_longitude]"><?php _e( 'Longitude', 'sportspress' ); ?></label></th>
<td>
<input type="text" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo esc_attr( $term_meta['sp_longitude'] ) ? esc_attr( $term_meta['sp_longitude'] ) : ''; ?>">
</td>
</tr>
<?php
}
/**
* save_category_fields function.
*
* @access public
* @param mixed $term_id Term ID being saved
* @param mixed $tt_id
* @param mixed $taxonomy Taxonomy of the term being saved
* @return void
*/
public function save_venue_fields( $term_id, $tt_id ) {
if ( isset( $_POST['term_meta'] ) ) {
$t_id = $term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$cat_keys = array_keys( $_POST['term_meta'] );
foreach ( $cat_keys as $key ) {
if ( isset ( $_POST['term_meta'][ $key ] ) ) {
$term_meta[$key] = $_POST['term_meta'][ $key ];
}
}
update_option( "taxonomy_$t_id", $term_meta );
}
}
/**
* Thumbnail column added to category admin.
*
* @access public
* @param mixed $columns
* @return array
*/
public function venue_columns( $columns ) {
$new_columns = array();
$new_columns['sp_address'] = __( 'Address', 'sportspress' );
$new_columns['posts'] = __( 'Events', 'sportspress' );
unset( $columns['description'] );
unset( $columns['slug'] );
unset( $columns['posts'] );
return array_merge( $columns, $new_columns );
}
/**
* Thumbnail column value added to category admin.
*
* @access public
* @param mixed $columns
* @param mixed $column
* @param mixed $id
* @return array
*/
public function venue_column( $columns, $column, $id ) {
if ( $column == 'sp_address' ) {
$term_meta = get_option( "taxonomy_$id" );
$address = ( isset( $term_meta['sp_address'] ) ? $term_meta['sp_address'] : '&mdash;' );
$columns .= $address;
}
return $columns;
}
}
new SP_Admin_Taxonomies();

View File

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

View File

@@ -222,9 +222,6 @@ final class SportsPress {
include_once( 'includes/class-sp-countries.php' ); // Defines continents and countries include_once( 'includes/class-sp-countries.php' ); // Defines continents and countries
include_once( 'includes/class-sp-text.php' ); // Defines editable strings include_once( 'includes/class-sp-text.php' ); // Defines editable strings
// Terms (deprecating)
include_once( 'admin/terms/venue.php' );
// Typical request actions (deprecating) // Typical request actions (deprecating)
include_once( 'admin/hooks/plugins-loaded.php' ); include_once( 'admin/hooks/plugins-loaded.php' );
include_once( 'admin/hooks/wp-enqueue-scripts.php' ); include_once( 'admin/hooks/wp-enqueue-scripts.php' );
@@ -237,7 +234,7 @@ final class SportsPress {
include_once( 'admin/hooks/admin-enqueue-scripts.php' ); include_once( 'admin/hooks/admin-enqueue-scripts.php' );
include_once( 'admin/hooks/admin-print-styles.php' ); include_once( 'admin/hooks/admin-print-styles.php' );
include_once( 'admin/hooks/admin-head.php' ); include_once( 'admin/hooks/admin-head.php' );
include_once( 'admin/hooks/current-screen.php' ); //include_once( 'admin/hooks/current-screen.php' );
// Administrative actions (deprecating) // Administrative actions (deprecating)
//include_once( 'admin/hooks/manage-posts-columns.php' ); //include_once( 'admin/hooks/manage-posts-columns.php' );