Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Bug Affecting Widgets without description #14587

Merged

Conversation

jorgefilipecosta
Copy link
Member

Description

Fixes: #14552

We were not checking in the widget description was set and on widgets, without description, an undefined notice was being thrown.

How has this been tested?

I installed the AnsPress Question Answer plugin: https://wordpress.org/plugins/anspress-question-answer.
I created a new page and verified and checked Undefined notice was not being thrown in the PHP code. In master, a notice should appear.

lib/widgets.php Outdated
@@ -110,7 +115,7 @@ function gutenberg_legacy_widget_settings( $settings ) {
}
$available_legacy_widgets[ $widget_id ] = array(
'name' => html_entity_decode( $widget_obj['name'] ),
'description' => null,
'description' => html_entity_decode( wp_widget_description( $widget_id ) ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what way is this change related to the fix?

Copy link
Member Author

@jorgefilipecosta jorgefilipecosta Mar 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During these changes, I noticed I missed to pass a description when I added support some simple call back widgets.
But it is not directly related to these changes. I separated this change to other PR #14615.

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative test (I'd created before this pull request):

  1. Ensure define( 'WP_DEBUG', true ); in wp-config.php
  2. Add the following as wp-content/mu-plugins/custom-widget.php:
<?php

class Custom_Widget extends WP_Widget {
	public function __construct() {
		parent::__construct( 'Custom_Widget', 'Custom Widget' );
	}

	public function widget( $args, $instance ) {
	}

	public function form( $instance ) {
	}

	public function update( $new_instance, $old_instance ) {
		return $new_instance;
	}
}

add_action( 'init', function() {
	register_widget( 'Custom_Widget' );
} );
  1. Navigate to Posts > Add New

The PHP warning notice is no longer shown after these changes.

Can you confirm: Prior to this change, description was passed as an empty string when not defined by the widget. It is now passed as null. Is there a meaningful impact of this difference?

@jorgefilipecosta jorgefilipecosta force-pushed the fix/problem-affecting-widgets-without-description branch from fba1311 to 0d9e369 Compare March 25, 2019 10:37
@jorgefilipecosta
Copy link
Member Author

Hi @aduth,
In my tests, there is no difference between returning a null or empty string. In legacy widgets description is only used in the inspector, and empty string and null are both unrendered in React.

<PanelBody title={ widgetObject.name }>
{ widgetObject.description }
</PanelBody>

@jorgefilipecosta jorgefilipecosta added the [Type] Bug An existing feature does not function as intended label Mar 25, 2019
@jorgefilipecosta jorgefilipecosta merged commit f9027da into master Mar 25, 2019
@jorgefilipecosta jorgefilipecosta deleted the fix/problem-affecting-widgets-without-description branch March 25, 2019 14:43
@youknowriad youknowriad added this to the 5.4 (Gutenberg) milestone Mar 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants