ACF_Admin_Field_Groups::render_admin_table_column_locations()publicACF 5.9.0

Displays a visual representation of the field group's locations.

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

Хуков нет.

Возвращает

null. Ничего.

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

$ACF_Admin_Field_Groups = new ACF_Admin_Field_Groups();
$ACF_Admin_Field_Groups->render_admin_table_column_locations( $field_group );
$field_group(массив) (обязательный)
The field group.

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

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

Код ACF_Admin_Field_Groups::render_admin_table_column_locations() ACF 6.0.4

public function render_admin_table_column_locations( $field_group ) {
	$objects = array();

	// Loop over location rules and determine connected object types.
	if ( $field_group['location'] ) {
		foreach ( $field_group['location'] as $i => $rules ) {

			// Determine object types for each rule.
			foreach ( $rules as $j => $rule ) {

				// Get location type and subtype for the current rule.
				$location                = acf_get_location_rule( $rule['param'] );
				$location_object_type    = '';
				$location_object_subtype = '';
				if ( $location ) {
					$location_object_type    = $location->get_object_type( $rule );
					$location_object_subtype = $location->get_object_subtype( $rule );
				}
				$rules[ $j ]['object_type']    = $location_object_type;
				$rules[ $j ]['object_subtype'] = $location_object_subtype;
			}

			// Now that each $rule conains object type data...
			$object_types = array_column( $rules, 'object_type' );
			$object_types = array_filter( $object_types );
			$object_types = array_values( $object_types );
			if ( $object_types ) {
				$object_type = $object_types[0];
			} else {
				continue;
			}

			$object_subtypes = array_column( $rules, 'object_subtype' );
			$object_subtypes = array_filter( $object_subtypes );
			$object_subtypes = array_values( $object_subtypes );
			$object_subtypes = array_map( 'acf_array', $object_subtypes );
			if ( count( $object_subtypes ) > 1 ) {
				$object_subtypes = call_user_func_array( 'array_intersect', $object_subtypes );
				$object_subtypes = array_values( $object_subtypes );
			} elseif ( $object_subtypes ) {
				$object_subtypes = $object_subtypes[0];
			} else {
				$object_subtypes = array( '' );
			}

			// Append to objects.
			foreach ( $object_subtypes as $object_subtype ) {
				$object = acf_get_object_type( $object_type, $object_subtype );
				if ( $object ) {
					$objects[ $object->name ] = $object;
				}
			}
		}
	}

	// Reset keys.
	$objects = array_values( $objects );

	// Display.
	$html = '';
	if ( $objects ) {
		$limit = 3;
		$total = count( $objects );

		// Icon.
		$html .= '<span class="dashicons ' . $objects[0]->icon . ( $total > 1 ? ' acf-multi-dashicon' : '' ) . '"></span>';

		// Labels.
		$labels = array_column( $objects, 'label' );
		$labels = array_slice( $labels, 0, 3 );
		$html  .= implode( ', ', $labels );

		// More.
		if ( $total > $limit ) {
			$html .= ', ...';
		}
	} else {
		$html = '<span class="dashicons dashicons-businesswoman"></span> ' . __( 'Various', 'acf' );
	}

	// Filter.
	echo acf_esc_html( $html );
}