prefix = framework_get_prefix(); /* Set up the widget options. */ $widget_options = array( 'classname' => 'tags', 'description' => esc_html__( 'Display your site\'s tags.', 'wordsmith' ) ); /* Set up the widget control options. */ $control_options = array( 'width' => 525, 'height' => 350 ); /* Create the widget. */ $this->WP_Widget( "{$this->prefix}-tags", __( 'Tags', 'wordsmith' ), $widget_options, $control_options ); } /* Outputs the widget based on the arguments input through the widget controls. */ function widget( $args, $instance ) { extract( $args ); /* Arguments for the widget. */ $args['taxonomy'] = $instance['taxonomy']; $args['number'] = intval( $instance['number'] ); $args['include'] = $instance['include']; $args['exclude'] = $instance['exclude']; $args['order'] = $instance['order']; $args['orderby'] = $instance['orderby']; $args['echo'] = false; /* Output the theme's $before_widget wrapper. */ echo $before_widget; /* If a title was input by the user, display it. */ if ( !empty( $instance['title'] ) ) echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title; /* Get the tag cloud. */ $tags = str_replace( array( "\r", "\n", "\t" ), ' ', wp_tag_cloud( $args ) ); /* Wrap tag cloud links with a span for easier background image styling. */ $tags = preg_replace( "/>(.*?)<\/a>/", ">$1", wp_tag_cloud( $args ) ); echo $tags; /* Close the theme's widget wrapper. */ echo $after_widget; } /* Updates the widget control options for the particular instance of the widget. */ function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance = $new_instance; if ( $instance['taxonomy'] !== $old_instance['taxonomy'] ) { $instance['include'] = array(); $instance['exclude'] = array(); } $instance['title'] = strip_tags( $new_instance['title'] ); $instance['taxonomy'] = $new_instance['taxonomy']; $instance['order'] = $new_instance['order']; $instance['orderby'] = $new_instance['orderby']; $instance['include'] = $new_instance['include']; $instance['exclude'] = $new_instance['exclude']; $instance['number'] = strip_tags( $new_instance['number'] ); return $instance; } /* Displays the widget control options in the Widgets admin screen. */ function form( $instance ) { /* Set up the default form values. */ $defaults = array( 'title' => esc_attr__( 'Tags', 'wordsmith' ), 'number' => '15', 'orderby' => 'name', 'order' => 'ASC', 'taxonomy' => 'post_tag' ); /* Merge the user-selected arguments with the defaults. */ $instance = wp_parse_args( (array) $instance, $defaults ); /* Select element options. */ $taxonomies = get_taxonomies( array( 'show_tagcloud' => true ), 'objects' ); $terms = get_terms( $instance['taxonomy'] ); $order = array( 'ASC' => esc_attr__( 'Ascending', 'wordsmith' ), 'DESC' => esc_attr__( 'Descending', 'wordsmith' ), 'RAND' => esc_attr__( 'Random', 'wordsmith' ) ); $orderby = array( 'count' => esc_attr__( 'Count', 'wordsmith' ), 'name' => esc_attr__( 'Name', 'wordsmith' ) ); ?>