Skip Navigation

Resolved

Reported for: Advanced Custom Fields Multilingual 2.0.3

Resolved in: 2.0.4

Topic Tags: Bug

Overview of the issue

When using Advanced Custom Fields Pro and saving a theme option with a taxonomy field, the followign fatal error occurs:

PHP Fatal error: Uncaught Error: Cannot use object of type WP_Term as array in …\wp-content\plugins\acfml\classes\strategy\repeater-shuffle\OptionsPage.php:89
Stack trace:
#0 …\wp-content\plugins\acfml\classes\strategy\repeater-shuffle\OptionsPage.php(75): ACFML\Repeater\Shuffle\OptionsPage->addNormalizedValuesForFieldState(Array, ”, ‘my_taxo_term’, Object(WP_Term))
…\plugins\acfml\classes\class-wpml-acf-field-state.php(57): ACFML\Repeater\Shuffle\OptionsPage->getAllMeta(‘options’)
…\plugins\acfml\classes\class-wpml-acf-field-state.php(41): ACFML\FieldState->getCurrentMetadata(‘options’)
…\class-wp-hook.php(308): ACFML\FieldState->storeStateBefore(‘options’)
…\class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array)
…\plugin.php(517): WP_Hook->do_action(Array)…

Workaround

Please, make a full backup of your site before proceeding.

  1. Open the …/wp-content/plugins/acfml/classes/strategy/repeater-shuffle/OptionsPage.php file.
  2. Look for line 88.
  3. Replace:
    	private function addNormalizedValuesForFieldState( $options, $prefix, $key, $value ) {
    		if ( $value instanceof WP_Post || isset( $value['ID'] ) ) {
    			return array_merge( $options, [ "${prefix}${key}" => Obj::prop( 'ID', $value ) ] );
    		} elseif ( $this->isArrayOfStrings( $value ) ) {
    			return array_merge( $options, [ "${prefix}${key}" => $value ] );
    		} elseif ( is_array( $value ) ) {
    			foreach ( $value as $index => $item ) {
    				if ( is_numeric( $index ) ) {
    					foreach ( $item as $field => $field_value ) {
    						$options = array_merge( $options, $this->addNormalizedValuesForFieldState( $options, "${prefix}${key}_${index}_", $field, $field_value ) );
    					}
    				} else {
    					$options = $this->addNormalizedValuesForFieldState( $options, "${prefix}${key}_", $index, $item );
    				}
    			}
    			return $options;
    		} else {
    			return array_merge( $options, [ "${prefix}${key}" => $value ] );
    		}
    	}
    

    With:

    	private function addNormalizedValuesForFieldState( $options, $prefix, $key, $value ) {
    		if ( $value instanceof WP_Post || is_array($value) && isset( $value['ID'] ) ) {
    			return array_merge( $options, [ "${prefix}${key}" => Obj::prop( 'ID', $value ) ] );
    		} elseif ( $value instanceof WP_Term || isset( $value->term_id ) ) {
    			return array_merge( $options, [ "${prefix}${key}" => Obj::prop( 'term_id', $value ) ] );
    		} elseif ( $this->isArrayOfStrings( $value ) ) {
    			return array_merge( $options, [ "${prefix}${key}" => $value ] );
    		}  elseif ( is_array( $value ) ) {
    			foreach ( $value as $index => $item ) {
    				if ( is_numeric( $index ) ) {
    					foreach ( $item as $field => $field_value ) {
    						$options = array_merge( $options, $this->addNormalizedValuesForFieldState( $options, "${prefix}${key}_${index}_", $field, $field_value ) );
    					}
    				} else {
    					$options = $this->addNormalizedValuesForFieldState( $options, "${prefix}${key}_", $index, $item );
    				}
    			}
    
    			return $options;
    		} else {
    			return array_merge( $options, [ "${prefix}${key}" => $value ] );
    		}
    	}