WP_Theme_JSON::set_spacing_sizes(): null|void

In this article

Sets the spacingSizes array based on the spacingScale values from theme.json.

Return

null|void

Source

	 */
	if ( is_array( $override ) ) {
		$value = _wp_array_get( $theme_json, array_merge( $path, $override ) );
		if ( isset( $value ) ) {
			return ! $value;
		}

		// Search the top-level key if none was found for this node.
		$value = _wp_array_get( $theme_json, array_merge( array( 'settings' ), $override ) );
		if ( isset( $value ) ) {
			return ! $value;
		}

		return true;
	}
}

/**
 * Returns the default slugs for all the presets in an associative array
 * whose keys are the preset paths and the leaves is the list of slugs.
 *
 * For example:
 *
 *     array(
 *       'color' => array(
 *         'palette'   => array( 'slug-1', 'slug-2' ),
 *         'gradients' => array( 'slug-3', 'slug-4' ),
 *       ),
 *     )
 *
 * @since 5.9.0
 *
 * @param array $data      A theme.json like structure.
 * @param array $node_path The path to inspect. It's 'settings' by default.
 * @return array
 */
protected static function get_default_slugs( $data, $node_path ) {
	$slugs = array();

	foreach ( static::PRESETS_METADATA as $metadata ) {
		$path = $node_path;
		foreach ( $metadata['path'] as $leaf ) {
			$path[] = $leaf;
		}
		$path[] = 'default';

		$preset = _wp_array_get( $data, $path, null );
		if ( ! isset( $preset ) ) {
			continue;
		}

		$slugs_for_preset = array();
		foreach ( $preset as $item ) {
			if ( isset( $item['slug'] ) ) {
				$slugs_for_preset[] = $item['slug'];
			}
		}

		_wp_array_set( $slugs, $metadata['path'], $slugs_for_preset );
	}

	return $slugs;
}

/**
 * Gets a `default`'s preset name by a provided slug.
 *
 * @since 5.9.0
 *
 * @param string $slug The slug we want to find a match from default presets.
 * @param array  $base_path The path to inspect. It's 'settings' by default.
 * @return string|null
 */
protected function get_name_from_defaults( $slug, $base_path ) {
	$path            = $base_path;
	$path[]          = 'default';
	$default_content = _wp_array_get( $this->theme_json, $path, null );
	if ( ! $default_content ) {
		return null;
	}
	foreach ( $default_content as $item ) {
		if ( $slug === $item['slug'] ) {
			return $item['name'];
		}
	}
	return null;
}

/**
 * Removes the preset values whose slug is equal to any of given slugs.
 *
 * @since 5.9.0
 *
 * @param array $node  The node with the presets to validate.
 * @param array $slugs The slugs that should not be overridden.
 * @return array The new node.
 */
protected static function filter_slugs( $node, $slugs ) {
	if ( empty( $slugs ) ) {
		return $node;
	}

	$new_node = array();
	foreach ( $node as $value ) {
		if ( isset( $value['slug'] ) && ! in_array( $value['slug'], $slugs, true ) ) {
			$new_node[] = $value;
		}
	}

	return $new_node;
}

/**
 * Removes insecure data from theme.json.
 *

Changelog

VersionDescription
6.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.