Add single staff shortcode and widget

This commit is contained in:
Brian Miyaji
2014-11-11 09:44:56 +11:00
parent 70446f91ca
commit 04c9d1dade
6 changed files with 133 additions and 3 deletions

View File

@@ -173,6 +173,7 @@ class SP_Admin_Meta_Boxes {
add_meta_box( 'sp_editordiv', __( 'Description', 'sportspress' ), 'SP_Meta_Box_List_Editor::output', 'sp_list', 'normal', 'low' );
// Staff
add_meta_box( 'sp_shortcodediv', __( 'Shortcode', 'sportspress' ), 'SP_Meta_Box_Staff_Shortcode::output', 'sp_staff', 'side', 'default' );
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Staff_Details::output', 'sp_staff', 'side', 'default' );
add_meta_box( 'sp_editordiv', __( 'Profile', 'sportspress' ), 'SP_Meta_Box_Staff_Editor::output', 'sp_staff', 'normal', 'low' );
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Staff Shortcode
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 1.4.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Staff_Shortcode
*/
class SP_Meta_Box_Staff_Shortcode {
/**
* Output the metabox
*/
public static function output( $post ) {
?>
<p class="howto">
<?php _e( 'Copy this code and paste it into your post, page or text widget content.', 'sportspress' ); ?>
</p>
<p><input type="text" value="[staff <?php echo $post->ID; ?>]" readonly="readonly" class="code widefat"></p>
<?php
}
}

View File

@@ -28,6 +28,7 @@ class SP_Shortcodes {
'player_statistics' => __CLASS__ . '::player_statistics',
'player_list' => __CLASS__ . '::player_list',
'player_gallery' => __CLASS__ . '::player_gallery',
'staff' => __CLASS__ . '::staff',
);
foreach ( $shortcodes as $shortcode => $function ) {

View File

@@ -0,0 +1,25 @@
<?php
/**
* Staff Shortcode
*
* @author ThemeBoy
* @category Shortcodes
* @package SportsPress/Shortcodes/Staff
* @version 1.4.7
*/
class SP_Shortcode_Staff {
/**
* Output the staff shortcode.
*
* @param array $atts
*/
public static function output( $atts ) {
if ( ! isset( $atts['id'] ) && isset( $atts[0] ) && is_numeric( $atts[0] ) )
$atts['id'] = $atts[0];
sp_get_template( 'staff-photo.php', $atts );
sp_get_template( 'staff-details.php', $atts );
}
}

View File

@@ -0,0 +1,73 @@
<?php
class SP_Widget_Staff extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_staff widget_sp_staff', 'description' => __( 'Display a single staff member.', 'sportspress' ) );
parent::__construct('sp_staff', __( 'Staff', 'sportspress' ) . ' (' . __( 'SportsPress', 'sportspress' ) . ')', $widget_ops);
}
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? null : $instance['title'], $instance, $this->id_base);
$id = empty($instance['id']) ? null : $instance['id'];
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
// Action to hook into
do_action( 'sportspress_before_widget_template', $args, $instance, 'staff' );
sp_get_template( 'staff-photo.php', array( 'id' => $id ) );
sp_get_template( 'staff-details.php', array( 'id' => $id ) );
// Action to hook into
do_action( 'sportspress_after_widget_template', $args, $instance, 'staff' );
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['id'] = intval($new_instance['id']);
// Filter to hook into
$instance = apply_filters( 'sportspress_widget_update', $instance, $new_instance, $old_instance, 'staff' );
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '' ) );
$title = strip_tags($instance['title']);
$id = intval($instance['id']);
// Action to hook into
do_action( 'sportspress_before_widget_template_form', $this, $instance, 'staff' );
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:', 'sportspress' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<p><label for="<?php echo $this->get_field_id('id'); ?>"><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Staff', 'sportspress' ) ); ?></label>
<?php
$args = array(
'post_type' => 'sp_staff',
'name' => $this->get_field_name('id'),
'id' => $this->get_field_id('id'),
'selected' => $id,
'values' => 'ID',
'class' => 'widefat',
);
if ( ! sp_dropdown_pages( $args ) ):
sp_post_adder( 'sp_staff', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<?php
// Action to hook into
do_action( 'sportspress_after_widget_template_form', $this, $instance, 'staff' );
}
}
register_widget( 'SP_Widget_Staff' );

View File

@@ -3,7 +3,7 @@
* Plugin Name: SportsPress
* Plugin URI: http://themeboy.com/sportspress/
* Description: Manage your club and its players, staff, events, league tables, and player lists.
* Version: 1.4.6
* Version: 1.4.7
* Author: ThemeBoy
* Author URI: http://themeboy.com
* Requires at least: 3.8
@@ -26,14 +26,14 @@ if ( ! class_exists( 'SportsPress' ) ) :
* Main SportsPress Class
*
* @class SportsPress
* @version 1.4.6
* @version 1.4.7
*/
final class SportsPress {
/**
* @var string
*/
public $version = '1.4.6';
public $version = '1.4.7';
/**
* @var SporsPress The single instance of the class
@@ -253,6 +253,7 @@ final class SportsPress {
include_once( 'includes/widgets/class-sp-widget-league-table.php' );
include_once( 'includes/widgets/class-sp-widget-player-list.php' );
include_once( 'includes/widgets/class-sp-widget-player-gallery.php' );
include_once( 'includes/widgets/class-sp-widget-staff.php' );
do_action( 'sportspress_widgets' );
}