PluginProbe
Import WP – CSV & XML Import Export for WordPress / trunk
Import WP – CSV & XML Import Export for WordPress vtrunk
2.14.24 2.14.23 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 2.9.1 trunk 0.1.6 All 142 releases
jc-importer / class / Common / AddonAPI / Importer / Template / Group.php

Group.php in Import WP – CSV & XML Import Export for WordPress trunk, at class/Common/AddonAPI/Importer/Template/Group.php

65 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImportWP\Common\AddonAPI\Importer\Template;
4
5 class Group
6 {
7 /**
8 * @var Field[]|FieldGroup[]
9 */
10 private $_fields = [];
11
12 public function register_group($name, $args = [])
13 {
14 $field_group = new FieldGroup($name, $args);
15 $this->_fields[] = $field_group;
16 return $field_group;
17 }
18
19 public function register_field($name, $args = [])
20 {
21 $field = new Field($name, $args);
22 $this->_fields[] = $field;
23 return $field;
24 }
25
26 public function register_attachment_field($name, $field_label = '', $args = [])
27 {
28 $field = new Field($name, array_merge($args, [
29 'type' => 'attachment',
30 'field_label' => $field_label,
31 ]));
32 $this->_fields[] = $field;
33 return $field;
34 }
35
36 public function get_fields()
37 {
38 return $this->_fields;
39 }
40
41 /**
42 * @param \ImportWP\Common\Importer\Template\Template $template
43 * @return []
44 */
45 public function get_template_data($template)
46 {
47 $output = [];
48
49 foreach ($this->get_fields() as $field) {
50 if (is_a($field, FieldGroup::class)) {
51 $output[] = $template->register_group(
52 $field->get_name(),
53 $field->get_id(),
54 $field->get_template_data($template),
55 $field->get_args()
56 );
57 } elseif (is_a($field, Field::class)) {
58 $output[] = $field->get_template_data($template);
59 }
60 }
61
62 return $output;
63 }
64 }
65