Skip to content

Commit

Permalink
valid Mai ACF fields
Browse files Browse the repository at this point in the history
For #651
  • Loading branch information
JiveDig committed Jul 11, 2024
1 parent cd05fea commit 1fc0f67
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/fields/validate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Mai Engine.
*
* @package BizBudding\MaiEngine
* @link https://bizbudding.com
* @author BizBudding
* @copyright Copyright © 2020 BizBudding
* @license GPL-2.0-or-later
*/

// Prevent direct file access.
defined( 'ABSPATH' ) || die;

add_filter( 'acf/is_field_key', 'mai_acf_is_field_key', 10, 2 );
/**
* Checks if a field key is a valid ACF field key.
* We need this because we wrongly used custom field keys that don't start with `field_`.
* Our engine blocks use `mai_` and plugin blocks use `maicca_', `maipub_`, etc., so we check for `mai`.
*
* @since TBD
*
* @param bool $bool The result.
* @param string $id The identifier.
*
* @return bool
*/
function mai_acf_is_field_key( $bool, $id ) {
// Bail if already true.
if ( $bool ) {
return $bool;
}

return $id && str_starts_with( $id, 'mai' );
}
1 change: 1 addition & 0 deletions lib/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ function mai_load_files() {
'fields/icons',
'fields/wp-query',
'fields/wp-term-query',
'fields/validate',

// Blocks.
'blocks/general',
Expand Down

0 comments on commit 1fc0f67

Please sign in to comment.