PluginProbe ʕ •ᴥ•ʔ
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets / 4.1.1
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets v4.1.1
4.1.1 3.9.5 3.9.6 4.0.0 4.0.1 4.1.0 trunk 2.12 2.13 2.14 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9 3.7.0 3.7.1 3.7.2 3.7.3 3.7.3-beta-1.0 3.7.4 3.7.4-beta-1.0 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4
wp-all-import / addon-api / fields / switcher.php
wp-all-import / addon-api / fields Last commit date
checkbox.php 2 months ago date.php 2 months ago datetime.php 2 months ago field.php 2 months ago gallery.php 2 months ago map.php 2 months ago media-url.php 2 months ago media.php 2 months ago number.php 2 months ago post.php 2 months ago radio.php 2 months ago repeater.php 2 months ago select.php 2 months ago switcher.php 2 months ago text.php 2 months ago time.php 2 months ago toggle.php 2 months ago user.php 2 months ago
switcher.php
83 lines
1 <?php
2
3 namespace Wpai\AddonAPI;
4
5 if ( ! defined( 'ABSPATH' ) ) exit;
6
7 class PMXI_Addon_Switcher_Field extends PMXI_Addon_Field {
8
9 public function generateValue($slug, $default = null) {
10 // If this is a repeater field,
11 // get the value from the parent
12 if ($this->parent && $this->repeater_row_index !== null) {
13 $switchers = $this->view->options[$this->addon->slug . '_' . $slug];
14 $parent_value = $switchers[$this->parent->key] ?? null;
15 return $parent_value['rows'][$this->repeater_row_index][$this->key] ?? null;
16 }
17
18 return $this->view->getAddonValue($this->key, $slug, $default);
19 }
20
21 public function getSwitcherValue() {
22 return $this->generateValue('switchers', 'yes');
23 }
24
25 public function getMultipleValue() {
26 $val = $this->generateValue('multiple');
27 $multiple = $this->data['multiple'] ?? false;
28
29 if ($multiple && !is_array($val)) {
30 return [$val];
31 }
32
33 return $val;
34 }
35
36 public function getMultipleName() {
37 $multiple = $this->data['multiple'] ?? false;
38 $prefix = $this->getParentsPrefix();
39 $suffix = $multiple ? '[]' : '';
40 return $this->addon->slug . '_multiple' . $prefix . "[$this->key]" . $suffix;
41 }
42
43 public function getParentsPrefixSafeForHtmlId() {
44 return str_replace(['[', ']'], ['_', ''], $this->getParentsPrefix());
45 }
46
47 /**
48 * Get field HTML
49 * @return string
50 */
51 public function html() {
52 $params = $this->params();
53 $yes_name = $this->getMultipleName();
54 $yes_value = $this->getMultipleValue();
55 $multiple = $this->data['multiple'] ?? false;
56 $yes_type = $multiple ? 'checkbox' : $this->type;
57
58 $yes_params = array_merge(
59 $params,
60 [
61 'html_name' => $yes_name,
62 'field_value' => $yes_value
63 ]
64 );
65
66 $prefix = $this->addon->slug . '_switchers';
67 $id = $prefix . $this->getParentsPrefixSafeForHtmlId() . $this->key;
68 $name = $prefix . $this->getParentsPrefix() . "[$this->key]";
69
70 return view('switcher', array_merge($params, [
71 'switcher_id' => $id,
72 'switcher_name' => $name,
73 'switcher_value' => $this->getSwitcherValue(),
74
75 'yes_label' => __('Select value for all records', 'wp-all-import'),
76 'no_label' => __('Set with XPath', 'wp-all-import'),
77
78 'yes_input' => $this->getView($yes_type, $yes_params),
79 'no_input' => view('fields/text', $params, null, false),
80 ]), null, false);
81 }
82 }
83