Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r41685 r42343  
    2424    public function __construct() {
    2525        $widget_ops = array(
    26             'description' => __( 'Your blogroll' ),
     26            'description'                 => __( 'Your blogroll' ),
    2727            'customize_selective_refresh' => true,
    2828        );
     
    4040     */
    4141    public function widget( $args, $instance ) {
    42         $show_description = isset($instance['description']) ? $instance['description'] : false;
    43         $show_name = isset($instance['name']) ? $instance['name'] : false;
    44         $show_rating = isset($instance['rating']) ? $instance['rating'] : false;
    45         $show_images = isset($instance['images']) ? $instance['images'] : true;
    46         $category = isset($instance['category']) ? $instance['category'] : false;
    47         $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name';
    48         $order = $orderby == 'rating' ? 'DESC' : 'ASC';
    49         $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1;
     42        $show_description = isset( $instance['description'] ) ? $instance['description'] : false;
     43        $show_name        = isset( $instance['name'] ) ? $instance['name'] : false;
     44        $show_rating      = isset( $instance['rating'] ) ? $instance['rating'] : false;
     45        $show_images      = isset( $instance['images'] ) ? $instance['images'] : true;
     46        $category         = isset( $instance['category'] ) ? $instance['category'] : false;
     47        $orderby          = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name';
     48        $order            = $orderby == 'rating' ? 'DESC' : 'ASC';
     49        $limit            = isset( $instance['limit'] ) ? $instance['limit'] : -1;
    5050
    5151        $before_widget = preg_replace( '/id="[^"]*"/', 'id="%id"', $args['before_widget'] );
     
    9393    public function update( $new_instance, $old_instance ) {
    9494        $new_instance = (array) $new_instance;
    95         $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );
     95        $instance     = array(
     96            'images'      => 0,
     97            'name'        => 0,
     98            'description' => 0,
     99            'rating'      => 0,
     100        );
    96101        foreach ( $instance as $field => $val ) {
    97             if ( isset($new_instance[$field]) )
    98                 $instance[$field] = 1;
     102            if ( isset( $new_instance[ $field ] ) ) {
     103                $instance[ $field ] = 1;
     104            }
    99105        }
    100106
    101107        $instance['orderby'] = 'name';
    102         if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) )
     108        if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) ) {
    103109            $instance['orderby'] = $new_instance['orderby'];
     110        }
    104111
    105112        $instance['category'] = intval( $new_instance['category'] );
    106         $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;
     113        $instance['limit']    = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;
    107114
    108115        return $instance;
     
    119126
    120127        //Defaults
    121         $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) );
     128        $instance  = wp_parse_args(
     129            (array) $instance, array(
     130                'images'      => true,
     131                'name'        => true,
     132                'description' => false,
     133                'rating'      => false,
     134                'category'    => false,
     135                'orderby'     => 'name',
     136                'limit'       => -1,
     137            )
     138        );
    122139        $link_cats = get_terms( 'link_category' );
    123         if ( ! $limit = intval( $instance['limit'] ) )
     140        if ( ! $limit = intval( $instance['limit'] ) ) {
    124141            $limit = -1;
     142        }
    125143            ?>
    126144        <p>
    127         <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label>
    128         <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
    129         <option value=""><?php _ex('All Links', 'links widget'); ?></option>
     145        <label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Select Link Category:' ); ?></label>
     146        <select class="widefat" id="<?php echo $this->get_field_id( 'category' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>">
     147        <option value=""><?php _ex( 'All Links', 'links widget' ); ?></option>
    130148        <?php
    131149        foreach ( $link_cats as $link_cat ) {
     
    136154        ?>
    137155        </select>
    138         <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label>
    139         <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
     156        <label for="<?php echo $this->get_field_id( 'orderby' ); ?>"><?php _e( 'Sort by:' ); ?></label>
     157        <select name="<?php echo $this->get_field_name( 'orderby' ); ?>" id="<?php echo $this->get_field_id( 'orderby' ); ?>" class="widefat">
    140158            <option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option>
    141159            <option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option>
     
    145163        </p>
    146164        <p>
    147         <input class="checkbox" type="checkbox"<?php checked($instance['images'], true) ?> id="<?php echo $this->get_field_id('images'); ?>" name="<?php echo $this->get_field_name('images'); ?>" />
    148         <label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
    149         <input class="checkbox" type="checkbox"<?php checked($instance['name'], true) ?> id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" />
    150         <label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br />
    151         <input class="checkbox" type="checkbox"<?php checked($instance['description'], true) ?> id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>" />
    152         <label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br />
    153         <input class="checkbox" type="checkbox"<?php checked($instance['rating'], true) ?> id="<?php echo $this->get_field_id('rating'); ?>" name="<?php echo $this->get_field_name('rating'); ?>" />
    154         <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
     165        <input class="checkbox" type="checkbox"<?php checked( $instance['images'], true ); ?> id="<?php echo $this->get_field_id( 'images' ); ?>" name="<?php echo $this->get_field_name( 'images' ); ?>" />
     166        <label for="<?php echo $this->get_field_id( 'images' ); ?>"><?php _e( 'Show Link Image' ); ?></label><br />
     167        <input class="checkbox" type="checkbox"<?php checked( $instance['name'], true ); ?> id="<?php echo $this->get_field_id( 'name' ); ?>" name="<?php echo $this->get_field_name( 'name' ); ?>" />
     168        <label for="<?php echo $this->get_field_id( 'name' ); ?>"><?php _e( 'Show Link Name' ); ?></label><br />
     169        <input class="checkbox" type="checkbox"<?php checked( $instance['description'], true ); ?> id="<?php echo $this->get_field_id( 'description' ); ?>" name="<?php echo $this->get_field_name( 'description' ); ?>" />
     170        <label for="<?php echo $this->get_field_id( 'description' ); ?>"><?php _e( 'Show Link Description' ); ?></label><br />
     171        <input class="checkbox" type="checkbox"<?php checked( $instance['rating'], true ); ?> id="<?php echo $this->get_field_id( 'rating' ); ?>" name="<?php echo $this->get_field_name( 'rating' ); ?>" />
     172        <label for="<?php echo $this->get_field_id( 'rating' ); ?>"><?php _e( 'Show Link Rating' ); ?></label>
    155173        </p>
    156174        <p>
    157         <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label>
    158         <input id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit == -1 ? '' : intval( $limit ); ?>" size="3" />
     175        <label for="<?php echo $this->get_field_id( 'limit' ); ?>"><?php _e( 'Number of links to show:' ); ?></label>
     176        <input id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" type="text" value="<?php echo $limit == -1 ? '' : intval( $limit ); ?>" size="3" />
    159177        </p>
    160178        <?php
Note: See TracChangeset for help on using the changeset viewer.