WP_Widget::get_field_name( string $field_name ): string
Constructs name attributes for use in form() fields
Description
This function should be used in form() methods to create name attributes for fields to be saved by update()
Parameters
-
$field_name
string Required -
Field name.
Return
string Name attribute for $field_name
.
Source
File: wp-includes/class-wp-widget.php
.
View all references
public function get_field_name( $field_name ) {
$pos = strpos( $field_name, '[' );
if ( false !== $pos ) {
// Replace the first occurrence of '[' with ']['.
$field_name = '[' . substr_replace( $field_name, '][', $pos, strlen( '[' ) );
} else {
$field_name = '[' . $field_name . ']';
}
return 'widget-' . $this->id_base . '[' . $this->number . ']' . $field_name;
}
Changelog
Version | Description |
---|---|
4.4.0 | Array format field names are now accepted. |
2.8.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
Example