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

WordPress Trac noreply at wordpress.org
Fri Jul 16 14:07:58 UTC 2021


#53625: The 'explode' function does not work on widget block editor.
-------------------------------------------------+-------------------------
 Reporter:  subrataemfluence                     |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  closed
 Priority:  normal                               |   Milestone:
Component:  Widgets                              |     Version:  trunk
 Severity:  major                                |  Resolution:  invalid
 Keywords:  has-screenshots 2nd-opinion          |     Focuses:
  reporter-feedback                              |  administration
-------------------------------------------------+-------------------------

Comment (by subrataemfluence):

 Thanks for your detailed reply @zieladam . But IMO there is something
 wrong.

 I am trying to shorten down the area of interest in the code and only with
 editor support enabled. Please look at the following code snippet:

 {{{#!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']);

    // Please see the following lines...
    $instance['groups_str'] = $new_instance['groups'];
    $instance['groups'] = explode( ',', $new_instance['groups'] );
 }
 }}}


 The above code creates the following record in the database:


 {{{
 a:2:{i:2;a:4:{s:5:"title";s:18:"New Platform
 Title";s:5:"about";s:0:"";s:10:"groups_str";a:2:{i:0;s:6:"237500";i:1;s:6:"457844";}s:6:"groups";N;}s:12:"_multiwidget";i:1;}
 }}}


 Please note, the record saved has an array with the groups ID, i.e.
 `"groups_str";a:2:{i:0;s:6:"237500";i:1;s:6:"457844";}`

 But the most noticeable thing here is `$instance['groups_str']` is
 assigned the comma separated string value, not an array, but still it is
 saving the values as an array in the database!! While, I am expecting the
 `$instance['groups']` to have the array saved against it, but all I get is
 an **'N'**!

 Moving forward, if I take out one line (`$instance['groups'] = explode(
 ',', $new_instance['groups'] );`) from the above snippet to make the
 function to read:

 {{{#!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']);

    // Please see the following lines...
    $instance['groups_str'] = $new_instance['groups'];
 }
 }}}


 the record saved in the database is:


 {{{
 a:2:{i:2;a:3:{s:5:"title";s:18:"New Platform
 Title";s:5:"about";s:2:"wd";s:10:"groups_str";N;}s:12:"_multiwidget";i:1;}

 }}}

 **Please note. I did not change anything in the following line:**
 `$instance['groups_str'] = $new_instance['groups'];`.

 I believe there are issues and could be inspected more. At least this is
 what I am experiencing so far.

 My development environment:

 WordPress version: Beta RC-4
 Theme: 2021 (up to date)
 Plugins: Widget plugin I am building

 ''One more thing. The order of the arguments for update method was written
 wrong in my previous message, but they were correct in the code. Sorry for
 this confusion.''

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


More information about the wp-trac mailing list