WP_Customize_Widgets::parse_widget_setting_id() WordPress Method

The parse_widget_setting_id() method is used to parse the widget setting id. It accepts a widget setting id and an array of widget setting ids as parameters. The method returns an array of parsed widget setting ids.

WP_Customize_Widgets::parse_widget_setting_id( string $setting_id ) #

Converts a widget setting ID (option path) to its id_base and number components.


Parameters

$setting_id

(string)(Required)Widget setting ID.


Top ↑

Return

(array|WP_Error) Array containing a widget's id_base and number components, or a WP_Error object.


Top ↑

Source

File: wp-includes/class-wp-customize-widgets.php

	public function parse_widget_setting_id( $setting_id ) {
		if ( ! preg_match( '/^(widget_(.+?))(?:\[(\d+)\])?$/', $setting_id, $matches ) ) {
			return new WP_Error( 'widget_setting_invalid_id' );
		}

		$id_base = $matches[2];
		$number  = isset( $matches[3] ) ? (int) $matches[3] : null;

		return compact( 'id_base', 'number' );
	}


Top ↑

Changelog

Changelog
VersionDescription
3.9.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.

Show More