PluginProbe
WooCommerce Square / 3.4.2
WooCommerce Square v3.4.2
5.5.0 5.4.3 5.4.2 5.4.1 5.4.0 trunk 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 All 132 releases
woocommerce-square / includes / Framework / Compatibility / Data_Compatibility.php
Data_Compatibility.php
115 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WooCommerce\Square\Framework\Compatibility;
4 use WooCommerce\Square\Framework\Plugin_Compatibility;
5
6 defined( 'ABSPATH' ) or exit;
7
8 /**
9 * WooCommerce data compatibility class.
10 *
11 * @since 3.0.0
12 */
13 abstract class Data_Compatibility {
14
15 /**
16 * Gets an object property.
17 *
18 * @since 3.0.0
19 * @param \WC_Data $object the data object, likely \WC_Order or \WC_Product
20 * @param string $prop the property name
21 * @param string $context if 'view' then the value will be filtered
22 * @param array $compat_props Compatibility properties.
23 * @return mixed
24 */
25 public static function get_prop( $object, $prop, $context = 'edit', $compat_props = array() ) {
26
27 $value = '';
28
29 if ( is_callable( array( $object, "get_{$prop}" ) ) ) {
30 $value = $object->{"get_{$prop}"}( $context );
31 }
32
33 return $value;
34 }
35
36
37 /**
38 * Sets an object's properties.
39 *
40 * Note that this does not save any data to the database.
41 *
42 * @since 3.0.0
43 * @param \WC_Data $object the data object, likely \WC_Order or \WC_Product
44 * @param array $props the new properties as $key => $value
45 * @param array $compat_props Compatibility properties.
46 * @return \WC_Data
47 */
48 public static function set_props( $object, $props, $compat_props = array() ) {
49 $object->set_props( $props );
50
51 return $object;
52 }
53
54
55 /**
56 * Gets an object's stored meta value.
57 *
58 * @since 3.0.0
59 * @param \WC_Data $object the data object, likely \WC_Order or \WC_Product
60 * @param string $key the meta key
61 * @param bool $single whether to get the meta as a single item. Defaults to `true`
62 * @param string $context if 'view' then the value will be filtered
63 * @return mixed
64 */
65 public static function get_meta( $object, $key = '', $single = true, $context = 'edit' ) {
66 $value = $object->get_meta( $key, $single, $context );
67
68 return $value;
69 }
70
71
72 /**
73 * Stores an object meta value.
74 *
75 * @since 3.0.0
76 * @param \WC_Data $object the data object, likely \WC_Order or \WC_Product
77 * @param string $key the meta key
78 * @param string $value the meta value
79 * @param bool $unique Optional. Whether the meta should be unique.
80 */
81 public static function add_meta_data( $object, $key, $value, $unique = false ) {
82 $object->add_meta_data( $key, $value, $unique );
83 $object->save_meta_data();
84 }
85
86
87 /**
88 * Updates an object's stored meta value.
89 *
90 * @since 3.0.0
91 * @param \WC_Data $object the data object, likely \WC_Order or \WC_Product
92 * @param string $key the meta key
93 * @param string $value the meta value
94 * @param int|string $meta_id Optional. The specific meta ID to update
95 */
96 public static function update_meta_data( $object, $key, $value, $meta_id = '' ) {
97 $object->update_meta_data( $key, $value, $meta_id );
98 $object->save_meta_data();
99 }
100
101
102 /**
103 * Deletes an object's stored meta value.
104 *
105 * @since 3.0.0
106 * @param \WC_Data $object the data object, likely \WC_Order or \WC_Product
107 * @param string $key the meta key
108 */
109 public static function delete_meta_data( $object, $key ) {
110 $object->delete_meta_data( $key );
111 $object->save_meta_data();
112 }
113 }
114
115