alleyinteractive / alleyinteractive/wordpress-fieldmanager

Saving empty multi-select field in group causes PHP Warnings/Notices

Đang mở
#701 0 bình luận 0 reaction 1 người được giao Được @mslinnea nhận Xem trên GitHub
bug scope:field
Ngôn ngữ chính
PHP
Star
563
Fork
99
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

## Steps to reproduce:

1. Add the following code:

```php
add_action( 'fm_post_post', function() {
$fm = new Fieldmanager_Group( [
'name' => 'group',
'children' => [
'field' => new Fieldmanager_Select( [
'multiple' => true,
'options' => [ 'One', 'Two' ],
] ),
],
] );
$fm->add_meta_box( 'Testing', 'post' );
} );
```

2. Add a post, don't select an option/deselect one if one is selected, and save the post.

This results in the following warnings and notices (with sample stack trace):

```
( ! ) Warning: Illegal string offset 'field' in /var/www/wordpress/wp-content/plugins/wordpress-fieldmanager/php/class-fieldmanager-group.php on line 359
--

1 | 0.0026 | 424224 | {main}( ) | .../post.php:0
2 | 0.2975 | 4330736 | edit_post( ??? ) | .../post.php:194
3 | 0.3057 | 4386312 | wp_update_post( array(67), ??? ) | .../post.php:377
4 | 0.3072 | 4401864 | wp_insert_post( array(81), false ) | .../post.php:3654
5 | 0.3320 | 4741056 | do_action( string(9), long, object(WP_Post)[1581], true ) | .../post.php:3581
6 | 0.3320 | 4741432 | WP_Hook->do_action( array(3) ) | .../plugin.php:453
7 | 0.3320 | 4741432 | WP_Hook->apply_filters( string(0), array(3) ) | .../class-wp-hook.php:310
8 | 0.3321 | 4743120 | Fieldmanager_Context_Post->delegate_save_post( long ) | .../class-wp-hook.php:288
9 | 0.3321 | 4743120 | Fieldmanager_Context_Post->save_fields_for_post( long ) | .../class-fieldmanager-context-post.php:165
10 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save_to_post_meta( long, ??? ) | .../class-fieldmanager-context-post.php:220
11 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save( null ) | .../class-fieldmanager-context-post.php:255
12 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save_field( object(Fieldmanager_Group)[932], null, long ) | .../class-fieldmanager-context-storable.php:52
13 | 0.3323 | 4745032 | Fieldmanager_Context_Post->prepare_data( string(0), null, object(Fieldmanager_Group)[932] ) | .../class-fieldmanager-context-storable.php:87
14 | 0.3323 | 4745032 | Fieldmanager_Group->presave_all( string(0), string(0) ) | .../class-fieldmanager-context.php:72
15 | 0.3323 | 4745408 | Fieldmanager_Group->presave( string(0), string(0) ) | .../class-fieldmanager-field.php:859

( ! ) Warning: Cannot assign an empty string to a string offset in /var/www/wordpress/wp-content/plugins/wordpress-fieldmanager/php/class-fieldmanager-group.php on line 359
--

1 | 0.0026 | 424224 | {main}( ) | .../post.php:0
2 | 0.2975 | 4330736 | edit_post( ??? ) | .../post.php:194
3 | 0.3057 | 4386312 | wp_update_post( array(67), ??? ) | .../post.php:377
4 | 0.3072 | 4401864 | wp_insert_post( array(81), false ) | .../post.php:3654
5 | 0.3320 | 4741056 | do_action( string(9), long, object(WP_Post)[1581], true ) | .../post.php:3581
6 | 0.3320 | 4741432 | WP_Hook->do_action( array(3) ) | .../plugin.php:453
7 | 0.3320 | 4741432 | WP_Hook->apply_filters( string(0), array(3) ) | .../class-wp-hook.php:310
8 | 0.3321 | 4743120 | Fieldmanager_Context_Post->delegate_save_post( long ) | .../class-wp-hook.php:288
9 | 0.3321 | 4743120 | Fieldmanager_Context_Post->save_fields_for_post( long ) | .../class-fieldmanager-context-post.php:165
10 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save_to_post_meta( long, ??? ) | .../class-fieldmanager-context-post.php:220
11 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save( null ) | .../class-fieldmanager-context-post.php:255
12 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save_field( object(Fieldmanager_Group)[932], null, long ) | .../class-fieldmanager-context-storable.php:52
13 | 0.3323 | 4745032 | Fieldmanager_Context_Post->prepare_data( string(0), null, object(Fieldmanager_Group)[932] ) | .../class-fieldmanager-context-storable.php:87
14 | 0.3323 | 4745032 | Fieldmanager_Group->presave_all( string(0), string(0) ) | .../class-fieldmanager-context.php:72
15 | 0.3323 | 4745408 | Fieldmanager_Group->presave( string(0), string(0) ) | .../class-fieldmanager-field.php:859

( ! ) Warning: Illegal string offset 'field' in /var/www/wordpress/wp-content/plugins/wordpress-fieldmanager/php/class-fieldmanager-group.php on line 369
--

1 | 0.0026 | 424224 | {main}( ) | .../post.php:0
2 | 0.2975 | 4330736 | edit_post( ??? ) | .../post.php:194
3 | 0.3057 | 4386312 | wp_update_post( array(67), ??? ) | .../post.php:377
4 | 0.3072 | 4401864 | wp_insert_post( array(81), false ) | .../post.php:3654
5 | 0.3320 | 4741056 | do_action( string(9), long, object(WP_Post)[1581], true ) | .../post.php:3581
6 | 0.3320 | 4741432 | WP_Hook->do_action( array(3) ) | .../plugin.php:453
7 | 0.3320 | 4741432 | WP_Hook->apply_filters( string(0), array(3) ) | .../class-wp-hook.php:310
8 | 0.3321 | 4743120 | Fieldmanager_Context_Post->delegate_save_post( long ) | .../class-wp-hook.php:288
9 | 0.3321 | 4743120 | Fieldmanager_Context_Post->save_fields_for_post( long ) | .../class-fieldmanager-context-post.php:165
10 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save_to_post_meta( long, ??? ) | .../class-fieldmanager-context-post.php:220
11 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save( null ) | .../class-fieldmanager-context-post.php:255
12 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save_field( object(Fieldmanager_Group)[932], null, long ) | .../class-fieldmanager-context-storable.php:52
13 | 0.3323 | 4745032 | Fieldmanager_Context_Post->prepare_data( string(0), null, object(Fieldmanager_Group)[932] ) | .../class-fieldmanager-context-storable.php:87
14 | 0.3323 | 4745032 | Fieldmanager_Group->presave_all( string(0), string(0) ) | .../class-fieldmanager-context.php:72
15 | 0.3323 | 4745408 | Fieldmanager_Group->presave( string(0), string(0) ) | .../class-fieldmanager-field.php:859

( ! ) Notice: Uninitialized string offset: 0 in /var/www/wordpress/wp-content/plugins/wordpress-fieldmanager/php/class-fieldmanager-group.php on line 369
--

1 | 0.0026 | 424224 | {main}( ) | .../post.php:0
2 | 0.2975 | 4330736 | edit_post( ??? ) | .../post.php:194
3 | 0.3057 | 4386312 | wp_update_post( array(67), ??? ) | .../post.php:377
4 | 0.3072 | 4401864 | wp_insert_post( array(81), false ) | .../post.php:3654
5 | 0.3320 | 4741056 | do_action( string(9), long, object(WP_Post)[1581], true ) | .../post.php:3581
6 | 0.3320 | 4741432 | WP_Hook->do_action( array(3) ) | .../plugin.php:453
7 | 0.3320 | 4741432 | WP_Hook->apply_filters( string(0), array(3) ) | .../class-wp-hook.php:310
8 | 0.3321 | 4743120 | Fieldmanager_Context_Post->delegate_save_post( long ) | .../class-wp-hook.php:288
9 | 0.3321 | 4743120 | Fieldmanager_Context_Post->save_fields_for_post( long ) | .../class-fieldmanager-context-post.php:165
10 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save_to_post_meta( long, ??? ) | .../class-fieldmanager-context-post.php:220
11 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save( null ) | .../class-fieldmanager-context-post.php:255
12 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save_field( object(Fieldmanager_Group)[932], null, long ) | .../class-fieldmanager-context-storable.php:52
13 | 0.3323 | 4745032 | Fieldmanager_Context_Post->prepare_data( string(0), null, object(Fieldmanager_Group)[932] ) | .../class-fieldmanager-context-storable.php:87
14 | 0.3323 | 4745032 | Fieldmanager_Group->presave_all( string(0), string(0) ) | .../class-fieldmanager-context.php:72
15 | 0.3323 | 4745408 | Fieldmanager_Group->presave( string(0), string(0) ) | .../class-fieldmanager-field.php:859

( ! ) Warning: Illegal string offset 'field' in /var/www/wordpress/wp-content/plugins/wordpress-fieldmanager/php/class-fieldmanager-group.php on line 369
--

1 | 0.0026 | 424224 | {main}( ) | .../post.php:0
2 | 0.2975 | 4330736 | edit_post( ??? ) | .../post.php:194
3 | 0.3057 | 4386312 | wp_update_post( array(67), ??? ) | .../post.php:377
4 | 0.3072 | 4401864 | wp_insert_post( array(81), false ) | .../post.php:3654
5 | 0.3320 | 4741056 | do_action( string(9), long, object(WP_Post)[1581], true ) | .../post.php:3581
6 | 0.3320 | 4741432 | WP_Hook->do_action( array(3) ) | .../plugin.php:453
7 | 0.3320 | 4741432 | WP_Hook->apply_filters( string(0), array(3) ) | .../class-wp-hook.php:310
8 | 0.3321 | 4743120 | Fieldmanager_Context_Post->delegate_save_post( long ) | .../class-wp-hook.php:288
9 | 0.3321 | 4743120 | Fieldmanager_Context_Post->save_fields_for_post( long ) | .../class-fieldmanager-context-post.php:165
10 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save_to_post_meta( long, ??? ) | .../class-fieldmanager-context-post.php:220
11 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save( null ) | .../class-fieldmanager-context-post.php:255
12 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save_field( object(Fieldmanager_Group)[932], null, long ) | .../class-fieldmanager-context-storable.php:52
13 | 0.3323 | 4745032 | Fieldmanager_Context_Post->prepare_data( string(0), null, object(Fieldmanager_Group)[932] ) | .../class-fieldmanager-context-storable.php:87
14 | 0.3323 | 4745032 | Fieldmanager_Group->presave_all( string(0), string(0) ) | .../class-fieldmanager-context.php:72
15 | 0.3323 | 4745408 | Fieldmanager_Group->presave( string(0), string(0) ) | .../class-fieldmanager-field.php:859

( ! ) Notice: Array to string conversion in /var/www/wordpress/wp-content/plugins/wordpress-fieldmanager/php/class-fieldmanager-group.php on line 369
--

1 | 0.0026 | 424224 | {main}( ) | .../post.php:0
2 | 0.2975 | 4330736 | edit_post( ??? ) | .../post.php:194
3 | 0.3057 | 4386312 | wp_update_post( array(67), ??? ) | .../post.php:377
4 | 0.3072 | 4401864 | wp_insert_post( array(81), false ) | .../post.php:3654
5 | 0.3320 | 4741056 | do_action( string(9), long, object(WP_Post)[1581], true ) | .../post.php:3581
6 | 0.3320 | 4741432 | WP_Hook->do_action( array(3) ) | .../plugin.php:453
7 | 0.3320 | 4741432 | WP_Hook->apply_filters( string(0), array(3) ) | .../class-wp-hook.php:310
8 | 0.3321 | 4743120 | Fieldmanager_Context_Post->delegate_save_post( long ) | .../class-wp-hook.php:288
9 | 0.3321 | 4743120 | Fieldmanager_Context_Post->save_fields_for_post( long ) | .../class-fieldmanager-context-post.php:165
10 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save_to_post_meta( long, ??? ) | .../class-fieldmanager-context-post.php:220
11 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save( null ) | .../class-fieldmanager-context-post.php:255
12 | 0.3323 | 4744616 | Fieldmanager_Context_Post->save_field( object(Fieldmanager_Group)[932], null, long ) | .../class-fieldmanager-context-storable.php:52
13 | 0.3323 | 4745032 | Fieldmanager_Context_Post->prepare_data( string(0), null, object(Fieldmanager_Group)[932] ) | .../class-fieldmanager-context-storable.php:87
14 | 0.3323 | 4745032 | Fieldmanager_Group->presave_all( string(0), string(0) ) | .../class-fieldmanager-context.php:72
15 | 0.3323 | 4745408 | Fieldmanager_Group->presave( string(0), string(0) ) | .../class-fieldmanager-field.php:859
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.