54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?php
|
|
class SportsPress_Widget_League_Table extends WP_Widget {
|
|
|
|
function __construct() {
|
|
$widget_ops = array('classname' => 'widget_league_table widget_sp_league_table', 'description' => __( 'SportsPress widget.', 'sportspress' ) );
|
|
parent::__construct('sp_table', __( 'League Table', 'sportspress', 'sportspress' ), $widget_ops);
|
|
}
|
|
|
|
function widget( $args, $instance ) {
|
|
extract($args);
|
|
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
|
|
$id = empty($instance['id']) ? null : $instance['id'];
|
|
echo $before_widget;
|
|
if ( $title )
|
|
echo $before_title . $title . $after_title;
|
|
echo '<div id="sp_league_table_wrap">';
|
|
echo sportspress_league_table( $id );
|
|
echo '</div>';
|
|
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']);
|
|
|
|
return $instance;
|
|
}
|
|
|
|
function form( $instance ) {
|
|
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => '' ) );
|
|
$title = strip_tags($instance['title']);
|
|
$id = intval($instance['id']);
|
|
?>
|
|
<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>
|
|
<?php
|
|
$args = array(
|
|
'post_type' => 'sp_table',
|
|
'name' => $this->get_field_name('id'),
|
|
'id' => $this->get_field_id('id'),
|
|
'show_option_none' => __( '-- Select --', 'sportspress' ),
|
|
'selected' => $id,
|
|
'values' => 'ID',
|
|
);
|
|
sportspress_dropdown_pages( $args );
|
|
?>
|
|
</p>
|
|
<?php
|
|
}
|
|
}
|
|
add_action( 'widgets_init', create_function( '', 'return register_widget( "SportsPress_Widget_League_Table" );' ) );
|