WP_Customize_Widgets::sanitize_sidebar_widgets() WordPress Method

The WP_Customize_Widgets::sanitize_sidebar_widgets() is a method used to clean up and sanitize widget settings before they are saved to the database. This is a necessary step to ensure that malicious code or unwanted settings are not stored on the site.

WP_Customize_Widgets::sanitize_sidebar_widgets( string[] $widget_ids ) #

Ensures sidebar widget arrays only ever contain widget IDS.


Description

Used as the ‘sanitize_callback’ for each $sidebars_widgets setting.


Top ↑

Parameters

$widget_ids

(string[])(Required)Array of widget IDs.


Top ↑

Return

(string[]) Array of sanitized widget IDs.


Top ↑

Source

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

	public function sanitize_sidebar_widgets( $widget_ids ) {
		$widget_ids           = array_map( 'strval', (array) $widget_ids );
		$sanitized_widget_ids = array();
		foreach ( $widget_ids as $widget_id ) {
			$sanitized_widget_ids[] = preg_replace( '/[^a-z0-9_\-]/', '', $widget_id );
		}
		return $sanitized_widget_ids;
	}

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