ACF_Field_User::format_value_for_jsonld │ public │ ACF 6.8.0

Formats the field value for JSON-LD output.

Метод класса: ACF_Field_User{}

Хуков нет.

Возвращает

mixed.

Использование

$ACF_Field_User = new ACF_Field_User();
$ACF_Field_User->format_value_for_jsonld( $value, $post_id, $field );
$value(разное) (обязательный)
The value of the field.
$post_id(int|строка) (обязательный)
The ID of the post.
$field(массив) (обязательный)
The field array.

Список изменений

С версии 6.8.0 Введена.

Код ACF_Field_User::format_value_for_jsonld() ACF 6.8.11

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;
}