next_widget_id_number

The WordPress Core next widget id number function.

Description

(int) next_widget_id_number( (string) $id_base ); 

Returns (int)

Parameters (1)

0. $id_base (string)
The id base.

Usage

  1. if ( !function_exists( 'next_widget_id_number' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/widgets.php'; 
  3.  
  4. // The id base. 
  5. $id_base = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = next_widget_id_number($id_base); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/widgets.php  
  1. function next_widget_id_number( $id_base ) { 
  2. global $wp_registered_widgets; 
  3. $number = 1; 
  4.  
  5. foreach ( $wp_registered_widgets as $widget_id => $widget ) { 
  6. if ( preg_match( '/' . $id_base . '-([0-9]+)$/', $widget_id, $matches ) ) 
  7. $number = max($number, $matches[1]); 
  8. $number++; 
  9.  
  10. return $number;