Support Forum ยป User Profile

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • in reply to: Fix for nesting groups #2599
    aconwayaconway
    Participant

    Great, thanks! That was a good catch to make it more efficient.

    in reply to: Fix for nesting groups #2569
    aconwayaconway
    Participant

    Hi,

    what I posted above isn't exactly right, I ran into the issue that the attributes are set as strings on the metabox html object so you have an issue if there's a array (ie an image value or something).

    I made it instead like this

    	static function html( $meta, $field )
    	{
    		// Get parent field and filter to child field meta value
    		if(!isset($field['parent_meta'])){
    			add_filter( 'rwmb_field_meta', array( __CLASS__, 'child_field_meta' ), 10, 3 );
    		}
    
    		ob_start();
    
    		foreach ( $field['fields'] as $child_field )
    		{
    			$child_field['attributes']['name'] = $child_field['field_name'] = self::child_field_name( $field['field_name'], $child_field['field_name'] ); 
    			if(isset($meta[$child_field['id']])){
    				$child_field['parent_meta'] = $meta[$child_field['id']];
    			}
    			call_user_func( array( RW_Meta_Box::get_class_name( $child_field ), 'show' ), $child_field, RWMB_Group::$saved);	
    		}
    
    		// Remove filter to child field meta value and reset class's parent field's meta
    		if(!isset($field['parent_meta'])){
    			remove_filter( 'rwmb_field_meta', array( __CLASS__, 'child_field_meta' ) );
    		}
    
    	   return ob_get_clean();
    	}
    static function child_field_meta( $meta, $child_field, $saved )
    	{
    
    		$meta = '';
    		$id   = $child_field['id'];
    
    		if ( isset( $child_field['parent_meta'] ) )
    		{
    			$meta = $child_field['parent_meta'];
    		}
    		elseif ( ! $saved && isset( $child_field['std'] ) )
    		{
    			$meta = $child_field['std'];
    		}
    		elseif ( $child_field['multiple'] )
    		{
    			$meta = array();
    		}
    
    		return $meta;
    	}
    
Viewing 2 posts - 1 through 2 (of 2 total)