PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.0
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.0
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / Services / Settings / Tax_Ids_Section.php

Tax_Ids_Section.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.0, at includes/Services/Settings/Tax_Ids_Section.php

96 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Tax IDs Settings Section.
4 *
5 * @package WCPOS\WooCommercePOS
6 */
7
8 namespace WCPOS\WooCommercePOS\Services\Settings;
9
10 use WCPOS\WooCommercePOS\Services\Tax_Id_Types;
11
12 /**
13 * The Tax IDs Settings Section: per-type meta-key write overrides. Empty by
14 * default — the composed write_map (defaults + plugin detection + scan) is
15 * used when no override exists.
16 */
17 class Tax_Ids_Section extends Abstract_Section {
18 /**
19 * Section id.
20 */
21 public function id(): string {
22 return 'tax_ids';
23 }
24
25 /**
26 * Section defaults.
27 */
28 public function defaults(): array {
29 return array(
30 'write_map' => array(),
31 );
32 }
33
34 /**
35 * Migrate write_map from its legacy home inside the general option, in memory only.
36 *
37 * @param array $raw Raw option value.
38 */
39 protected function migrate( array $raw ): array {
40 if ( ! \array_key_exists( 'write_map', $raw ) ) {
41 $legacy_general = get_option( self::DB_PREFIX . 'general', array() );
42 if (
43 \is_array( $legacy_general )
44 && isset( $legacy_general['tax_ids']['write_map'] )
45 && \is_array( $legacy_general['tax_ids']['write_map'] )
46 ) {
47 $raw['write_map'] = $legacy_general['tax_ids']['write_map'];
48 }
49 }
50
51 return $raw;
52 }
53
54 /**
55 * Write_map is intentionally a full replacement (not deep-merged) so
56 * users can remove entries by sending the trimmed map.
57 *
58 * @param array $existing Existing settings view.
59 * @param array $patch Incoming partial payload.
60 */
61 public function merge( array $existing, array $patch ): array {
62 $settings = array_replace_recursive( $existing, $patch );
63 if ( isset( $patch['write_map'] ) && \is_array( $patch['write_map'] ) ) {
64 $settings['write_map'] = $patch['write_map'];
65 }
66
67 return $settings;
68 }
69
70 /**
71 * REST endpoint args (formerly the legacy API\Settings controller's
72 * get_tax_ids_endpoint_args(), removed in 1.10).
73 */
74 public function endpoint_args(): array {
75 return array(
76 'write_map' => array(
77 'validate_callback' => function ( $param, $request, $key ) {
78 if ( ! \is_array( $param ) ) {
79 return false;
80 }
81 foreach ( $param as $type => $meta_key ) {
82 if ( ! \is_string( $type ) || ! Tax_Id_Types::is_valid_type( $type ) ) {
83 return false;
84 }
85 if ( ! \is_string( $meta_key ) ) {
86 return false;
87 }
88 }
89
90 return true;
91 },
92 ),
93 );
94 }
95 }
96