WC_Admin_Settings::get_field_description()public staticWC 1.0

Helper function to get the formatted description and tip HTML for a given form field. Plugins can call this when implementing their own custom settings types.

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

Хуков нет.

Возвращает

Массив. The description and tip as a 2 element array.

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

$result = WC_Admin_Settings::get_field_description( $value );
$value(массив) (обязательный)
The form field value array.

Код WC_Admin_Settings::get_field_description() WC 8.7.0

public static function get_field_description( $value ) {
	$description  = '';
	$tooltip_html = '';

	if ( true === $value['desc_tip'] ) {
		$tooltip_html = $value['desc'];
	} elseif ( ! empty( $value['desc_tip'] ) ) {
		$description  = $value['desc'];
		$tooltip_html = $value['desc_tip'];
	} elseif ( ! empty( $value['desc'] ) ) {
		$description = $value['desc'];
	}

	$description_is_error    = $value['description_is_error'] ?? false;
	$extra_description_style = $description_is_error ? " style='color:red'" : '';

	if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ), true ) ) {
		$description = '<p style="margin-top:0">' . wp_kses_post( $description ) . '</p>';
	} elseif ( $description && in_array( $value['type'], array( 'checkbox' ), true ) ) {
		$description = wp_kses_post( $description );
	} elseif ( $description ) {
		$description = '<p class="description"' . $extra_description_style . '>' . wp_kses_post( $description ) . '</p>';
	}

	if ( $tooltip_html && in_array( $value['type'], array( 'checkbox' ), true ) ) {
		$tooltip_html = '<p class="description"' . $extra_description_style . '>' . $tooltip_html . '</p>';
	} elseif ( $tooltip_html ) {
		$tooltip_html = wc_help_tip( $tooltip_html );
	}

	return array(
		'description'  => $description,
		'tooltip_html' => $tooltip_html,
	);
}