Skip to content

Saving empty multi-select field in group using term datasource causes PHP Fatal error #702

Open
@mboynes

Description

@mboynes

Steps to reproduce:

  1. Add the following code:

    add_action( 'fm_post_post', function() {
    	$fm = new \Fieldmanager_Group( [
    		'name' => 'group',
    		'children' => [
    			'field' => new \Fieldmanager_Select( [
    				'remove_default_meta_boxes' => true,
    				'multiple' => true,
    				'datasource' => new \Fieldmanager_Datasource_Term( [
    					'taxonomy' => 'category',
    					'only_save_to_taxonomy' => true,
    				] ),
    			] ),
    		],
    	] );
    	$fm->add_meta_box( 'Testing', 'post' );
    } );
  2. Add a post, don't select a category/deselect one if one is selected, and save the post.

This results in the following fatal error (with sample stack trace):

( ! ) Fatal error: Uncaught Error: Cannot unset string offsets in /var/www/wordpress/wp-content/plugins/wordpress-fieldmanager/php/class-fieldmanager-group.php on line 381
--



1 | 0.0019 | 423744 | {main}( ) | .../post.php:0
2 | 0.2893 | 4337392 | edit_post( ??? ) | .../post.php:194
3 | 0.3053 | 4409136 | wp_update_post( array(63), ??? ) | .../post.php:377
4 | 0.3075 | 4424976 | wp_insert_post( array(78), false ) | .../post.php:3654
5 | 0.3475 | 4783280 | do_action( string(9), long, object(WP_Post)[1615], true ) | .../post.php:3581
6 | 0.3475 | 4783656 | WP_Hook->do_action( array(3) ) | .../plugin.php:453
7 | 0.3475 | 4783656 | WP_Hook->apply_filters( string(0), array(3) ) | .../class-wp-hook.php:310
8 | 0.3478 | 4785344 | Fieldmanager_Context_Post->delegate_save_post( long ) | .../class-wp-hook.php:288
9 | 0.3478 | 4785344 | Fieldmanager_Context_Post->save_fields_for_post( long ) | .../class-fieldmanager-context-post.php:165
10 | 0.3480 | 4785560 | Fieldmanager_Context_Post->save_to_post_meta( long, ??? ) | .../class-fieldmanager-context-post.php:220
11 | 0.3480 | 4785560 | Fieldmanager_Context_Post->save( null ) | .../class-fieldmanager-context-post.php:255
12 | 0.3480 | 4785560 | Fieldmanager_Context_Post->save_field( object(Fieldmanager_Group)[932], null, long ) | .../class-fieldmanager-context-storable.php:52
13 | 0.3480 | 4786296 | Fieldmanager_Context_Post->prepare_data( string(1), null, object(Fieldmanager_Group)[932] ) | .../class-fieldmanager-context-storable.php:87
14 | 0.3481 | 4786296 | Fieldmanager_Group->presave_all( string(0), string(1) ) | .../class-fieldmanager-context.php:72
15 | 0.3481 | 4852208 | Fieldmanager_Group->presave( string(0), string(1) ) | .../class-fieldmanager-field.php:859

Relates to #701 and the same warnings/notices may appear as well.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions