Widgets: don't show a dropdown if there is only 1 taxonomy or zero taxonomies available to the Tag Cloud widget form. Don't output the widget if there are no terms in the selected taxonomy.
Props GautamGupta, wonderboymusic. Fixes #16125. Built from https://develop.svn.wordpress.org/trunk@34273 git-svn-id: http://core.svn.wordpress.org/trunk@34237 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c2e1bab509
commit
a2f15ca7cd
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.4-alpha-34272';
|
$wp_version = '4.4-alpha-34273';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
|
@ -30,15 +30,6 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
|
|
||||||
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
|
|
||||||
|
|
||||||
echo $args['before_widget'];
|
|
||||||
if ( $title ) {
|
|
||||||
echo $args['before_title'] . $title . $args['after_title'];
|
|
||||||
}
|
|
||||||
echo '<div class="tagcloud">';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the taxonomy used in the Tag Cloud widget.
|
* Filter the taxonomy used in the Tag Cloud widget.
|
||||||
*
|
*
|
||||||
|
@ -49,10 +40,27 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
|
||||||
*
|
*
|
||||||
* @param array $current_taxonomy The taxonomy to use in the tag cloud. Default 'tags'.
|
* @param array $current_taxonomy The taxonomy to use in the tag cloud. Default 'tags'.
|
||||||
*/
|
*/
|
||||||
wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(
|
$tag_cloud = wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(
|
||||||
'taxonomy' => $current_taxonomy
|
'taxonomy' => $current_taxonomy,
|
||||||
|
'echo' => false
|
||||||
) ) );
|
) ) );
|
||||||
|
|
||||||
|
if ( empty( $tag_cloud ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
|
||||||
|
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
|
||||||
|
|
||||||
|
echo $args['before_widget'];
|
||||||
|
if ( $title ) {
|
||||||
|
echo $args['before_title'] . $title . $args['after_title'];
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<div class="tagcloud">';
|
||||||
|
|
||||||
|
echo $tag_cloud;
|
||||||
|
|
||||||
echo "</div>\n";
|
echo "</div>\n";
|
||||||
echo $args['after_widget'];
|
echo $args['after_widget'];
|
||||||
}
|
}
|
||||||
|
@ -74,20 +82,54 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
|
||||||
*/
|
*/
|
||||||
public function form( $instance ) {
|
public function form( $instance ) {
|
||||||
$current_taxonomy = $this->_get_current_taxonomy($instance);
|
$current_taxonomy = $this->_get_current_taxonomy($instance);
|
||||||
$title = isset( $instance['title'] ) ? $instance['title'] : '';
|
$title_id = $this->get_field_id( 'title' );
|
||||||
?>
|
$instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
|
||||||
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
|
|
||||||
<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr( $title ); ?>" /></p>
|
echo '<p><label for="' . $title_id .'">' . __( 'Title:' ) . '</label>
|
||||||
<p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
|
<input type="text" class="widefat" id="' . $title_id .'" name="' . $this->get_field_name( 'title' ) .'" value="' . $instance['title'] .'" />
|
||||||
<select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">
|
</p>';
|
||||||
<?php foreach ( get_taxonomies() as $taxonomy ) :
|
|
||||||
$tax = get_taxonomy($taxonomy);
|
$taxonomies = get_taxonomies( array( 'show_tagcloud' => true ), 'object' );
|
||||||
if ( !$tax->show_tagcloud || empty($tax->labels->name) )
|
$id = $this->get_field_id( 'taxonomy' );
|
||||||
continue;
|
$name = $this->get_field_name( 'taxonomy' );
|
||||||
?>
|
$input = '<input type="hidden" id="' . $id . '" name="' . $name . '" value="%s" />';
|
||||||
<option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo esc_attr( $tax->labels->name ); ?></option>
|
|
||||||
<?php endforeach; ?>
|
switch ( count( $taxonomies ) ) {
|
||||||
</select></p><?php
|
|
||||||
|
// No tag cloud supporting taxonomies found, display error message
|
||||||
|
case 0:
|
||||||
|
echo '<p>' . __( 'The tag cloud will not be displayed since their are no taxonomies that support the tag cloud widget.' ) . '</p>';
|
||||||
|
printf( $input, '' );
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Just a single tag cloud supporting taxonomy found, no need to display options
|
||||||
|
case 1:
|
||||||
|
$keys = array_keys( $taxonomies );
|
||||||
|
$taxonomy = reset( $keys );
|
||||||
|
printf( $input, esc_attr( $taxonomy ) );
|
||||||
|
break;
|
||||||
|
|
||||||
|
// More than one tag cloud supporting taxonomy found, display options
|
||||||
|
default:
|
||||||
|
printf(
|
||||||
|
'<p><label for="%1$s">%2$s</label>' .
|
||||||
|
'<select class="widefat" id="%1$s" name="%3$s">',
|
||||||
|
$id,
|
||||||
|
__( 'Taxonomy:' ),
|
||||||
|
$name
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ( $taxonomies as $taxonomy => $tax ) {
|
||||||
|
printf(
|
||||||
|
'<option value="%s"%s>%s</option>',
|
||||||
|
esc_attr( $taxonomy ),
|
||||||
|
selected( $taxonomy, $current_taxonomy, false ),
|
||||||
|
$tax->labels->name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '</select></p>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue