- Trạng thái
- Đã giải quyết
- Được báo cáo cho
- Advanced Custom Fields Multilingual 2.0.3
- Đã giải quyết trong
- 2.0.4
- Plugin/giao diện liên quan
- Advanced Custom Fields (ACF)
- Thẻ chủ đề
- Bug
Tổng quan về lỗi
Khi sử dụng Advanced Custom Fields Pro và lưu một tùy chọn giao diện với một trường phân loại, lỗi nghiêm trọng sau đây xảy ra:
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:89Stack 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)…
Giải pháp tạm thời
Vui lòng tạo một bản sao lưu đầy đủ cho trang web của bạn trước khi tiếp tục.
- Mở tệp …/wp-content/plugins/acfml/classes/strategy/repeater-shuffle/OptionsPage.php.
- Tìm dòng 88.
- Thay thế:
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 ] ); } }Bằng:
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 ] ); } }