PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.2.7
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.2.7
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / admin / classes / admin-options / fields / fields-group / class-merchant-field-fields-group.php

class-merchant-field-fields-group.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 2.2.7, at admin/classes/admin-options/fields/fields-group/class-merchant-field-fields-group.php

121 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Merchant Field: Fields Group
4 *
5 * A container field that groups multiple sub-fields together, with optional
6 * accordion display, status flag, and support for nesting inside flexible_content.
7 *
8 * @package Merchant
9 * @since 2.2.5
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 /**
17 * Merchant_Field_Fields_Group
18 *
19 * Renders a collapsible group of nested sub-fields.
20 *
21 * @since 2.2.5
22 */
23 class Merchant_Field_Fields_Group extends Merchant_Abstract_Field {
24
25 /**
26 * Render the fields group (standard usage, not inside flexible_content).
27 *
28 * @since 2.2.5
29 *
30 * @return void
31 */
32 public function render() {
33 $control_field_status = ! empty( $this->field['display_status'] ) && $this->field['display_status'] === true;
34 $accordion = ! empty( $this->field['accordion'] ) && $this->field['accordion'] === true;
35 $state = ! empty( $this->field['state'] ) && $this->field['state'] === 'open';
36
37 $this->get_template_part( 'template', array(
38 'accordion' => $accordion,
39 'control_field_status' => $control_field_status,
40 'state' => $state,
41 'inside_flexible' => false,
42 'args' => array(),
43 ) );
44 }
45
46 /**
47 * Render the fields group.
48 *
49 * Public static so flexible_content can call it with extra parameters
50 * for nested usage inside layouts.
51 *
52 * @since 2.2.5
53 *
54 * @param array<string, mixed> $settings Field settings.
55 * @param mixed $value Field value.
56 * @param string $module_id Module ID.
57 * @param bool $inside_flexible Whether this group is inside a flexible_content layout.
58 * @param array<string, mixed> $args Extra arguments when inside flexible_content.
59 *
60 * @return void
61 */
62 public static function render_group( $settings, $value, $module_id = '', $inside_flexible = false, $args = array() ) {
63 $control_field_status = ! empty( $settings['display_status'] ) && $settings['display_status'] === true;
64 $accordion = ! empty( $settings['accordion'] ) && $settings['accordion'] === true;
65 $state = ! empty( $settings['state'] ) && $settings['state'] === 'open';
66
67 include __DIR__ . '/template.php';
68 }
69
70 /**
71 * Type-specific sanitization for the fields group.
72 *
73 * Fields group values are sanitized per-sub-field during save_options,
74 * so this method returns the value as-is.
75 *
76 * @since 2.2.5
77 *
78 * @param mixed $value The raw submitted value.
79 *
80 * @return mixed The sanitized value.
81 */
82 protected function sanitize_value( $value ) {
83 if ( ! is_array( $value ) || empty( $this->field['fields'] ) ) {
84 return $value;
85 }
86
87 $registry = Merchant_Field_Registry::instance();
88 $sanitized = array();
89
90 foreach ( $this->field['fields'] as $sub_field ) {
91 if ( ! isset( $sub_field['id'] ) ) {
92 continue;
93 }
94
95 $sub_id = $sub_field['id'];
96 $sub_value = $value[ $sub_id ] ?? ( $sub_field['default'] ?? null );
97 $sub_type = $sub_field['type'] ?? 'text';
98
99 if ( $registry->has( $sub_type ) ) {
100 $instance = $registry->create( $sub_type, $sub_field, $sub_value );
101 if ( $instance !== null ) {
102 $sub_value = $instance->preprocess( $sub_value );
103 $sub_value = $instance->sanitize( $sub_value );
104 }
105 } else {
106 $sub_value = sanitize_text_field( $sub_value );
107 }
108
109 $sanitized[ $sub_id ] = $sub_value;
110 }
111
112 // Preserve the status sub-field if present (injected by render_group).
113 $status_id = $this->field['id'] . '_status';
114 if ( isset( $value[ $status_id ] ) ) {
115 $sanitized[ $status_id ] = sanitize_text_field( $value[ $status_id ] );
116 }
117
118 return $sanitized;
119 }
120 }
121