wp-customize-utils.php 800 B

12345678910111213141516171819202122232425
  1. <?php
  2. /**
  3. *
  4. * Assign a value to an object at the given location. Create the nested objects if they aren't already available.
  5. *
  6. * @param object $target The object to assign the value to
  7. * @param array $array The array describing the location of the property to update
  8. * @param object $value The value to assign
  9. * @return object The modified $target object with $value assigned where $array describes
  10. *
  11. */
  12. function set_settings_array( $target, $array, $value ) {
  13. $key = array_shift( $array );
  14. $current =& $target;
  15. while ( 0 < sizeof( $array ) ) {
  16. if ( ! property_exists( $current, $key ) ) {
  17. $current->{ $key } = (object) array();
  18. }
  19. $current =& $current->{ $key };
  20. $key = array_shift( $array );
  21. }
  22. $current->{ $key } = $value;
  23. return $target;
  24. }