WP_Theme_JSON::get_settings_slugs() WordPress Method

The WP_Theme_JSON::get_settings_slugs() method can be used to get an array of setting slugs for a given WordPress theme. This is useful for creating a customizer panel for a theme.

WP_Theme_JSON::get_settings_slugs( array $settings, array $preset_metadata, array $origins = null ) #

Similar to get_settings_values_by_slug, but doesn’t compute the value.


Parameters

$settings

(array)(Required)Settings to process.

$preset_metadata

(array)(Required)One of the PRESETS_METADATA values.

$origins

(array)(Optional)List of origins to process.

Default value: null


Top ↑

Return

(array) Array of presets where the key and value are both the slug.


Top ↑

Source

File: wp-includes/class-wp-theme-json.php

	protected static function get_settings_slugs( $settings, $preset_metadata, $origins = null ) {
		if ( null === $origins ) {
			$origins = static::VALID_ORIGINS;
		}

		$preset_per_origin = _wp_array_get( $settings, $preset_metadata['path'], array() );

		$result = array();
		foreach ( $origins as $origin ) {
			if ( ! isset( $preset_per_origin[ $origin ] ) ) {
				continue;
			}
			foreach ( $preset_per_origin[ $origin ] as $preset ) {
				$slug = _wp_to_kebab_case( $preset['slug'] );

				// Use the array as a set so we don't get duplicates.
				$result[ $slug ] = $slug;
			}
		}
		return $result;
	}


Top ↑

Changelog

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