WPML
Statut
Résolu
Signalé pour
Advanced Custom Fields Multilingual 2.0.3
Résolu dans
2.0.4
Extension/thème associé
Advanced Custom Fields (ACF)
Étiquettes de sujet
Bug

Aperçu de l’anomalie

Lors de l’utilisation d’Advanced Custom Fields Pro et de l’enregistrement d’une option de thème avec un champ de taxonomie, l’erreur fatale suivante se produit :

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

Solution de contournement

Faites une sauvegarde complète de votre site avant de continuer.


  1. Ouvrez le fichier …/wp-content/plugins/acfml/classes/strategy/repeater-shuffle/OptionsPage.php.

  2. Cherchez la ligne 88.

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

    Par :

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

Toutes les anomalies connues →