Skip to content

Commit

Permalink
Make Test_Widget compatible with WP_Widget (#34355)
Browse files Browse the repository at this point in the history
* Make Test_Widget compatible with WP_Widget

* Move the isset($instance['title']) from update() to form() where it's needed

* Explain why codingStandardsIgnoreStart
  • Loading branch information
adamziel authored Aug 30, 2021
1 parent 098bd96 commit b2c4a00
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/e2e-tests/plugins/class-test-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function form( $instance ) {
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( isset( $instance['title'] ) ? $instance['title'] : '' ); ?>" />
</p>
<?php
}
Expand All @@ -58,11 +58,14 @@ public function form( $instance ) {
*
* @param array $new_instance New settings for this instance as input by the user via
* WP_Widget::form().
* @param array $old_instance Old settings for this instance.
*
* @return array Settings to save or bool false to cancel saving.
* @since 4.8.1
*/
public function update( $new_instance ) {
// @codingStandardsIgnoreStart – to prevent phpcs from complaining about unused function argument.
public function update( $new_instance, $old_instance ) {
// @codingStandardsIgnoreEnd
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
Expand Down

0 comments on commit b2c4a00

Please sign in to comment.