Plugin Directory

Changeset 3255425


Ignore:
Timestamp:
03/13/2025 02:40:29 PM (13 months ago)
Author:
kovalchik8
Message:

Fixed ACF oembed field type

Location:
magic-export-import
Files:
55 added
2 edited

Legend:

Unmodified
Added
Removed
  • magic-export-import/trunk/includes/plugin-adapters/class-magic-ex-im-adapter-acf.php

    r3220340 r3255425  
    293293            switch ( $acf_field_type ) {
    294294
     295                case 'oembed':
    295296                case 'textarea':
    296                     $new_lines = $acf_field_object['new_lines'] ?? '';
    297 
    298                     if ( 'br' === $new_lines ) {
    299                         $value = str_replace( array( '<br>', '<br/>', '<br />' ), '', $value );
    300 
    301                     } elseif ( 'wpautop' === $new_lines ) {
    302                         $value = str_replace( array( '<p>', '</p>' ), array( '', "\n" ), $value );
    303                     }
     297                    $value = $this->get_unformatted_acf_value( $key, $acf_field_object['key'] );
    304298                    break;
    305299
     
    628622        return $acf_field_key;
    629623    }
     624
     625    /**
     626     * Gets unformatted ACF value.
     627     *
     628     * @param string $parent_field_name  Field name to search in.
     629     * @param string $field_key   The key to look for.
     630     * @param array  $unformatted_arr   Array to find in.
     631     * @return mixed|null   The value if found, null otherwise or value as it is if it's not array.
     632     */
     633    private function get_unformatted_acf_value( $parent_field_name, $field_key, $unformatted_arr = null ) {
     634
     635        $unformatted_arr ??= get_field( $parent_field_name, $this->get_item_acf_id( $parent_field_name ), false );
     636
     637        // If the input is not an array, return it as is.
     638        if ( ! is_array( $unformatted_arr ) ) {
     639            return $unformatted_arr;
     640        }
     641
     642        // If the key exists directly in the array, return its value.
     643        if ( isset( $unformatted_arr[ $field_key ] ) ) {
     644            return $unformatted_arr[ $field_key ];
     645        }
     646
     647        // Otherwise, search recursively in all array elements that are arrays.
     648        foreach ( $unformatted_arr as $value ) {
     649            if ( is_array( $value ) ) {
     650                $result = $this->get_unformatted_acf_value( $parent_field_name, $field_key, $value );
     651                if ( null !== $result ) {
     652                    return $result;
     653                }
     654            }
     655        }
     656
     657        return null;
     658    }
    630659}
    631660
  • magic-export-import/trunk/readme.txt

    r3240994 r3255425  
    44Tags: export, import, content migration, csv, custom fields
    55Tested up to: 6.7
    6 Stable tag: 1.0.2
     6Stable tag: 1.0.3
    77License: GPL v3 or later
    88License URI: https://www.gnu.org/licenses/gpl-3.0.txt
     
    7777== Changelog ==
    7878
     79= 1.0.3 =
     80* Fixed ACF oembed field type
     81
    7982= 1.0.2 =
    8083* Fixed WooCommerce HPOS Identification for shop orders import
Note: See TracChangeset for help on using the changeset viewer.