$part ) { /** * Skip the 1st item, it's already been dealt with * when we got the value initially right before this loop. */ if ( 0 === $key ) { continue; } $part = str_replace( ']', '', $part ); /** * If the item exists in the value, then change $value to the item. * This runs recursively for all parts until we get to the end. */ if ( is_array( $value ) && isset( $value[ $part ] ) ) { $value = $value[ $part ]; continue; } /** * If we got here, the item was not found in the value. * We need to change the value accordingly depending on whether * this is the last item in the loop or not. */ $value = ( isset( $parts[ $key + 1 ] ) ) ? [] : ''; } } return $value; } /** * Allow filtering the arguments. * * @since 0.1 * @param array $args The arguments. * @param WP_Customize_Manager $customizer The customizer instance. * @return array Return the arguments. */ public function add_setting_args( $args, $customizer ) { // If this is not an option, early exit. if ( ! isset( $args['option_type'] ) || 'option' !== $args['option_type'] ) { return $args; } // Set "type" argument to option. $args['type'] = 'option'; return $this->maybe_change_settings( $args ); } /** * Allow filtering the arguments. * * @since 0.1 * @param array $args The arguments. * @param WP_Customize_Manager $customizer The customizer instance. * @return array Return the arguments. */ public function add_control_args( $args, $customizer ) { // If this is not an option, early exit. if ( ! isset( $args['option_type'] ) || 'option' !== $args['option_type'] ) { return $args; } return $this->maybe_change_settings( $args ); } /** * Change the settings argument. * * @access private * @since 1.0 * @param array $args The arguments. * @return array Returns modified array with tweaks to the [settings] argument if needed. */ private function maybe_change_settings( $args ) { // Check if we have an option-name defined. if ( isset( $args['option_name'] ) ) { if ( empty( $args['option_name'] ) ) { return $args; } if ( isset( $args['settings'] ) && $args['settings'] && false !== strpos( $args['settings'], $args['option_name'] . '[' ) ) { return $args; } if ( false === strpos( $args['settings'], '[' ) ) { // ? Bagus: in line above, it's obvious that '[' is not found in $args['settings']. But why do we explode it using '[' here? $parts = explode( '[', $args['settings'] ); $final_parts = [ $args['option_name'] ]; foreach ( $parts as $part ) { $final_parts[] = $part; } $args['settings'] = \implode( '][', $final_parts ) . ']'; $args['settings'] = str_replace( $args['option_name'] . '][', $args['option_name'] . '[', $args['settings'] ); } } return $args; } }