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

 *
 * For example, the following:
 *
 * {
 *   "settings": {
 *     "color": {
 *       "palette": {
 *         "theme": [ {} ],
 *         "custom": [ {} ]
 *       }
 *     }
 *   }
 * }
 *
 * will be converted to:
 *
 * {
 *   "settings": {
 *     "color": {
 *       "palette": [ {} ]
 *     }
 *   }
 * }
 */
foreach ( $nodes as $node ) {
	foreach ( static::PRESETS_METADATA as $preset_metadata ) {
		$path = $node['path'];
		foreach ( $preset_metadata['path'] as $preset_metadata_path ) {
			$path[] = $preset_metadata_path;
		}
		$preset = _wp_array_get( $output, $path, null );
		if ( null === $preset ) {
			continue;
		}

		$items = array();
		if ( isset( $preset['theme'] ) ) {
			foreach ( $preset['theme'] as $item ) {
				$slug = $item['slug'];
				unset( $item['slug'] );
				$items[ $slug ] = $item;
			}
		}
		if ( isset( $preset['custom'] ) ) {
			foreach ( $preset['custom'] as $item ) {
				$slug = $item['slug'];
				unset( $item['slug'] );
				$items[ $slug ] = $item;
			}
		}
		$flattened_preset = array();
		foreach ( $items as $slug => $value ) {
			$flattened_preset[] = array_merge( array( 'slug' => (string) $slug ), $value );
		}
		_wp_array_set( $output, $path, $flattened_preset );
	}
}

/*
 * If all of the static::APPEARANCE_TOOLS_OPT_INS are true,
 * this code unsets them and sets 'appearanceTools' instead.
 */
foreach ( $nodes as $node ) {
	$all_opt_ins_are_set = true;
	foreach ( static::APPEARANCE_TOOLS_OPT_INS as $opt_in_path ) {
		$full_path = $node['path'];
		foreach ( $opt_in_path as $opt_in_path_item ) {
			$full_path[] = $opt_in_path_item;
		}
		/*
		 * Use "unset prop" as a marker instead of "null" because
		 * "null" can be a valid value for some props (e.g. blockGap).
		 */
		$opt_in_value = _wp_array_get( $output, $full_path, 'unset prop' );
		if ( 'unset prop' === $opt_in_value ) {
			$all_opt_ins_are_set = false;
			break;
		}
	}

	if ( $all_opt_ins_are_set ) {
		$node_path_with_appearance_tools   = $node['path'];
		$node_path_with_appearance_tools[] = 'appearanceTools';
		_wp_array_set( $output, $node_path_with_appearance_tools, true );
		foreach ( static::APPEARANCE_TOOLS_OPT_INS as $opt_in_path ) {
			$full_path = $node['path'];
			foreach ( $opt_in_path as $opt_in_path_item ) {
				$full_path[] = $opt_in_path_item;
			}
			/*
			 * Use "unset prop" as a marker instead of "null" because
			 * "null" can be a valid value for some props (e.g. blockGap).
			 */
			$opt_in_value = _wp_array_get( $output, $full_path, 'unset prop' );
			if ( true !== $opt_in_value ) {
				continue;
			}

			/*
			 * The following could be improved to be path independent.
			 * At the moment it relies on a couple of assumptions:
			 *
			 * - all opt-ins having a path of size 2.
			 * - there's two sources of settings: the top-level and the block-level.
			 */
			if (
				( 1 === count( $node['path'] ) ) &&
				( 'settings' === $node['path'][0] )
			) {
				// Top-level settings.
				unset( $output['settings'][ $opt_in_path[0] ][ $opt_in_path[1] ] );
				if ( empty( $output['settings'][ $opt_in_path[0] ] ) ) {
					unset( $output['settings'][ $opt_in_path[0] ] );
				}
			} elseif (

Changelog

VersionDescription
6.1.0Introduced.

User Contributed Notes

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