[wp-trac] [WordPress Trac] #53548: Widget Block: widget_id is undefined when a widget is placed
WordPress Trac
noreply at wordpress.org
Tue Jun 29 05:47:25 UTC 2021
#53548: Widget Block: widget_id is undefined when a widget is placed
------------------------------+-----------------------------
Reporter: subrataemfluence | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Widgets | Version: trunk
Severity: major | Keywords:
Focuses: administration |
------------------------------+-----------------------------
I am not sure whether this is already under discussion.
While playing with the new Widget block of 5.8 Beta 3, I got the following
notice:
Undefined index: widget_id
I am only trying to create an element inside the widget() method:
{{{#!php
<?php
public function widget( $args, $instance ) { ?>
<div id="element-$args['widget_id']">...</div>
<?php }
}}}
However, when I switch to the classic Widget page more, the error goes
away and a proper widget_id is returned.
{{{#!php
<?php
public function widget( $args, $instance ) {
if( ! isset( $args['widget_id'] ) ) { $args['widget_id'] = $this->id; }
?>
<div id="element-$args['widget_id']">...</div>
<?php }
}}}
The undefined notice does go away with the above modification, but
`$this->id` is always `-1`. In general, an element with ID like `element--
1`, is fine, but the problem starts when multiple instances of the same
widget are placed and JavaScript is unable to locate the right element.
The ID of each instance becomes the same.
How to grab the ID of the current widget while on a Block based widget
page?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53548>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list