[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> class-wp-theme-json-data.php (source)

   1  <?php
   2  /**
   3   * WP_Theme_JSON_Data class
   4   *
   5   * @package WordPress
   6   * @subpackage Theme
   7   * @since 6.1.0
   8   */
   9  
  10  /**
  11   * Class to provide access to update a theme.json structure.
  12   */
  13  #[AllowDynamicProperties]
  14  class WP_Theme_JSON_Data {
  15  
  16      /**
  17       * Container of the data to update.
  18       *
  19       * @since 6.1.0
  20       * @var WP_Theme_JSON
  21       */
  22      private $theme_json = null;
  23  
  24      /**
  25       * The origin of the data: default, theme, user, etc.
  26       *
  27       * @since 6.1.0
  28       * @var string
  29       */
  30      private $origin = '';
  31  
  32      /**
  33       * Constructor.
  34       *
  35       * @since 6.1.0
  36       *
  37       * @link https://developer.wordpress.org/block-editor/reference-guides/theme-json-reference/
  38       *
  39       * @param array  $data   Array following the theme.json specification.
  40       * @param string $origin The origin of the data: default, theme, user.
  41       */
  42  	public function __construct( $data = array(), $origin = 'theme' ) {
  43          $this->origin     = $origin;
  44          $this->theme_json = new WP_Theme_JSON( $data, $this->origin );
  45      }
  46  
  47      /**
  48       * Updates the theme.json with the the given data.
  49       *
  50       * @since 6.1.0
  51       *
  52       * @param array $new_data Array following the theme.json specification.
  53       *
  54       * @return WP_Theme_JSON_Data The own instance with access to the modified data.
  55       */
  56  	public function update_with( $new_data ) {
  57          $this->theme_json->merge( new WP_Theme_JSON( $new_data, $this->origin ) );
  58          return $this;
  59      }
  60  
  61      /**
  62       * Returns an array containing the underlying data
  63       * following the theme.json specification.
  64       *
  65       * @since 6.1.0
  66       *
  67       * @return array
  68       */
  69  	public function get_data() {
  70          return $this->theme_json->get_raw_data();
  71      }
  72  }


Generated : Thu May 2 08:20:01 2024 Cross-referenced by PHPXref