WP_Widget::get_field_id()publicWP 2.8.0

Constructs id attributes for use in WP_Widget::form() fields.

This function should be used in form() methods to create id attributes for fields to be saved by WP_Widget::update().

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

Хуков нет.

Возвращает

Строку. ID attribute for $field_name.

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

$WP_Widget = new WP_Widget();
$WP_Widget->get_field_id( $field_name );
$field_name(строка) (обязательный)
Field name.

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

С версии 2.8.0 Введена.
С версии 4.4.0 Array format field IDs are now accepted.

Код WP_Widget::get_field_id() WP 6.5.2

public function get_field_id( $field_name ) {
	$field_name = str_replace( array( '[]', '[', ']' ), array( '', '-', '' ), $field_name );
	$field_name = trim( $field_name, '-' );

	return 'widget-' . $this->id_base . '-' . $this->number . '-' . $field_name;
}