acf_field_flexible_content::should_disable_layoutprivateACF 6.5

Checks if a layout should be disabled based on the provided index and disabled layouts.

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

Хуков нет.

Возвращает

boolean.

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

// private - только в коде основоного (родительского) класса
$result = $this->should_disable_layout( $layout_index, $disabled_layouts ): bool;
$layout_index(int|строка) (обязательный)
The index of the layout to check.
$disabled_layouts(массив)
The array of disabled layout indices.
По умолчанию: array()

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

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

Код acf_field_flexible_content::should_disable_layout() ACF 6.8.8

private function should_disable_layout( $layout_index, $disabled_layouts = array() ): bool {
	// No disabled layouts provided, so no need to disable.
	if ( ! is_array( $disabled_layouts ) || empty( $disabled_layouts ) ) {
		return false;
	}

	// The layout is not in the disabled list, so no need to disable.
	if ( ! in_array( $layout_index, $disabled_layouts, true ) ) {
		return false;
	}

	if ( is_admin() ) {
		$args = acf_request_args(
			array(
				'action' => '',
				'query'  => '',
				'block'  => null,
			)
		);

		$wp_block_type = null;

		// If we are dealing with a flexible content field inside a block.
		if ( ! empty( $args['block'] ) ) {
			$block_data = json_decode( wp_unslash( $args['block'] ), true );

			if ( JSON_ERROR_NONE === json_last_error() && is_array( $block_data ) && isset( $block_data['name'] ) ) {
				$registry      = WP_Block_Type_Registry::get_instance();
				$wp_block_type = $registry->get_registered( $block_data['name'] );
			}
		}

		// If this is a block preview, disable the layout.
		if (
			// Blocks v2 preview check
			(
				$args['action'] === 'acf/ajax/fetch-block' &&
				! empty( $args['query']['preview'] ) &&
				( $wp_block_type && isset( $wp_block_type->acf_block_version ) && $wp_block_type->acf_block_version <= 2 )
			) ||
			// Blocks v3 preview check
			acf_get_data( 'acf_doing_block_preview' )
		) {
			return true;
		}

		// Editing a layout in the admin, so don't disable it.
		return false;
	}

	// The layout has been disabled, and we're on the frontend.
	return true;
}