fewbricks\bricks\brick::get_field PHP Method

get_field() protected method

protected get_field ( $data_name, boolean $post_id = false, boolean $prepend_this_name = true, boolean $get_from_sub_field = false ) : boolean | mixed | null | void
$data_name
$post_id boolean
$prepend_this_name boolean
$get_from_sub_field boolean
return boolean | mixed | null | void
    protected function get_field($data_name, $post_id = false, $prepend_this_name = true, $get_from_sub_field = false)
    {
        if ($prepend_this_name) {
            if (substr($data_name, 0, 1) !== '_') {
                $data_name = '_' . $data_name;
            }
            $name = $this->name . $data_name;
        } else {
            $name = $data_name;
        }
        if ($post_id === false && $this->post_id_to_get_field_from !== false) {
            $post_id = $this->post_id_to_get_field_from;
        }
        $data_value = null;
        // Do we have some manually set data?
        if ($this->data !== false && array_key_exists($name, $this->data)) {
            $data_value = $this->data[$name];
        } elseif ($post_id === false && ($get_from_sub_field || $this->is_layout || $this->is_sub_field)) {
            // We should get data using acf functions and we are dealing with layout or sub field
            // Is it an ACF option?
            if ($this->is_option === true) {
                if (null !== ($value = get_sub_field($name, 'options'))) {
                    $data_value = $value;
                }
            } else {
                // Not ACF option
                if (null !== ($value = get_sub_field($name))) {
                    $data_value = $value;
                }
            }
        } else {
            // ACF data which is not a layout or sub field
            if ($this->is_option === true) {
                if (null !== ($value = get_field($name, 'options'))) {
                    $data_value = $value;
                }
            } elseif (null !== ($value = get_field($name, $post_id))) {
                $data_value = $value;
            }
        }
        return $data_value;
    }