WP_Customize_Widgets::parse_widget_id() WordPress Method
The WP_Customize_Widgets::parse_widget_id() method is used to parse a widget ID string into its parts. The parts are: - The base ID - The number - The ID suffix This method is used internally by the WordPress widget system and is not intended to be used by plugin or theme developers.
WP_Customize_Widgets::parse_widget_id( string $widget_id ) #
Converts a widget ID into its id_base and number components.
Parameters
- $widget_id
(string)(Required)Widget ID.
Return
(array) Array containing a widget's id_base and number components.
Source
File: wp-includes/class-wp-customize-widgets.php
public function parse_widget_id( $widget_id ) {
$parsed = array(
'number' => null,
'id_base' => null,
);
if ( preg_match( '/^(.+)-(\d+)$/', $widget_id, $matches ) ) {
$parsed['id_base'] = $matches[1];
$parsed['number'] = (int) $matches[2];
} else {
// Likely an old single widget.
$parsed['id_base'] = $widget_id;
}
return $parsed;
}
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
| Version | Description |
|---|---|
| 3.9.0 | Introduced. |