Created
October 9, 2025 12:51
-
-
Save rmpel/265b8eca0a9036b05526444b5bec1cc5 to your computer and use it in GitHub Desktop.
ACF-PHP File validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
function acf_add_local_field_group($data) { | |
foreach ( $data as $array_key => $array_value ) { | |
if ( is_array($array_value) ) { | |
acf_add_local_field_group( $array_value ); | |
} | |
else { | |
if ( 'key' === $array_key && false === strpos( $array_value, 'layout_' ) ) { | |
ensure_key_unique( $array_value ); | |
} | |
} | |
} | |
} | |
function ensure_key_unique( $key ) { | |
static $keys = []; | |
if ( '***RESET***' === $key ) { | |
$keys = []; return; | |
} | |
if ( in_array( $key, $keys ) ) { | |
print "$key is already defined, please repair this file.\n"; | |
} | |
$keys[] = $key; | |
} | |
function apply_filters( $filter_name, $value ) { | |
return $value; | |
} | |
function add_filter() { | |
// nop | |
} | |
function _x( $string ) { | |
return $string; | |
} | |
$directory = $argv[1] ?? __DIR__; | |
foreach ( glob("$directory/group_*php") as $acf_file ) { | |
print "Checking: $acf_file \n"; | |
include $acf_file; | |
ensure_key_unique( '***RESET***' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment