WP_Theme_JSON::get_settings_values_by_slug()
Gets preset values keyed by slugs based on settings and metadata.
$settings = array( 'typography' => array( 'fontFamilies' => array( array( 'slug' => 'sansSerif', 'fontFamily' => '"Helvetica Neue", sans-serif', ), array( 'slug' => 'serif', 'colors' => 'Georgia, serif', ) ), ), ); $meta = array( 'path' => array( 'typography', 'fontFamilies' ), 'value_key' => 'fontFamily', ); $values_by_slug = get_settings_values_by_slug(); // $values_by_slug === array( // 'sans-serif' => '"Helvetica Neue", sans-serif', // 'serif' => 'Georgia, serif', // );
Метод класса: WP_Theme_JSON{}
Хуков нет.
Возвращает
Массив
. Array of presets where each key is a slug and each value is the preset value.
Использование
$result = WP_Theme_JSON::get_settings_values_by_slug( $settings, $preset_metadata, $origins );
- $settings(массив) (обязательный)
- Settings to process.
- $preset_metadata(массив) (обязательный)
- One of the PRESETS_METADATA values.
- $origins(string[]) (обязательный)
- List of origins to process.
Список изменений
С версии 5.9.0 | Введена. |
С версии 6.6.0 | Passing $settings to the callbacks defined in static::PRESETS_METADATA. |
Код WP_Theme_JSON::get_settings_values_by_slug() WP Theme JSON::get settings values by slug WP 6.6.1
protected static function get_settings_values_by_slug( $settings, $preset_metadata, $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'] ); $value = ''; if ( isset( $preset_metadata['value_key'], $preset[ $preset_metadata['value_key'] ] ) ) { $value_key = $preset_metadata['value_key']; $value = $preset[ $value_key ]; } elseif ( isset( $preset_metadata['value_func'] ) && is_callable( $preset_metadata['value_func'] ) ) { $value_func = $preset_metadata['value_func']; $value = call_user_func( $value_func, $preset, $settings ); } else { // If we don't have a value, then don't add it to the result. continue; } $result[ $slug ] = $value; } } return $result; }