wp_parse_widget_id() WordPress Function

The wp_parse_widget_id() function is used to parse a widget id. It accepts a single parameter, the id string. The function returns an array containing the id string and the number of the widget.

wp_parse_widget_id( string $id ) #

Converts a widget ID into its id_base and number components.


Parameters

$id

(string)(Required)Widget ID.


Top ↑

Return

(array) Array containing a widget's id_base and number components.


Top ↑

Source

File: wp-includes/widgets.php

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;
}


Top ↑

Changelog

Changelog
VersionDescription
5.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.