WC_Settings_Page::add_settings_ui_body_class │ public │ WC 10.9.0

Add a body class for settings pages rendered through the settings UI.

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

Хуков нет.

Возвращает

string. The modified body classes for the admin area.

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

$WC_Settings_Page = new WC_Settings_Page();
$WC_Settings_Page->add_settings_ui_body_class( $classes );
$classes(строка) (обязательный)
The existing body classes for the admin area.

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

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

Код WC_Settings_Page::add_settings_ui_body_class() WC 11.2.1

public function add_settings_ui_body_class( $classes ) {
	global $current_section, $current_tab;

	if ( ! is_string( $classes ) || $this->id !== $current_tab ) {
		return $classes;
	}

	$section = is_string( $current_section ) ? $current_section : '';
	$context = $this->get_settings_ui_request_context( $section );

	try {
		if ( ! $context || ! $context->is_rendering_enabled() ) {
			return $classes;
		}

		// Preflight and cache adapter failures before this body class can hide the classic Save button.
		$context->get_page_id();

		// The legacy fallback renderer needs the classic styling: the settings UI
		// body class hides the legacy Save button via CSS.
		if ( $context->has_schema_failed() || $context->has_script_handle_loading_failed() ) {
			return $classes;
		}

		$is_rendering_drill_down = $context->is_drill_down();
	} catch ( \Throwable $e ) {
		return $classes;
	}

	$body_classes = explode( ' ', $classes );

	if ( ! in_array( 'woocommerce-settings-ui-page', $body_classes, true ) ) {
		$classes       .= ' woocommerce-settings-ui-page';
		$body_classes[] = 'woocommerce-settings-ui-page';
	}

	if (
		$is_rendering_drill_down
		&& ! in_array( 'woocommerce-settings-ui-drill-down', $body_classes, true )
	) {
		$classes .= ' woocommerce-settings-ui-drill-down';
	}

	return $classes;
}