ACF_Field_User::format_value_for_jsonld
Formats the field value for JSON-LD output.
Method of the class: ACF_Field_User{}
No Hooks.
Returns
mixed.
Usage
$ACF_Field_User = new ACF_Field_User(); $ACF_Field_User->format_value_for_jsonld( $value, $post_id, $field );
- $value(mixed) (required)
- The value of the field.
- $post_id(int|string) (required)
- The ID of the post.
- $field(array) (required)
- The field array.
Changelog
| Since 6.8.0 | Introduced. |
ACF_Field_User::format_value_for_jsonld() ACF Field User::format value for jsonld code ACF 6.8.8
public function format_value_for_jsonld( $value, $post_id, $field ) {
if ( empty( $value ) ) {
return null;
}
// Get output format with fallback.
$output_format = $field['schema_output_format'] ?? '';
if ( empty( $output_format ) ) {
$property = $field['schema_property'] ?? '';
$output_format = \ACF\AI\GEO\Schema::get_default_output_format( $this->name, $property );
}
// Default to Person if still empty.
if ( empty( $output_format ) ) {
$output_format = 'Person';
}
$field['return_format'] = 'object';
$users = $this->format_value( $value, $post_id, $field );
if ( ! $users ) {
return null;
}
// Handle single user.
if ( $users instanceof \WP_User ) {
return $this->format_user_for_jsonld( $users, $output_format );
}
// Handle multiple users.
$formatted = array();
if ( is_array( $users ) ) {
foreach ( $users as $user ) {
if ( $user instanceof \WP_User ) {
$formatted[] = $this->format_user_for_jsonld( $user, $output_format );
}
}
}
return $formatted;
}