Make WordPress Core

Ticket #32470: 32470.4.diff

File 32470.4.diff, 5.8 KB (added by welcher, 11 years ago)

Adding verify_settings() and widget_title() methods

  • wp-includes/default-widgets.php

     
    254254         * @param array $args
    255255         * @param array $instance
    256256         */
    257         public function widget( $args, $instance ) {
    258                 /** This filter is documented in wp-includes/default-widgets.php */
    259                 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
    260 
    261                 echo $args['before_widget'];
    262                 if ( $title ) {
    263                         echo $args['before_title'] . $title . $args['after_title'];
    264                 }
    265 
     257        public function widget_markup( $args, $instance ) {
    266258                // Use current theme search form if it exists
    267259                get_search_form();
    268 
    269                 echo $args['after_widget'];
    270260        }
    271261
    272262        /**
     
    444434         * @param array $args
    445435         * @param array $instance
    446436         */
    447         public function widget( $args, $instance ) {
    448                 /** This filter is documented in wp-includes/default-widgets.php */
    449                 $title = apply_filters( 'widget_title', empty($instance['title']) ? __( 'Meta' ) : $instance['title'], $instance, $this->id_base );
    450 
    451                 echo $args['before_widget'];
    452                 if ( $title ) {
    453                         echo $args['before_title'] . $title . $args['after_title'];
    454                 }
     437        public function widget_markup( $args, $instance ) {
    455438?>
    456439                        <ul>
    457440                        <?php wp_register(); ?>
     
    476459?>
    477460                        </ul>
    478461<?php
    479                 echo $args['after_widget'];
    480462        }
    481463
    482464        /**
     
    519501         * @param array $args
    520502         * @param array $instance
    521503         */
    522         public function widget( $args, $instance ) {
    523                 /** This filter is documented in wp-includes/default-widgets.php */
    524                 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
    525 
    526                 echo $args['before_widget'];
    527                 if ( $title ) {
    528                         echo $args['before_title'] . $title . $args['after_title'];
    529                 }
     504        public function widget_markup( $args, $instance ) {
    530505                echo '<div id="calendar_wrap">';
    531506                get_calendar();
    532507                echo '</div>';
    533                 echo $args['after_widget'];
    534508        }
    535509
    536510        /**
     
    575549         * @param array $args
    576550         * @param array $instance
    577551         */
    578         public function widget( $args, $instance ) {
    579                 /** This filter is documented in wp-includes/default-widgets.php */
    580                 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
     552        public function widget_markup( $args, $instance ) {
    581553
    582554                /**
    583555                 * Filter the content of the Text widget.
     
    588560                 * @param WP_Widget $instance    WP_Widget instance.
    589561                 */
    590562                $text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance );
    591                 echo $args['before_widget'];
    592                 if ( ! empty( $title ) ) {
    593                         echo $args['before_title'] . $title . $args['after_title'];
    594                 } ?>
     563                ?>
    595564                        <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
    596565                <?php
    597                 echo $args['after_widget'];
    598566        }
    599567
    600568        /**
     
    13921360         * @param array $args
    13931361         * @param array $instance
    13941362         */
    1395         public function widget( $args, $instance ) {
     1363        public function widget_markup( $args, $instance ) {
    13961364                $current_taxonomy = $this->_get_current_taxonomy($instance);
    13971365                if ( !empty($instance['title']) ) {
    13981366                        $title = $instance['title'];
     
    14051373                        }
    14061374                }
    14071375
    1408                 /** This filter is documented in wp-includes/default-widgets.php */
    1409                 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
    1410 
    1411                 echo $args['before_widget'];
    1412                 if ( $title ) {
    1413                         echo $args['before_title'] . $title . $args['after_title'];
    1414                 }
    14151376                echo '<div class="tagcloud">';
    14161377
    14171378                /**
     
    14291390                ) ) );
    14301391
    14311392                echo "</div>\n";
    1432                 echo $args['after_widget'];
    14331393        }
    14341394
    14351395        /**
  • wp-includes/widgets.php

     
    104104         * @param array $instance The settings for the particular instance of the widget.
    105105         */
    106106        public function widget( $args, $instance ) {
    107                 die('function WP_Widget::widget() must be over-ridden in a sub-class.');
     107                //verify that we should be showing the widget
     108                if ( ! $this->verify_settings( $instance ) ) {
     109                        return;
     110                }
     111
     112                $this->before_widget( $args, $instance );
     113                $this->widget_markup( $args, $instance );
     114                $this->after_widget( $args, $instance );
    108115        }
    109116
    110117        /**
     118         * Verify settings
     119         *
     120         * Used to determine whether we should render the widget or not. Props @jdgrimes {link} https://core.trac.wordpress.org/ticket/32470#comment:15
     121         * @param array $instance
     122         * @return bool
     123         */
     124        public function verify_settings( $instance ) {
     125                return true;
     126        }
     127
     128        /**
     129         * Default treatment of before widget markup
     130         *
     131         * @param $args
     132         * @param $instance
     133         */
     134        public function before_widget( $args, $instance ) {
     135                $title = $this->widget_title( $instance );
     136                echo $args['before_widget'];
     137                if ( $title ) {
     138                        echo $args['before_title'] . $title . $args['after_title'];
     139                }
     140        }
     141
     142        /**
     143         * Output the custom markup content for the widget
     144         *
     145         * Subclasses will override this to create their output
     146         */
     147        public function widget_markup( $args, $instance ) {}
     148
     149        /**
     150         * Default treatment of after widget markup
     151         *
     152         * @param $args
     153         * @param $instance
     154         */
     155        public function after_widget( $args, $instance ) {
     156                echo $args['after_widget'];
     157        }
     158
     159        /**
     160         * Return the title of the widget
     161         *
     162         * @param $instance
     163         *
     164         * @return mixed|void
     165         */
     166        public function widget_title( $instance ) {
     167                return  apply_filters( 'widget_title', ! isset($instance['title']  ) || empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
     168        }
     169
     170        /**
    111171         * Update a particular instance.
    112172         *
    113173         * This function should check that $new_instance is set correctly. The newly-calculated