Papi_Entry_Type::get_property PHP Method

get_property() public method

Get property from entry type.
public get_property ( string $slug, string $child_slug = '' ) : Papi_Property
$slug string
$child_slug string
return Papi_Property
    public function get_property($slug, $child_slug = '')
    {
        $boxes = $this->get_boxes();
        $parts = preg_split('/\\[\\d+\\]/', $slug);
        $parts = array_map(function ($part) {
            return preg_replace('/(\\[|\\])/', '', $part);
        }, $parts);
        if (count($parts) > 1) {
            $property = null;
            for ($i = 0, $l = count($parts); $i < $l; $i++) {
                $child = isset($parts[$i + 1]) ? $parts[$i + 1] : '';
                $property = $this->get_property($parts[$i], $child);
                if (isset($parts[$i + 1])) {
                    $i++;
                }
            }
            /**
             * Modify property.
             *
             * @param  Papi_Core_Property $property
             */
            return apply_filters('papi/get_property', $property);
        }
        foreach ($boxes as $box) {
            foreach ($box->properties as $property) {
                $property = papi_get_property_type($property);
                if (papi_is_property($property) && $property->match_slug($slug)) {
                    if (empty($child_slug)) {
                        /**
                         * Modify property.
                         *
                         * @param  Papi_Core_Property $property
                         */
                        return apply_filters('papi/get_property', $property);
                    }
                    $property = $property->get_child_property($child_slug);
                    if (papi_is_property($property)) {
                        /**
                         * Modify property.
                         *
                         * @param  Papi_Core_Property $property
                         */
                        return apply_filters('papi/get_property', $property);
                    }
                }
            }
        }
    }