Skip to content

Commit 9815acc

Browse files
authored
Resolve missing function from clone field (#26)
1 parent 7bef182 commit 9815acc

File tree

3 files changed

+80
-5
lines changed

3 files changed

+80
-5
lines changed

includes/fields/class-acf-field-clone.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,82 @@ public function get_cloned_fields( $field ) {
224224
return $fields;
225225
}
226226

227+
/**
228+
* This function is run when cloning a clone field
229+
* Important to run the acf_clone_field function on sub fields to pass on settings such as 'parent_layout'
230+
*
231+
* @type function
232+
* @date 28/06/2016
233+
* @since 5.3.8
234+
*
235+
* @param array $field The field array.
236+
* @param array $clone_field The clone field array.
237+
* @return array $field
238+
*/
239+
public function acf_clone_field( $field, $clone_field ) {
240+
241+
// bail early if this field is being cloned by some other kind of field (future proof)
242+
if ( 'clone' !== $clone_field['type'] ) {
243+
return $field;
244+
}
245+
246+
// backup (used later)
247+
// - backup only once (cloned clone fields can cause issues)
248+
if ( ! isset( $field['__key'] ) ) {
249+
$field['__key'] = $field['key'];
250+
$field['__name'] = $field['_name'];
251+
$field['__label'] = $field['label'];
252+
}
253+
254+
// seamless
255+
if ( 'seamless' === $clone_field['display'] ) {
256+
257+
// modify key
258+
// - this will allow sub clone fields to correctly load values for the same cloned field
259+
// - the original key will later be restored by acf/prepare_field allowing conditional logic JS to work
260+
$field['key'] = $clone_field['key'] . '_' . $field['key'];
261+
262+
// modify prefix allowing clone field to save sub fields
263+
// - only used for parent seamless fields. Block or sub field's prefix will be overriden which also works
264+
$field['prefix'] = $clone_field['prefix'] . '[' . $clone_field['key'] . ']';
265+
266+
// modify parent
267+
$field['parent'] = $clone_field['parent'];
227268

269+
// label_format
270+
if ( $clone_field['prefix_label'] ) {
271+
$field['label'] = $clone_field['label'] . ' ' . $field['label'];
272+
}
273+
}
274+
275+
// prefix_name
276+
if ( $clone_field['prefix_name'] ) {
277+
278+
// modify the field name
279+
// - this will allow field to load / save correctly
280+
$field['name'] = $clone_field['name'] . '_' . $field['_name'];
281+
282+
// modify the field _name (orig name)
283+
// - this will allow fields to correctly understand the modified field
284+
if ( 'seamless' === $clone_field['display'] ) {
285+
$field['_name'] = $clone_field['_name'] . '_' . $field['_name'];
286+
}
287+
}
288+
289+
// required
290+
if ( $clone_field['required'] ) {
291+
$field['required'] = 1;
292+
}
293+
294+
// type specific
295+
// note: seamless clone fields will not be triggered
296+
if ( 'clone' === $field['type'] ) {
297+
$field = $this->acf_clone_clone_field( $field, $clone_field );
298+
}
299+
300+
// return
301+
return $field;
302+
}
228303
/**
229304
* This function is run when cloning a clone field
230305
* Important to run the acf_clone_field function on sub fields to pass on settings such as 'parent_layout'

readme.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: fields, custom fields, meta, scf
44
Requires at least: 6.0
55
Tested up to: 6.7
66
Requires PHP: 7.4
7-
Stable tag: 6.4.1-beta5
7+
Stable tag: 6.4.1-beta6
88
License: GPLv2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010

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

8282
== Upgrade Notice ==
8383

84-
= 6.4.1-beta5 =
85-
Corrects some translation strings and now relies on the WordPress.org translation packs for Russian and Vietnamese.
84+
= 6.4.1-beta6 =
85+
Corrects issue where Options page would not display in wp-admin and a missing function from the Clone field.

secure-custom-fields.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Plugin Name: Secure Custom Fields
77
* Plugin URI: http://wordpress.org/plugins/secure-custom-fields/
88
* 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.
9-
* Version: 6.4.1-beta5
9+
* Version: 6.4.1-beta6
1010
* Author: WordPress.org
1111
* Author URI: https://wordpress.org/
1212
* Text Domain: secure-custom-fields
@@ -35,7 +35,7 @@ class ACF {
3535
*
3636
* @var string
3737
*/
38-
public $version = '6.4.1-beta5';
38+
public $version = '6.4.1-beta6';
3939

4040
/**
4141
* The plugin settings array.

0 commit comments

Comments
 (0)