Jake Vanderwerf
2026-05-01 48721c85ebcfa973ee81719d2467ca80e4253dc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace JVBase\registrar\fields;
 
 
if (!defined('ABSPATH')) {
    exit;
}
 
class RepeaterField extends GroupedField {
    protected array $fields = [];
    protected string $add_label = 'Add Row';
    protected string $row_label = 'New Item';
 
    public function setAddLabel(string $label):void
    {
        $this->add_label = $label;
    }
    public function getAddLabel():string
    {
        return $this->add_label;
    }
    protected function checkFieldVariables(string $variables):bool
    {
        if (!str_contains($variables, '{{')) {
            return false;
        }
        $fields = array_filter(array_map(function($field) { return str_replace('}}','',$field);}, explode('{{',$variables)));
        foreach ($fields as $field) {
            if (!array_key_exists($field, $this->fields)) {
                error_log('['.(new \ReflectionClass($this))->getShortName().']Invalid field attempted: '.$field);
                return false;
            }
        }
        return true;
    }
    public function setRowLabel(string $label):void
    {
        if (str_contains($label, '{{')) {
            if (!$this->checkFieldVariables($label)) {
                return;
            }
        }
 
        $this->row_label = $label;
    }
    public function getRowLabel():string
    {
        return $this->row_label;
    }
}