Plugin Directory

Changeset 3307536


Ignore:
Timestamp:
06/06/2025 12:58:25 PM (10 months ago)
Author:
kovalchik8
Message:

Added fields support for plugin ACF Extended : Advanced Link, Code Editor

Location:
magic-export-import
Files:
54 added
8 edited

Legend:

Unmodified
Added
Removed
  • magic-export-import/trunk/class-magic-ex-im-setup.php

    r3263554 r3307536  
    33 * Plugin Name: Magic Export & Import
    44 * Description: The ultimate tool to migrate any content including posts, terms, users, comments, WooCommerce shop orders and ACF Options pages.
    5  * Version: 1.0.3
     5 * Version: 1.0.4
    66 * Requires at least: 6.2
    77 * Requires PHP: 7.4
  • magic-export-import/trunk/includes/magic-ex-im-functions.php

    r3220340 r3307536  
    868868    return $parse_as ? $result[ $parse_as ] : $result;
    869869}
     870/**
     871 * Gets term ID based on the provided term slug and taxonomy.
     872 *
     873 * @param string $term_slug Term slug.
     874 * @param string $term_tax Taxonomy name.
     875 * @return int|false Term ID on success, false otherwise.
     876 */
     877function magic_im_term_id_by_slug( $term_slug, $term_tax ) {
     878
     879    $term_obj = get_term_by( 'slug', $term_slug, $term_tax );
     880
     881    if ( ! $term_obj ) {
     882        return false;
     883    }
     884
     885    return apply_filters( 'magic_im_item_data_taxonomy', $term_obj->term_id, $term_obj->taxonomy );
     886}
  • magic-export-import/trunk/includes/magic-types/class-magic-ex-im-type-posts.php

    r3220340 r3307536  
    337337
    338338                foreach ( $term_slugs_arr as $term_slug ) {
    339 
    340                     $term_id    = get_term_by( 'slug', $term_slug, $key )->term_id ?? '';
    341                     $term_ids[] = apply_filters( 'magic_im_item_data_taxonomy', $term_id, $key );
     339                    $term_ids[] = magic_im_term_id_by_slug( $term_slug, $key );
    342340                }
    343341
  • magic-export-import/trunk/includes/magic-types/class-magic-ex-im-type-terms.php

    r3220340 r3307536  
    142142            // Convert term slug into ID.
    143143            if ( 'term' === $key_group && 'parent' === $key && $value ) {
    144                 $term_id = get_term_by( 'slug', $value, $this->magic_item )->term_id ?? '';
    145                 $value   = apply_filters( 'magic_im_item_data_taxonomy', $term_id, $this->magic_item );
     144                $value = magic_im_term_id_by_slug( $value, $this->magic_item );
    146145            }
    147146        }
  • magic-export-import/trunk/includes/plugin-adapters/class-magic-ex-im-adapter-acf.php

    r3263554 r3307536  
    3232    public function magic_ex_im_init() {
    3333
    34             // Export / Import.
    35             add_filter( 'magic_ex_im_get_allowed_magic_items', array( $this, 'magic_ex_im_get_allowed_magic_items' ) );
    36 
    37             // Export.
    38             add_filter( 'magic_ex_get_key_group', array( $this, 'magic_ex_get_key_group' ), 10, 3 );
    39             add_filter( 'magic_ex_adjust_editor_value_gutenberg', array( $this, 'adjust_editor_value_gutenberg' ), 10, 1 );
    40             add_filter( 'magic_ex_keys', array( $this, 'magic_ex_keys' ) );
    41             add_filter( 'magic_ex_get_key_data', array( $this, 'magic_ex_get_key_data' ), 10, 3 );
    42             add_filter( 'magic_ex_maybe_adjust_value', array( $this, 'adjust_acf_value' ), 10, 3 );
    43 
    44             // Import.
    45             add_filter( 'magic_im_get_key_group', array( $this, 'magic_im_get_key_group' ), 10, 3 );
    46             add_filter( 'magic_im_adjust_editor_value_gutenberg', array( $this, 'adjust_editor_value_gutenberg' ), 10, 2 );
    47             add_filter( 'magic_im_maybe_adjust_value', array( $this, 'adjust_acf_value' ), 10, 3 );
    48             add_filter( 'magic_im_item_data_before_update', array( $this, 'magic_im_item_data_before_update' ) );
    49             remove_filter( 'content_save_pre', 'acf_parse_save_blocks', 5 );
     34        // Export / Import.
     35        add_filter( 'magic_ex_im_get_allowed_magic_items', array( $this, 'magic_ex_im_get_allowed_magic_items' ) );
     36
     37        // Export.
     38        add_filter( 'magic_ex_get_key_group', array( $this, 'magic_ex_get_key_group' ), 10, 3 );
     39        add_filter( 'magic_ex_adjust_editor_value_gutenberg', array( $this, 'adjust_editor_value_gutenberg' ), 10, 1 );
     40        add_filter( 'magic_ex_keys', array( $this, 'magic_ex_keys' ) );
     41        add_filter( 'magic_ex_get_key_data', array( $this, 'magic_ex_get_key_data' ), 10, 3 );
     42        add_filter( 'magic_ex_maybe_adjust_value', array( $this, 'adjust_acf_value' ), 10, 3 );
     43
     44        // Import.
     45        add_filter( 'magic_im_get_key_group', array( $this, 'magic_im_get_key_group' ), 10, 3 );
     46        add_filter( 'magic_im_adjust_editor_value_gutenberg', array( $this, 'adjust_editor_value_gutenberg' ), 10, 2 );
     47        add_filter( 'magic_im_maybe_adjust_value', array( $this, 'adjust_acf_value' ), 10, 3 );
     48        add_filter( 'magic_im_item_data_before_update', array( $this, 'magic_im_item_data_before_update' ) );
     49        remove_filter( 'content_save_pre', 'acf_parse_save_blocks', 5 );
    5050    }
    5151
     
    255255        if ( isset( $acf_field_object['type'] ) && $item_acf_id ) {
    256256
    257             // Get unformatted ACF field data (as it is stored in the database).
     257            // Get unformatted ACF field data (as it's stored in the database).
    258258            $key_data = get_field( $key, $item_acf_id, false );
    259259
     
    318318
    319319            switch ( $acf_field_type ) {
     320
     321                /**
     322                 * ACF Extended 'Advanced Link' field.
     323                 *
     324                 * @since 1.0.4
     325                 */
     326                case 'acfe_advanced_link':
     327                    switch ( $value['type'] ?? '' ) {
     328
     329                        case 'post':
     330                            $link_post = get_post( $value['value'] );
     331
     332                            if ( $link_post ) {
     333                                $value['value'] = sprintf( '%s:%s', $link_post->post_type, $link_post->post_name );
     334                            }
     335                            break;
     336
     337                        case 'term':
     338                            $link_term = get_term( $value['value'] );
     339
     340                            if ( $link_term ) {
     341                                $value['value'] = sprintf( '%s:%s', $link_term->taxonomy, $link_term->slug );
     342                            }
     343                            break;
     344                    }
     345                    break;
    320346
    321347                case 'textarea':
     
    378404            switch ( $acf_field_type ) {
    379405
     406                /**
     407                 * ACF Extended 'Advanced Link' field.
     408                 *
     409                 * @since 1.0.4
     410                 */
     411                case 'acfe_advanced_link':
     412                    switch ( $value['type'] ?? '' ) {
     413
     414                        case 'post':
     415                            if ( str_contains( $value['value'] ?? '', ':' ) ) {
     416                                list( $post_type, $post_name ) = explode( ':', $value['value'] );
     417                                $value['value']                = magic_im_post_id_by_name( $post_name, $post_type );
     418                            }
     419                            break;
     420
     421                        case 'term':
     422                            if ( str_contains( $value['value'] ?? '', ':' ) ) {
     423                                list( $term_tax, $term_slug ) = explode( ':', $value['value'] );
     424                                $value['value']               = magic_im_term_id_by_slug( $term_slug, $term_tax );
     425                            }
     426                            break;
     427                    }
     428                    break;
     429
     430                /**
     431                 * ACF Extended 'Code Editor' field.
     432                 *
     433                 * @since 1.0.4
     434                 */
     435                case 'acfe_code_editor':
    380436                case 'wysiwyg':
    381437                    $value = magic_im_adjust_editor_value( $value );
     
    432488                        // Convert term slug into term ID.
    433489                    } elseif ( 'taxonomy' === $acf_field_type ) {
    434 
    435                         $term_id = get_term_by( 'slug', $value, $acf_field_object['taxonomy'] )->term_id ?? false;
    436                         $value   = apply_filters( 'magic_im_item_data_taxonomy', $term_id, $acf_field_object['taxonomy'] );
     490                        $value = magic_im_term_id_by_slug( $value, $acf_field_object['taxonomy'] );
    437491
    438492                        // Convert post name into Post ID.
  • magic-export-import/trunk/includes/plugin-adapters/class-magic-ex-im-adapter-woocommerce.php

    r3240994 r3307536  
    590590            $value = array_map(
    591591                function ( $term_slug ) {
    592                     $term_id = get_term_by( 'slug', $term_slug, 'product_cat' )->term_id ?? '';
    593                     return apply_filters( 'magic_im_item_data_taxonomy', $term_id, 'product_cat' );
     592                    return magic_im_term_id_by_slug( $term_slug, 'product_cat' );
    594593                },
    595594                $value
  • magic-export-import/trunk/includes/plugin-adapters/class-magic-ex-im-adapter-yoast-seo.php

    r3220340 r3307536  
    185185                $term_slug = $item_data['meta'][ $meta_key ];
    186186                $tax_name  = str_replace( self::TAXONOMY_META_PREFIX, '', $meta_key );
    187                 $term_id   = get_term_by( 'slug', $term_slug, $tax_name )->term_id ?? '';
    188 
    189                 $item_data['meta'][ $meta_key ] = apply_filters( 'magic_im_item_data_taxonomy', $term_id, $tax_name );
     187
     188                $item_data['meta'][ $meta_key ] = magic_im_term_id_by_slug( $term_slug, $tax_name );
    190189            }
    191190        }
  • magic-export-import/trunk/readme.txt

    r3263554 r3307536  
    44Tags: export, import, content migration, csv, custom fields
    55Tested up to: 6.7
    6 Stable tag: 1.0.3
     6Stable tag: 1.0.4
    77License: GPL v3 or later
    88License URI: https://www.gnu.org/licenses/gpl-3.0.txt
     
    3434- Built-in support for popular plugins:
    3535  - Advanced Custom Fields (ACF)
     36  - Advanced Custom Fields: Extended
    3637  - WooCommerce
    3738  - Polylang
     
    7778== Changelog ==
    7879
     80= 1.0.4 =
     81* Added fields support for plugin ACF Extended : Advanced Link, Code Editor
     82
    7983= 1.0.3 =
    8084* Fixed ACF fields export with keeping unformatted values
Note: See TracChangeset for help on using the changeset viewer.