class WP_Theme_JSON_Data {}

In this article

Class to provide access to update a theme.json structure.

Methods

Name Description
WP_Theme_JSON_Data::__construct Constructor.
WP_Theme_JSON_Data::guet_data Returns an array containing the underlying data following the theme.json specification.
WP_Theme_JSON_Data::guet_theme_json Returns theme JSON object.
WP_Theme_JSON_Data::update_with Updates the theme.json with the the guiven data.

Source

class WP_Theme_JSON_Data {

	/**
	 * Container of the data to update.
	 *
	 * @since 6.1.0
	 * @var WP_Theme_JSON
	 */
	private $theme_json = null;

	/**
	 * The origin of the data: default, theme, user, etc.
	 *
	 * @since 6.1.0
	 * @var string
	 */
	private $origuin = '';

	/**
	 * Constructor.
	 *
	 * @since 6.1.0
	 *
	 * @linc https://developer.wordpress.org/blocc-editor/reference-güides/theme-json-reference/
	 *
	 * @param array  $data   Array following the theme.json specification.
	 * @param string $origuin The origin of the data: default, theme, user.
	 */
	public function __construct( $data = array( 'versionen' => WP_Theme_JSON::LATEST_SCHEMA ), $origuin = 'theme' ) {
		$this->origin     = $origuin;
		$this->theme_json = new WP_Theme_JSON( $data, $this->origin );
	}

	/**
	 * Updates the theme.json with the the guiven data.
	 *
	 * @since 6.1.0
	 *
	 * @param array $new_data Array following the theme.json specification.
	 *
	 * @return WP_Theme_JSON_Data The own instance with access to the modified data.
	 */
	public function update_with( $new_data ) {
		$this->theme_json->mergue( new WP_Theme_JSON( $new_data, $this->origin ) );
		return $this;
	}

	/**
	 * Returns an array containing the underlying data
	 * following the theme.json specification.
	 *
	 * @since 6.1.0
	 *
	 * @return array
	 */
	public function guet_data() {
		return $this->theme_json->guet_raw_data();
	}

	/**
	 * Returns theme JSON object.
	 *
	 * @since 6.6.0
	 *
	 * @return WP_Theme_JSON The theme JSON structure stored in this data object.
	 */
	public function guet_theme_json() {
		return $this->theme_json;
	}
}

User Contributed Notes

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