WP_Customize_Widgets::parse_widget_id()publicWP 3.9.0

Converts a widget ID into its id_base and number components.

Метод класса: WP_Customize_Widgets{}

Хуков нет.

Возвращает

Массив. Array containing a widget's id_base and number components.

Использование

$WP_Customize_Widgets = new WP_Customize_Widgets();
$WP_Customize_Widgets->parse_widget_id( $widget_id );
$widget_id(строка) (обязательный)
Widget ID.

Список изменений

С версии 3.9.0 Введена.

Код WP_Customize_Widgets::parse_widget_id() WP 6.4.3

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