+ }
+
+ if ( 'option' === $this->type || 'theme_mod' === $this->type ) {
+ // Other setting types can opt-in to aggregate multidimensional explicitly.
+ $this->aggregate_multidimensional();
+
+ // Allow option settings to indicate whether they should be autoloaded.
+ if ( 'option' === $this->type && isset( $args['autoload'] ) ) {
+ self::$aggregated_multidimensionals[ $this->type ][ $this->id_data['base'] ]['autoload'] = $args['autoload'];
+ }
+ }
+ }
+
+ /**
+ * Get parsed ID data for multidimensional setting.
+ *
+ * @since 4.4.0
+ * @access public
+ *
+ * @return array {
+ * ID data for multidimensional setting.
+ *
+ * @type string $base ID base
+ * @type array $keys Keys for multidimensional array.
+ * }
+ */
+ final public function id_data() {
+ return $this->id_data;
+ }
+
+ /**
+ * Set up the setting for aggregated multidimensional values.
+ *
+ * When a multidimensional setting gets aggregated, all of its preview and update
+ * calls get combined into one call, greatly improving performance.
+ *
+ * @since 4.4.0
+ * @access protected
+ */
+ protected function aggregate_multidimensional() {
+ $id_base = $this->id_data['base'];
+ if ( ! isset( self::$aggregated_multidimensionals[ $this->type ] ) ) {
+ self::$aggregated_multidimensionals[ $this->type ] = array();
+ }
+ if ( ! isset( self::$aggregated_multidimensionals[ $this->type ][ $id_base ] ) ) {
+ self::$aggregated_multidimensionals[ $this->type ][ $id_base ] = array(
+ 'previewed_instances' => array(), // Calling preview() will add the $setting to the array.
+ 'preview_applied_instances' => array(), // Flags for which settings have had their values applied.
+ 'root_value' => $this->get_root_value( array() ), // Root value for initial state, manipulated by preview and update calls.
+ );
+ }
+
+ if ( ! empty( $this->id_data['keys'] ) ) {
+ // Note the preview-applied flag is cleared at priority 9 to ensure it is cleared before a deferred-preview runs.
+ add_action( "customize_post_value_set_{$this->id}", array( $this, '_clear_aggregated_multidimensional_preview_applied_flag' ), 9 );
+ $this->is_multidimensional_aggregated = true;
+ }
+ }
+
+ /**
+ * Reset `$aggregated_multidimensionals` static variable.
+ *
+ * This is intended only for use by unit tests.
+ *
+ * @since 4.5.0
+ * @access public
+ * @ignore
+ */
+ static public function reset_aggregated_multidimensionals() {
+ self::$aggregated_multidimensionals = array();
+ }
+
+ /**
+ * The ID for the current site when the preview() method was called.
+ *
+ * @since 4.2.0
+ * @access protected
+ * @var int
+ */
+ protected $_previewed_blog_id;