-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript-cli.php
More file actions
32 lines (28 loc) · 1.06 KB
/
script-cli.php
File metadata and controls
32 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
// file: set-copy-once.php
$mode = 'copy_once'; // ignore | copy_once | translate | synchronize
$targetType = 'image'; // image | file | text | textarea | wysiwyg | ... | * (all fields)
require_once ABSPATH . 'wp-load.php';
function recurse_update( array $field, string $mode, string $targetType ): array {
// if type matches or update all is needed
if ( $targetType === '*' || $field['type'] === $targetType ) {
$field['translations'] = $mode;
acf_update_field( $field );
WP_CLI::log( "✔ {$field['key']} ⇒ {$mode}" );
}
// process sub-fields (group, repeater, flexible)
if ( ! empty( $field['sub_fields'] ) ) {
foreach ( $field['sub_fields'] as &$sub ) {
$sub = recurse_update( $sub, $mode, $targetType );
}
}
return $field;
}
$groups = acf_get_field_groups();
foreach ( $groups as $group ) {
$fields = acf_get_fields( $group['key'] );
foreach ( $fields as $field ) {
recurse_update( $field, $mode, $targetType );
}
}
WP_CLI::success( 'Done.' );