Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 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/class-wp-widget.php

    r41688 r42343  
    111111     */
    112112    public function widget( $args, $instance ) {
    113         die('function WP_Widget::widget() must be over-ridden in a sub-class.');
     113        die( 'function WP_Widget::widget() must be over-ridden in a sub-class.' );
    114114    }
    115115
     
    141141     */
    142142    public function form( $instance ) {
    143         echo '<p class="no-options-widget">' . __('There are no options for this widget.') . '</p>';
     143        echo '<p class="no-options-widget">' . __( 'There are no options for this widget.' ) . '</p>';
    144144        return 'noform';
    145145    }
     
    161161     */
    162162    public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) {
    163         $this->id_base = empty($id_base) ? preg_replace( '/(wp_)?widget_/', '', strtolower(get_class($this)) ) : strtolower($id_base);
    164         $this->name = $name;
    165         $this->option_name = 'widget_' . $this->id_base;
    166         $this->widget_options = wp_parse_args( $widget_options, array( 'classname' => $this->option_name, 'customize_selective_refresh' => false ) );
     163        $this->id_base         = empty( $id_base ) ? preg_replace( '/(wp_)?widget_/', '', strtolower( get_class( $this ) ) ) : strtolower( $id_base );
     164        $this->name            = $name;
     165        $this->option_name     = 'widget_' . $this->id_base;
     166        $this->widget_options  = wp_parse_args(
     167            $widget_options, array(
     168                'classname'                   => $this->option_name,
     169                'customize_selective_refresh' => false,
     170            )
     171        );
    167172        $this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) );
    168173    }
     
    200205     * @return string Name attribute for $field_name
    201206     */
    202     public function get_field_name($field_name) {
     207    public function get_field_name( $field_name ) {
    203208        if ( false === $pos = strpos( $field_name, '[' ) ) {
    204209            return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field_name . ']';
     
    231236    public function _register() {
    232237        $settings = $this->get_settings();
    233         $empty = true;
     238        $empty    = true;
    234239
    235240        // When $settings is an array-like object, get an intrinsic array for use with array_keys().
     
    263268     *                    instances of the same class.
    264269     */
    265     public function _set($number) {
     270    public function _set( $number ) {
    266271        $this->number = $number;
    267         $this->id = $this->id_base . '-' . $number;
     272        $this->id     = $this->id_base . '-' . $number;
    268273    }
    269274
     
    276281     */
    277282    public function _get_display_callback() {
    278         return array($this, 'display_callback');
     283        return array( $this, 'display_callback' );
    279284    }
    280285
     
    287292     */
    288293    public function _get_update_callback() {
    289         return array($this, 'update_callback');
     294        return array( $this, 'update_callback' );
    290295    }
    291296
     
    298303     */
    299304    public function _get_form_callback() {
    300         return array($this, 'form_callback');
     305        return array( $this, 'form_callback' );
    301306    }
    302307
     
    317322    public function is_preview() {
    318323        global $wp_customize;
    319         return ( isset( $wp_customize ) && $wp_customize->is_preview() ) ;
     324        return ( isset( $wp_customize ) && $wp_customize->is_preview() );
    320325    }
    321326
     
    393398
    394399        // We need to update the data
    395         if ( $this->updated )
     400        if ( $this->updated ) {
    396401            return;
    397 
    398         if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
     402        }
     403
     404        if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) {
    399405            // Delete the settings for this instance of the widget
    400             if ( isset($_POST['the-widget-id']) )
     406            if ( isset( $_POST['the-widget-id'] ) ) {
    401407                $del_id = $_POST['the-widget-id'];
    402             else
     408            } else {
    403409                return;
    404 
    405             if ( isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) {
    406                 $number = $wp_registered_widgets[$del_id]['params'][0]['number'];
    407 
    408                 if ( $this->id_base . '-' . $number == $del_id )
    409                     unset($all_instances[$number]);
     410            }
     411
     412            if ( isset( $wp_registered_widgets[ $del_id ]['params'][0]['number'] ) ) {
     413                $number = $wp_registered_widgets[ $del_id ]['params'][0]['number'];
     414
     415                if ( $this->id_base . '-' . $number == $del_id ) {
     416                    unset( $all_instances[ $number ] );
     417                }
    410418            }
    411419        } else {
    412             if ( isset($_POST['widget-' . $this->id_base]) && is_array($_POST['widget-' . $this->id_base]) ) {
    413                 $settings = $_POST['widget-' . $this->id_base];
    414             } elseif ( isset($_POST['id_base']) && $_POST['id_base'] == $this->id_base ) {
    415                 $num = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number'];
     420            if ( isset( $_POST[ 'widget-' . $this->id_base ] ) && is_array( $_POST[ 'widget-' . $this->id_base ] ) ) {
     421                $settings = $_POST[ 'widget-' . $this->id_base ];
     422            } elseif ( isset( $_POST['id_base'] ) && $_POST['id_base'] == $this->id_base ) {
     423                $num      = $_POST['multi_number'] ? (int) $_POST['multi_number'] : (int) $_POST['widget_number'];
    416424                $settings = array( $num => array() );
    417425            } else {
     
    420428
    421429            foreach ( $settings as $number => $new_instance ) {
    422                 $new_instance = stripslashes_deep($new_instance);
    423                 $this->_set($number);
    424 
    425                 $old_instance = isset($all_instances[$number]) ? $all_instances[$number] : array();
     430                $new_instance = stripslashes_deep( $new_instance );
     431                $this->_set( $number );
     432
     433                $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
    426434
    427435                $was_cache_addition_suspended = wp_suspend_cache_addition();
     
    451459                $instance = apply_filters( 'widget_update_callback', $instance, $new_instance, $old_instance, $this );
    452460                if ( false !== $instance ) {
    453                     $all_instances[$number] = $instance;
     461                    $all_instances[ $number ] = $instance;
    454462                }
    455463
     
    458466        }
    459467
    460         $this->save_settings($all_instances);
     468        $this->save_settings( $all_instances );
    461469        $this->updated = true;
    462470    }
     
    476484     */
    477485    public function form_callback( $widget_args = 1 ) {
    478         if ( is_numeric($widget_args) )
     486        if ( is_numeric( $widget_args ) ) {
    479487            $widget_args = array( 'number' => $widget_args );
    480 
    481         $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
     488        }
     489
     490        $widget_args   = wp_parse_args( $widget_args, array( 'number' => -1 ) );
    482491        $all_instances = $this->get_settings();
    483492
    484493        if ( -1 == $widget_args['number'] ) {
    485494            // We echo out a form where 'number' can be set later
    486             $this->_set('__i__');
     495            $this->_set( '__i__' );
    487496            $instance = array();
    488497        } else {
    489             $this->_set($widget_args['number']);
     498            $this->_set( $widget_args['number'] );
    490499            $instance = $all_instances[ $widget_args['number'] ];
    491500        }
     
    505514        $return = null;
    506515        if ( false !== $instance ) {
    507             $return = $this->form($instance);
     516            $return = $this->form( $instance );
    508517
    509518            /**
     
    537546     */
    538547    public function _register_one( $number = -1 ) {
    539         wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) );
     548        wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) );
    540549        _register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) );
    541         _register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) );
     550        _register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) );
    542551    }
    543552
Note: See TracChangeset for help on using the changeset viewer.