WPML
Estado
Resuelto
Notificado para
Advanced Custom Fields Multilingual 2.0.3
Resuelto en
2.0.4
Plugin/tema relacionado
Advanced Custom Fields (ACF)
Etiquetas de temática
Bug

Resumen del problema

Al usar Advanced Custom Fields Pro y guardar una opción del tema con un campo de taxonomía, se produce el siguiente error fatal:

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)…

Solución alternativa

Por favor, haga una copia de seguridad completa de su sitio antes de continuar.


  1. Abra el archivo …/wp-content/plugins/acfml/classes/strategy/repeater-shuffle/OptionsPage.php.

  2. Busque la línea 88.

  3. Reemplace:
    	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 ] );
    		}
    	}

    Por:

    	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 ] );
    		}
    	}

Todos los problemas conocidos →