Make WordPress Core


Ignore:
Timestamp:
04/17/2020 09:36:25 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Format the markup of widget forms in a more consistent manner.

See #49542.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/widgets/class-wp-widget-tag-cloud.php

    r47122 r47593  
    125125     */
    126126    public function form( $instance ) {
    127         $current_taxonomy  = $this->_get_current_taxonomy( $instance );
    128         $title_id          = $this->get_field_id( 'title' );
    129         $count             = isset( $instance['count'] ) ? (bool) $instance['count'] : false;
    130         $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
    131 
    132         echo '<p><label for="' . $title_id . '">' . __( 'Title:' ) . '</label>
    133             <input type="text" class="widefat" id="' . $title_id . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $instance['title'] . '" />
    134         </p>';
    135 
    136         $taxonomies = get_taxonomies( array( 'show_tagcloud' => true ), 'object' );
    137         $id         = $this->get_field_id( 'taxonomy' );
    138         $name       = $this->get_field_name( 'taxonomy' );
    139         $input      = '<input type="hidden" id="' . $id . '" name="' . $name . '" value="%s" />';
    140 
    141         $count_checkbox = sprintf(
    142             '<p><input type="checkbox" class="checkbox" id="%1$s" name="%2$s"%3$s /> <label for="%1$s">%4$s</label></p>',
    143             $this->get_field_id( 'count' ),
    144             $this->get_field_name( 'count' ),
    145             checked( $count, true, false ),
    146             __( 'Show tag counts' )
    147         );
     127        $title = ! empty( $instance['title'] ) ? $instance['title'] : '';
     128        $count = isset( $instance['count'] ) ? (bool) $instance['count'] : false;
     129        ?>
     130        <p>
     131            <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
     132            <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 ); ?>" />
     133        </p>
     134        <?php
     135        $taxonomies       = get_taxonomies( array( 'show_tagcloud' => true ), 'object' );
     136        $current_taxonomy = $this->_get_current_taxonomy( $instance );
    148137
    149138        switch ( count( $taxonomies ) ) {
     
    151140            // No tag cloud supporting taxonomies found, display error message.
    152141            case 0:
    153                 echo '<p>' . __( 'The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.' ) . '</p>';
    154                 printf( $input, '' );
     142                ?>
     143                <input type="hidden" id="<?php echo $this->get_field_id( 'taxonomy' ); ?>" name="<?php echo $this->get_field_name( 'taxonomy' ); ?>" value="" />
     144                <p>
     145                    <?php _e( 'The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.' ); ?>
     146                </p>
     147                <?php
    155148                break;
    156149
     
    159152                $keys     = array_keys( $taxonomies );
    160153                $taxonomy = reset( $keys );
    161                 printf( $input, esc_attr( $taxonomy ) );
    162                 echo $count_checkbox;
     154                ?>
     155                <input type="hidden" id="<?php echo $this->get_field_id( 'taxonomy' ); ?>" name="<?php echo $this->get_field_name( 'taxonomy' ); ?>" value="<?php echo esc_attr( $taxonomy ); ?>" />
     156                <?php
    163157                break;
    164158
    165159            // More than one tag cloud supporting taxonomy found, display a select.
    166160            default:
    167                 printf(
    168                     '<p><label for="%1$s">%2$s</label>' .
    169                     '<select class="widefat" id="%1$s" name="%3$s">',
    170                     $id,
    171                     __( 'Taxonomy:' ),
    172                     $name
    173                 );
    174 
    175                 foreach ( $taxonomies as $taxonomy => $tax ) {
    176                     printf(
    177                         '<option value="%s"%s>%s</option>',
    178                         esc_attr( $taxonomy ),
    179                         selected( $taxonomy, $current_taxonomy, false ),
    180                         $tax->labels->name
    181                     );
    182                 }
    183 
    184                 echo '</select></p>' . $count_checkbox;
     161                ?>
     162                <p>
     163                    <label for="<?php echo $this->get_field_id( 'taxonomy' ); ?>"><?php _e( 'Taxonomy:' ); ?></label>
     164                    <select class="widefat" id="<?php echo $this->get_field_id( 'taxonomy' ); ?>" name="<?php echo $this->get_field_name( 'taxonomy' ); ?>">
     165                    <?php foreach ( $taxonomies as $taxonomy => $tax ) : ?>
     166                        <option value="<?php echo esc_attr( $taxonomy ); ?>" <?php selected( $taxonomy, $current_taxonomy ); ?>>
     167                            <?php echo esc_html( $tax->labels->name ); ?>
     168                        </option>
     169                    <?php endforeach; ?>
     170                    </select>
     171                </p>
     172                <?php
     173        }
     174
     175        if ( count( $taxonomies ) > 0 ) {
     176            ?>
     177            <p>
     178                <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id( 'count' ); ?>" name="<?php echo $this->get_field_name( 'count' ); ?>" <?php checked( $count, true ); ?> />
     179                <label for="<?php echo $this->get_field_id( 'count' ); ?>"><?php _e( 'Show tag counts' ); ?></label>
     180            </p>
     181            <?php
    185182        }
    186183    }
Note: See TracChangeset for help on using the changeset viewer.