wp_parse_widget_id()WP 5.8.0

Converts a widget ID into its id_base and number components.

No Hooks.

Return

Array. Array containing a widget's id_base and number components.

Usage

wp_parse_widget_id( $id );
$id(string) (required)
Widget ID.

Changelog

Since 5.8.0 Introduced.

wp_parse_widget_id() code WP 6.4.3

function wp_parse_widget_id( $id ) {
	$parsed = array();

	if ( preg_match( '/^(.+)-(\d+)$/', $id, $matches ) ) {
		$parsed['id_base'] = $matches[1];
		$parsed['number']  = (int) $matches[2];
	} else {
		// Likely an old single widget.
		$parsed['id_base'] = $id;
	}

	return $parsed;
}