next_widget_id_number() WordPress Function

This function returns the next widget ID number. It is used internally by Wordpress to keep track of widget IDs.

next_widget_id_number( string $id_base ) #


Parameters

$id_base

(string)(Required)


Top ↑

Return

(int)


Top ↑

Source

File: wp-admin/includes/widgets.php

function next_widget_id_number( $id_base ) {
	global $wp_registered_widgets;
	$number = 1;

	foreach ( $wp_registered_widgets as $widget_id => $widget ) {
		if ( preg_match( '/' . preg_quote( $id_base, '/' ) . '-([0-9]+)$/', $widget_id, $matches ) ) {
			$number = max( $number, $matches[1] );
		}
	}
	$number++;

	return $number;
}

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.