mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Introduce support for array format field names in WP_Widget::get_field_name() and WP_Widget::get_field_id().
Fixes #12133 Props ch1902, welcher git-svn-id: https://develop.svn.wordpress.org/trunk@34780 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -177,11 +177,17 @@ class WP_Widget {
|
||||
*
|
||||
* This function should be used in form() methods to create name attributes for fields to be saved by update()
|
||||
*
|
||||
* @since 4.4.0 Array format field names are now accepted.
|
||||
*
|
||||
* @param string $field_name Field name
|
||||
* @return string Name attribute for $field_name
|
||||
*/
|
||||
public function get_field_name($field_name) {
|
||||
return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field_name . ']';
|
||||
if ( false === $pos = strpos( $field_name, '[' ) ) {
|
||||
return 'widget-' . $this->id_base . '[' . $this->number . '][' . $field_name . ']';
|
||||
} else {
|
||||
return 'widget-' . $this->id_base . '[' . $this->number . '][' . substr_replace( $field_name, '][', $pos, strlen( '[' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,6 +196,8 @@ class WP_Widget {
|
||||
* This function should be used in form() methods to create id attributes
|
||||
* for fields to be saved by {@see WP_Widget::update()}.
|
||||
*
|
||||
* @since 4.4.0 Array format field IDs are now accepted.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access public
|
||||
*
|
||||
@@ -197,7 +205,7 @@ class WP_Widget {
|
||||
* @return string ID attribute for `$field_name`.
|
||||
*/
|
||||
public function get_field_id( $field_name ) {
|
||||
return 'widget-' . $this->id_base . '-' . $this->number . '-' . $field_name;
|
||||
return 'widget-' . $this->id_base . '-' . $this->number . '-' . trim( str_replace( array( '[]', '[', ']' ), array( '', '-', '' ), $field_name ), '-' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user