[wp-trac] [WordPress Trac] #53625: The 'explode' function does not work on widget block editor.

WordPress Trac noreply at wordpress.org
Thu Jul 8 13:47:40 UTC 2021


#53625: The 'explode' function does not work on widget block editor.
------------------------------+-----------------------------
 Reporter:  subrataemfluence  |      Owner:  (none)
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Widgets           |    Version:  trunk
 Severity:  major             |   Keywords:  has-screenshots
  Focuses:  administration    |
------------------------------+-----------------------------
 The `explode()` function does not seem to be working on the new Widget
 block editor. I am testing it on the RC-2 version.

 I have created a simple widget that accepts Title, Description, and
 multiple selections from a Checkbox list items (Screenshots attached)

 On selecting checkboxes, the values form a comma-separated string (e.g.
 123456, 9822310, 457790 etc.) and stored in a textbox.

 Inside the `update()` function, I am exploding this string and storing the
 array as `$instance['groups']` element, which in turn gets saved in the
 database (`wp_options` table).

 The functionality works as expected if I have the `widgets-block-editor`
 support disabled. But when enabled, the `explode()` function is not
 working and nothing is in `$instance['groups]`.

 {{{#!php
 <?php
 public function update( $new_instance, $old_instance ) {
    $instance = $old_instance;

    $instance['title']  = strip_tags( $new_instance['title'] );
    $instance['about']  = strip_tags( $new_instance['about'] );

    $groups             = $new_instance['groups'];

    // the following line is not working and creating an empty array
    // when widgets-block-editor support is enabled.
    $instance['groups'] = array_pop ( explode( ',', $groups ) );


    return $instance;
 }
 }}}


 Database:


 {{{
 a:2:{i:2;a:3:{s:5:"title";s:15:"Product Channel";s:5:"about";s:41:"When
 you subscribe to our Product
 Channel";s:6:"groups";a:3:{i:0;s:6:"237500";i:1;s:6:"457844";}}s:12:"_multiwidget";i:1;}
 }}}


 However, the values get stored with block editor support enabled as a
 comma-separated string without the `explode()` function, i.e.


 {{{#!php
 <?php
 public function update( $new_instance, $old_instance ) {
    $instance = $old_instance;

    $instance['title']  = strip_tags( $new_instance['title'] );
    $instance['about']  = strip_tags( $new_instance['about'] );
    $instance['groups'] = $new_instance['groups'];

    return $instance;
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53625>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list