Skip to content

Instantly share code, notes, and snippets.

@SeanTOSCD
Created June 12, 2014 18:34
Show Gist options
  • Save SeanTOSCD/302b1762695f3fbacb89 to your computer and use it in GitHub Desktop.
Save SeanTOSCD/302b1762695f3fbacb89 to your computer and use it in GitHub Desktop.
Remove Downloads Categories / Tags widget and replace it with custom widget
<?php
/**
* replace original Categories / Tags widget with custom
*/
function replace_edd_categories_tags_widget() {
unregister_widget( 'edd_categories_tags_widget' );
register_widget( 'custom_edd_categories_tags_widget' );
}
add_action( 'widgets_init', 'replace_edd_categories_tags_widget' );
/**
* custom Downloads Categories / Tags Widget class
*/
class custom_edd_categories_tags_widget extends WP_Widget {
/** Constructor */
function custom_edd_categories_tags_widget() {
parent::WP_Widget( false, __( 'Downloads Categories / Tags', 'edd' ), array( 'description' => __( 'Display the downloads categories or tags', 'edd' ) ) );
}
/** @see WP_Widget::widget */
function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance[ 'title' ], $instance, $id );
$tax = $instance['taxonomy'];
$count = isset( $instance['count'] ) && $instance['count'] == 'on' ? 1 : 0;
$hide_empty = isset( $instance['hide_empty'] ) && $instance['hide_empty'] == 'on' ? 1 : 0;
global $post, $edd_options;
echo $before_widget;
if ( $title ) {
echo $before_title . $title . $after_title;
}
do_action( 'edd_before_taxonomy_widget' );
echo "<ul class=\"edd-taxonomy-widget\">\n";
wp_list_categories('title_li=&taxonomy=' . $tax . '&show_count=' . $count . '&hide_empty=' . $hide_empty);
echo "</ul>\n";
do_action( 'edd_after_taxonomy_widget' );
echo $after_widget;
}
/** @see WP_Widget::update */
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['taxonomy'] = strip_tags( $new_instance['taxonomy'] );
$instance['count'] = isset( $new_instance['count'] ) ? $new_instance['count'] : '';
$instance['hide_empty'] = isset( $new_instance['hide_empty'] ) ? $new_instance['hide_empty'] : '';
return $instance;
}
/** @see WP_Widget::form */
function form( $instance ) {
// Set up some default widget settings.
$defaults = array(
'title' => '',
'taxonomy' => 'download_category',
'count' => 'off',
'hide_empty' => 'off'
);
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:', 'edd' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo $title; ?>"/>
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'taxonomy' ) ); ?>"><?php _e( 'Taxonomy:', 'edd' ); ?></label>
<select name="<?php echo esc_attr( $this->get_field_name( 'taxonomy' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'taxonomy' ) ); ?>">
<option value="download_category" <?php selected( 'download_category', $taxonomy ); ?>><?php _e( 'Categories', 'edd' ); ?></option>
<option value="download_tag" <?php selected( 'download_tag', $taxonomy ); ?>><?php _e( 'Tags', 'edd' ); ?></option>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e( 'Show Count:', 'edd' ); ?></label>
<input <?php checked( $instance['count'], 'on' ); ?> id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>" type="checkbox" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'hide_empty' ); ?>"><?php _e( 'Hide Empty Categories:', 'edd' ); ?></label>
<input <?php checked( $instance['hide_empty'], 'on' ); ?> id="<?php echo $this->get_field_id( 'hide_empty' ); ?>" name="<?php echo $this->get_field_name( 'hide_empty' ); ?>" type="checkbox" />
</p>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment