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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
<?php
namespace AutomateWoo;
/** * @class Variable * @since 2.4 */ abstract class Variable {
/** @var string */ protected $name;
/** @var string */ protected $description;
/** * Stores parameter field objects. * * @var Fields\Field[] */ protected $parameter_fields = [];
/** @var string */ protected $data_type;
/** @var string */ protected $data_field;
/** @var bool */ public $use_fallback = true;
/** @var bool */ public $has_loaded_admin_details = false;
/** * Optional method */ public function init() {}
/** * Method to set description and other admin props */ public function load_admin_details() {}
/** * Load admin details for this variable, if available. */ public function maybe_load_admin_details() { if ( ! $this->has_loaded_admin_details ) { $this->load_admin_details(); $this->has_loaded_admin_details = true; } }
/** * Constructor */ public function __construct() { $this->init(); }
/** * Sets the name, data_type and data_field props * * @param string $name */ public function setup( $name ) { $this->name = $name; list( $this->data_type, $this->data_field ) = explode( '.', $this->name ); }
/** * @return string */ public function get_description() { $this->maybe_load_admin_details(); return $this->description; }
/** * Get the parameter fields for the variable. * * @since 4.6.0 * * @return Fields\Field[] */ public function get_parameter_fields() { $this->maybe_load_admin_details(); return $this->parameter_fields; }
/** * @return string */ public function get_name() { return $this->name; }
/** * @return string */ public function get_data_type() { return $this->data_type; }
/** * @return string */ public function get_data_field() { return $this->data_field; }
/** * Add a parameter field to the variable. * * @since 4.6.0 * * @param Fields\Field $field */ protected function add_parameter_field( Fields\Field $field ) { $this->parameter_fields[ $field->get_name() ] = $field; }
/** * Add a text parameter field to the variable. * * @param string $name * @param string $description * @param bool $required * @param string $placeholder * @param array $extra */ protected function add_parameter_text_field( $name, $description, $required = false, $placeholder = '', $extra = [] ) { $field = new Fields\Text(); $field->set_name( $name ); $field->set_description( $description ); $field->set_required( $required ); $field->set_placeholder( $placeholder ); $field->meta = $extra;
$this->add_parameter_field( $field ); }
/** * Add a select parameter field to the variable. * * @param string $name * @param string $description * @param array $options * @param bool $required * @param array $extra */ protected function add_parameter_select_field( $name, $description, $options = [], $required = false, $extra = [] ) { $field = new Fields\Select( false ); $field->set_name( $name ); $field->set_description( $description ); $field->set_required( $required ); $field->set_options( $options ); $field->meta = $extra;
$this->add_parameter_field( $field ); } }
|