Automattic\WooCommerce\Internal\Admin\Settings

SettingsUISchema::get_group_actionsprivate staticWC 1.0

Normalize group header actions.

Method of the class: SettingsUISchema{}

No Hooks.

Returns

Array.

Usage

$result = SettingsUISchema::get_group_actions( $setting ): array;
$setting(array) (required)
Legacy title setting definition.

SettingsUISchema::get_group_actions() code WC 10.9.1

private static function get_group_actions( array $setting ): array {
	if ( empty( $setting['actions'] ) || ! is_array( $setting['actions'] ) ) {
		return array();
	}

	$actions = array();

	foreach ( $setting['actions'] as $index => $action ) {
		if ( ! is_array( $action ) || empty( $action['label'] ) || ! is_scalar( $action['label'] ) ) {
			continue;
		}

		$href = $action['href'] ?? $action['url'] ?? '';
		if ( ! is_scalar( $href ) || '' === (string) $href ) {
			continue;
		}

		$href = esc_url_raw( (string) $href );
		if ( '' === $href ) {
			continue;
		}

		$normalized_action = array(
			'id'    => isset( $action['id'] ) && is_scalar( $action['id'] ) ? sanitize_key( (string) $action['id'] ) : 'action_' . $index,
			'label' => wp_strip_all_tags( html_entity_decode( (string) $action['label'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ) ),
			'href'  => $href,
		);

		if ( isset( $action['variant'] ) && is_scalar( $action['variant'] ) ) {
			$normalized_action['variant'] = sanitize_key( (string) $action['variant'] );
		}

		if ( isset( $action['target'] ) && is_scalar( $action['target'] ) && in_array( (string) $action['target'], array( '_blank', '_self', '_parent', '_top' ), true ) ) {
			$normalized_action['target'] = (string) $action['target'];
		}

		if ( isset( $action['rel'] ) && is_scalar( $action['rel'] ) ) {
			$normalized_action['rel'] = sanitize_text_field( (string) $action['rel'] );
		}

		$actions[] = $normalized_action;
	}

	return $actions;
}