Merge in Custom field data, meta and post data

@return    array    array with merged data
769973
public static function get_custom_field_data( $post_id ) {

		global $post;
		if ( ! is_object( $post ) ) {
			$post = get_post( $post_id );
		}

		$raw_data = get_post_meta( $post_id  );

		if ( ! is_array( $raw_data ) ) {
			return;

		}
		
		// init the data array		
		$template_data = array();

		// add taxonomies in with a :taxonomy alias
		$taxonomies = get_object_taxonomies( $post );
		if( !empty( $taxonomies ) ){
			foreach ( $taxonomies as $taxonomy_name  ) {

				$taxonomy = get_taxonomy( $taxonomy_name );
				$template_data['taxonomy'][ $taxonomy_name ] = $template_data[ $taxonomy_name ] = wp_get_post_terms( $post->ID, $taxonomy_name, array("fields" => "all") );

			}
		}

		// break to standard arrays
		foreach( $raw_data as $meta_key=>$meta_data ){

			if( count( $meta_data ) === 1 ){
				if( strlen( trim( $meta_data[0] ) ) > 0 ){ // check value is something else leave it out.
					$template_data[$meta_key] = trim( $meta_data[0] );
				}
			}else{
				$template_data[$meta_key] = $meta_data;
			}
		}
		// ACF support
		if( class_exists( 'acf' ) ){
			$fields = get_fields( $post->ID );
			if ( is_array( $fields ) && ! empty( $fields ) ) {
				$template_data = array_merge( $template_data, $fields );
			}

		}
		// CFS support
		if( class_exists( 'Custom_Field_Suite' ) ){
			$fields = CFS()->get();
			if ( is_array( $fields ) && ! empty( $fields ) ) {
				$template_data = array_merge( $template_data, $fields );
			}

		}

		//Pods support
		if ( class_exists( 'Pods' ) && false != ( $pods = pods( $post->post_type, $post->ID, true ) ) ) {
			$fields = $pods->export();
			if ( is_array( $fields ) && ! empty( $fields ) ) {
				$template_data = array_merge( $template_data, $fields );
			}

		}


		// include post values if in a post
		if( !empty( $post ) ){
			foreach( $post as $post_key=>$post_value ){
				$template_data[$post_key] = $post_value;
			}
			// author details
			$template_data['post_author'] = get_userdata( $template_data['post_author'] );
			// add permalink
			$template_data['permalink'] = get_permalink( $post->ID );
			// core post object
			$template_data['post_format'] = get_post_format( $post );

		}

		return $template_data;

	}
740612
protected function retrieveConfigPostMetas($post, $postTypeModel)
	{
		$metaKeys = [];
		$metaTaxonomies = [];

		$allKeys = $this->getValidationsKeys($postTypeModel);
		foreach($allKeys as $key => $value){

			$customFieldObject = $this->getCustomFieldObject($postTypeModel, $key);

			if(isset($customFieldObject['type']) && $customFieldObject['type'] == 'taxonomy'){

				// We need to get the values from the taxonomy table
				if(array_key_exists('post_type', $customFieldObject)){

					$customfieldPostTypes = $this->getPostTypeIdentifiers($customFieldObject['post_type']);

					// Lets query the post to retrieve all the connected ids
					$taxonomyIds = $post->taxonomies()->whereIn('post_type', $customfieldPostTypes)
						->get();

					// Lets foreach all the posts because we only need the id
					$ids = [];
					foreach($taxonomyIds as $value){
						array_push($ids, $value->id);
					}

					$ids = json_encode($ids);

					$metaTaxonomies[$key] = [
						'meta_key' => $key,
						'meta_value' => $ids,
					];

				}

			// The other items are default
			} else {

				// Register it to the main array so we can query it later
				array_push($metaKeys, $key);

			}

		}

		// Lets query the database to get only the values where we have registered the meta keys
		$postmetaSimple = $post->postmeta()
			->whereIn('meta_key', $metaKeys)
			->select(['meta_key', 'meta_value'])
			->get()
			->keyBy('meta_key')
			->toArray();

		// Lets attach the default post columns
		$defaultPostData = [];

		$defaultPostData['post_title'] = [
			'meta_key' => 'post_title',
			'meta_value' => $post->post_title,
		];

		$defaultPostData['post_name'] = [
			'meta_key' => 'post_name',
			'meta_value' => $post->post_name,
		];

		// Lets merge all the types of configs
		$postmeta = array_merge($postmetaSimple, $metaTaxonomies, $defaultPostData);

		// Return the post meta's
		return $postmeta;
	}
432941
public function combine() {

		$fieldnames = func_get_args();
		$values 	= [];

		foreach($fieldnames as $fieldname) {

			if(false === is_string($fieldname)) {
				return trigger_error(sprintf('All fieldnames used in "%s"() must be of the type string, "%s" given', __METHOD__, gettype($fieldname)), E_USER_ERROR);
			}

			$values[] = $this -> getValue($fieldname, $this -> getPrefix());
		}

		$combine = new Combine();
		$combine -> setValues($values);
		$combine -> setFieldnames($fieldnames);

		$this -> combine[] = $combine;

		return $combine;
	}
424189
public function merge()
    {
        $marged = NULL;
        foreach (func_get_args() as $arg) {
            // first is override.
            if ($marged === null) {
                $marged = $arg;

            // when mismatch variable type, then override.
            } elseif (gettype($marged) !== gettype($arg)) {
                $marged = $arg;

            // when not array, then override.
            } elseif (! is_array($arg)) {
                $marged = $arg;

            // when both array, then merge recursive.
            } else {
                foreach ($arg as $_key => $_val) {
                    // when int key, then push.
                    if(is_int($_key)) {
                        $marged[] = $_val;
                    // when not exists key, then override.
                    } elseif(! isset($marged[$_key])) {
                        $marged[$_key] = $_val;
                    // merge.
                    } else {
                        $marged[$_key] = $this->merge($marged[$_key], $_val);
                    }
                }
            }
        }
        return $marged;
    }
111152
public function customFieldsToArray()
    {
        $result = [];
        foreach ($this->getCustomFields() as $field) {
            $result[$field->getInternalFieldName()] = $field->getValue();
        }

        return $result;
    }
518170
public static function merge(): array
    {
        $arguments = [];
        foreach (func_get_args() as $key => $val) {
            if (!Any::isArray($val)) {
                $val = [];
            }

            $arguments[$key] = $val;
        }
        return call_user_func_array('array_merge', $arguments);
    }
833811
public function changedFieldNames()
    {
        $diffed = clone $this->fromRecord;
        $fields = array_keys($diffed->toMap());

        $changedFields = [];

        foreach ($fields as $field) {
            if (in_array($field, $this->ignoredFields)) {
                continue;
            }
            if ($this->fromRecord->$field != $this->toRecord->$field) {
                $changedFields[] = $field;
            }
        }

        return $changedFields;
    }
23094
protected function buildUpData()
    {
        $data   = [];
        $fields = $this->definition->getEditableFieldNames();
        foreach ($fields as $field) {
            $data[$field] = $this->entity->getRaw($field);
            $fixed        = $this->definition->getField($field, 'value');
            if ($fixed) {
                $data[$field] = $fixed;
            }
        }
        return $data;
    }
802343
protected function getPreviewFieldData()
    {
        $data = ArrayList::create();

        $fields = $this->record->Form()->Fields()->filter(
            'ClassName:not',
            [
                EditableLiteralField::class,
                EditableFormHeading::class,
            ]
        );

        foreach ($fields as $field) {
            $data->push(ArrayData::create([
                'Name' => $field->dbObject('Name'),
                'Title' => $field->dbObject('Title'),
                'Value' => DBField::create_field('Varchar', '$' . $field->Name),
                'FormattedValue' => DBField::create_field('Varchar', '$' . $field->Name)
            ]));
        }

        return $data;
    }
849276
public function getPostFields()
    {
        $this->validate();
        $mappedFields = $this->getMappedFields();
        $this->paymentMethod->addAdditionalFields($mappedFields);
        return $mappedFields;
    }
795432
public function merge()
    {
        $this->xmlParsed .= str_replace(array_keys($this->vars), array_values($this->vars), $this->xml);
        if ($this->hasChildren()) {
            foreach ($this->children as $child) {
                $this->xmlParsed = str_replace($child->xml, ($child->xmlParsed=="")?$child->merge():$child->xmlParsed, $this->xmlParsed);
                $child->xmlParsed = '';
                //Store all image names used in child segments in current segment array
                foreach ($child->manif_vars as $file) {
                    $this->manif_vars[] = $file;
                }

                $child->manif_vars = array();
            }
        }
        $reg = "/\[!--\sBEGIN\s$this->name\s--\](.*)\[!--\sEND\s$this->name\s--\]/smU";
        $this->xmlParsed = preg_replace($reg, '$1', $this->xmlParsed);
        $this->file->open($this->odf->getTmpfile());
        foreach ($this->images as $imageKey => $imageValue) {
            if ($this->file->getFromName('Pictures/' . $imageValue) === false) {
                $this->file->addFile($imageKey, 'Pictures/' . $imageValue);
            }
        }

        $this->file->close();
        return $this->xmlParsed;
    }
830756
protected function get_registered_fields() {
		$registered = array();

		foreach ( get_registered_meta_keys( $this->get_meta_type() ) as $name => $args ) {
			if ( empty( $args['show_in_rest'] ) ) {
				continue;
			}

			$rest_args = array();
			if ( is_array( $args['show_in_rest'] ) ) {
				$rest_args = $args['show_in_rest'];
			}

			$default_args = array(
				'name'             => $name,
				'single'           => $args['single'],
				'schema'           => array(),
				'prepare_callback' => array( $this, 'prepare_value' ),
			);
			$default_schema = array(
				'type'        => null,
				'description' => empty( $args['description'] ) ? '' : $args['description'],
				'default'     => isset( $args['default'] ) ? $args['default'] : null,
			);
			$rest_args = array_merge( $default_args, $rest_args );
			$rest_args['schema'] = array_merge( $default_schema, $rest_args['schema'] );

			if ( empty( $rest_args['schema']['type'] ) ) {
				// Skip over meta fields that don't have a defined type.
				if ( empty( $args['type'] ) ) {
					continue;
				}

				if ( $rest_args['single'] ) {
					$rest_args['schema']['type'] = $args['type'];
				} else {
					$rest_args['schema']['type'] = 'array';
					$rest_args['schema']['items'] = array(
						'type' => $args['type'],
					);
				}
			}

			$registered[ $rest_args['name'] ] = $rest_args;
		} // End foreach().

		return $registered;
	}
1114247
static function arrayMerge() {
        $output = [];
        
        foreach(func_get_args() as $array) {
            foreach($array as $key => $value) {
                $output[$key] = isset($output[$key]) ?
                    array_merge($output[$key], $value) : $value;
            }
        }
        
        return $output;
    }
51595
public static function get_field_data() {
		return array(
			'glue'              => array(
				'type'    => 'text',
				'title'   => __( 'Glue', 'carbon_breadcrumbs' ),
				'default' => ' > ',
				'help'    => __( 'This is displayed between the breadcrumb items.', 'carbon_breadcrumbs' ),
			),
			'link_before'       => array(
				'type'    => 'text',
				'title'   => __( 'Link Before', 'carbon_breadcrumbs' ),
				'default' => '',
				'help'    => __( 'This is displayed before the breadcrumb item link.', 'carbon_breadcrumbs' ),
			),
			'link_after'        => array(
				'type'    => 'text',
				'title'   => __( 'Link After', 'carbon_breadcrumbs' ),
				'default' => '',
				'help'    => __( 'This is displayed after the breadcrumb item link.', 'carbon_breadcrumbs' ),
			),
			'wrapper_before'    => array(
				'type'    => 'text',
				'title'   => __( 'Wrapper Before', 'carbon_breadcrumbs' ),
				'default' => '',
				'help'    => __( 'This is displayed before displaying the breadcrumb items.', 'carbon_breadcrumbs' ),
			),
			'wrapper_after'     => array(
				'type'    => 'text',
				'title'   => __( 'Wrapper After', 'carbon_breadcrumbs' ),
				'default' => '',
				'help'    => __( 'This is displayed after displaying the breadcrumb items.', 'carbon_breadcrumbs' ),
			),
			'title_before'      => array(
				'type'    => 'text',
				'title'   => __( 'Title Before', 'carbon_breadcrumbs' ),
				'default' => '',
				'help'    => __( 'This is displayed before the breadcrumb item title.', 'carbon_breadcrumbs' ),
			),
			'title_after'       => array(
				'type'    => 'text',
				'title'   => __( 'Title After', 'carbon_breadcrumbs' ),
				'default' => '',
				'help'    => __( 'This is displayed after the breadcrumb item title.', 'carbon_breadcrumbs' ),
			),
			'min_items'         => array(
				'type'    => 'text',
				'title'   => __( 'Min Items', 'carbon_breadcrumbs' ),
				'default' => 2,
				'help'    => __( 'Determines the minimum number of items, required to display the breadcrumb trail.', 'carbon_breadcrumbs' ),
			),
			'last_item_link'    => array(
				'type'    => 'checkbox',
				'title'   => __( 'Last Item Link', 'carbon_breadcrumbs' ),
				'default' => true,
				'help'    => __( 'Whether the last breadcrumb item should be a link.', 'carbon_breadcrumbs' ),
			),
			'display_home_item' => array(
				'type'    => 'checkbox',
				'title'   => __( 'Display Home Item?', 'carbon_breadcrumbs' ),
				'default' => true,
				'help'    => __( 'Whether the home breadcrumb item should be displayed.', 'carbon_breadcrumbs' ),
			),
			'home_item_title'   => array(
				'type'    => 'text',
				'title'   => __( 'Home Item Title', 'carbon_breadcrumbs' ),
				'default' => __( 'Home', 'carbon_breadcrumbs' ),
				'help'    => __( 'Determines the title of the home item.', 'carbon_breadcrumbs' ),
			),
		);
	}
1059212
private function _merge(array $data) : array
    {
        $values = $this->getValues();
        $values = array_merge($values, $data);
        return $values;
    }
208516
public function toArray()
    {
        return array_merge($this->wrappedObject->toArray(), [
            'human_status'        => $this->human_status(),
            'latest_update_id'    => $this->latest() ? $this->latest()->id : null,
            'latest_status'       => $this->latest_status(),
            'latest_human_status' => $this->latest_human_status(),
            'latest_icon'         => $this->latest_icon(),
            'permalink'           => $this->permalink(),
            'duration'            => $this->duration(),
            'meta'                => $this->meta(),
            'occurred_at'         => $this->occurred_at(),
            'created_at'          => $this->created_at(),
            'updated_at'          => $this->updated_at(),
        ]);
    }
289778
private function _mergeFields()
    {
        foreach ($this->_segmentInfos as $segName => $segmentInfo) {
            foreach ($segmentInfo->getFieldInfos() as $fieldInfo) {
                $this->_fieldsMap[$segName][$fieldInfo->number] = $this->_writer->addFieldInfo($fieldInfo);
            }
        }
    }