GC_Customize_Widgets::parse_widget_id()

最后更新于:2021-11-27 11:33:24

GC_Customize_Widgets::parse_widget_id( string$widget_id)

Converts a widget ID into its id_base and number components.

参数

$widget_id

(string) (Required) Widget ID.

响应

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

源文件

文件: gc-includes/class-gc-customize-widgets.php

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