Tribe__Events__Pro__Editor::gutenberg_custom_fields_canonical_keys( array $gutenberg_custom_fields )
Make sure the keys of the gutenberg custom fields match the same logic as the custom fields, this logic is basically if the key or index of a gutenberg field has _ at the start it means it belongs to an existing meta field and in order to have the right key we just need to remove the ‘_’ from the start on the other hand if does not have one it means it’s a new created field which requires to grab the highest max value available at this point and increase from there every time this scenario is presented.
Contents
Parameters
- $gutenberg_custom_fields
-
(array) (Required) An array with the gutenberg custom fields
Return
(array) An array with only number as index representing the location of the custom field block
Source
File: src/Tribe/Editor.php
public function gutenberg_custom_fields_canonical_keys( $gutenberg_custom_fields ) {
$max_index = $this->get_custom_fields_max_index();
$mapped = array();
foreach ( $gutenberg_custom_fields as $index => $field ) {
if ( 0 === strpos( $index, '_' ) ) {
$assigned_index = substr( $index, 1 );
} else {
$assigned_index = ++$max_index;
}
$mapped[ $assigned_index ] = $field;
}
return $mapped;
}
Changelog
| Version | Description |
|---|---|
| 4.5 | Introduced. |