Skip to content

Commit

Permalink
Resolve missing function from clone field (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
kraftbj authored Jan 12, 2025
1 parent 7bef182 commit 9815acc
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
75 changes: 75 additions & 0 deletions includes/fields/class-acf-field-clone.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,82 @@ public function get_cloned_fields( $field ) {
return $fields;
}

/**
* This function is run when cloning a clone field
* Important to run the acf_clone_field function on sub fields to pass on settings such as 'parent_layout'
*
* @type function
* @date 28/06/2016
* @since 5.3.8
*
* @param array $field The field array.
* @param array $clone_field The clone field array.
* @return array $field
*/
public function acf_clone_field( $field, $clone_field ) {

// bail early if this field is being cloned by some other kind of field (future proof)
if ( 'clone' !== $clone_field['type'] ) {
return $field;
}

// backup (used later)
// - backup only once (cloned clone fields can cause issues)
if ( ! isset( $field['__key'] ) ) {
$field['__key'] = $field['key'];
$field['__name'] = $field['_name'];
$field['__label'] = $field['label'];
}

// seamless
if ( 'seamless' === $clone_field['display'] ) {

// modify key
// - this will allow sub clone fields to correctly load values for the same cloned field
// - the original key will later be restored by acf/prepare_field allowing conditional logic JS to work
$field['key'] = $clone_field['key'] . '_' . $field['key'];

// modify prefix allowing clone field to save sub fields
// - only used for parent seamless fields. Block or sub field's prefix will be overriden which also works
$field['prefix'] = $clone_field['prefix'] . '[' . $clone_field['key'] . ']';

// modify parent
$field['parent'] = $clone_field['parent'];

// label_format
if ( $clone_field['prefix_label'] ) {
$field['label'] = $clone_field['label'] . ' ' . $field['label'];
}
}

// prefix_name
if ( $clone_field['prefix_name'] ) {

// modify the field name
// - this will allow field to load / save correctly
$field['name'] = $clone_field['name'] . '_' . $field['_name'];

// modify the field _name (orig name)
// - this will allow fields to correctly understand the modified field
if ( 'seamless' === $clone_field['display'] ) {
$field['_name'] = $clone_field['_name'] . '_' . $field['_name'];
}
}

// required
if ( $clone_field['required'] ) {
$field['required'] = 1;
}

// type specific
// note: seamless clone fields will not be triggered
if ( 'clone' === $field['type'] ) {
$field = $this->acf_clone_clone_field( $field, $clone_field );
}

// return
return $field;
}
/**
* This function is run when cloning a clone field
* Important to run the acf_clone_field function on sub fields to pass on settings such as 'parent_layout'
Expand Down
6 changes: 3 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: fields, custom fields, meta, scf
Requires at least: 6.0
Tested up to: 6.7
Requires PHP: 7.4
Stable tag: 6.4.1-beta5
Stable tag: 6.4.1-beta6
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -81,5 +81,5 @@ This plugin builds upon and is a fork of the previous work done by the contribut

== Upgrade Notice ==

= 6.4.1-beta5 =
Corrects some translation strings and now relies on the WordPress.org translation packs for Russian and Vietnamese.
= 6.4.1-beta6 =
Corrects issue where Options page would not display in wp-admin and a missing function from the Clone field.
4 changes: 2 additions & 2 deletions secure-custom-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Plugin Name: Secure Custom Fields
* Plugin URI: http://wordpress.org/plugins/secure-custom-fields/
* Description: Secure Custom Fields (SCF) offers an intuitive way for developers to enhance WordPress content management by adding extra fields and options without coding requirements.
* Version: 6.4.1-beta5
* Version: 6.4.1-beta6
* Author: WordPress.org
* Author URI: https://wordpress.org/
* Text Domain: secure-custom-fields
Expand Down Expand Up @@ -35,7 +35,7 @@ class ACF {
*
* @var string
*/
public $version = '6.4.1-beta5';
public $version = '6.4.1-beta6';

/**
* The plugin settings array.
Expand Down

0 comments on commit 9815acc

Please sign in to comment.